summaryrefslogtreecommitdiff
path: root/spec/javascripts/diffs/components/app_spec.js
blob: 3c9b5ee0176dfe52e1e279ff35a603a304b50257 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import Vue from 'vue';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { TEST_HOST } from 'spec/test_constants';
import App from '~/diffs/components/app.vue';
import createDiffsStore from '../create_diffs_store';
import getDiffWithCommit from '../mock_data/diff_with_commit';

describe('diffs/components/app', () => {
  const oldMrTabs = window.mrTabs;
  const Component = Vue.extend(App);

  let vm;

  beforeEach(() => {
    // setup globals (needed for component to mount :/)
    window.mrTabs = jasmine.createSpyObj('mrTabs', ['resetViewContainer']);

    // setup component
    const store = createDiffsStore();
    store.state.diffs.isLoading = false;

    vm = mountComponentWithStore(Component, {
      store,
      props: {
        endpoint: `${TEST_HOST}/diff/endpoint`,
        projectPath: 'namespace/project',
        currentUser: {},
      },
    });
  });

  afterEach(() => {
    // reset globals
    window.mrTabs = oldMrTabs;

    // reset component
    vm.$destroy();
  });

  it('does not show commit info', () => {
    expect(vm.$el).not.toContainElement('.blob-commit-info');
  });

  it('shows comments message, with commit', done => {
    vm.$store.state.diffs.commit = getDiffWithCommit().commit;

    vm.$nextTick()
      .then(() => {
        expect(vm.$el).toContainText('Only comments from the following commit are shown below');
        expect(vm.$el).toContainElement('.blob-commit-info');
      })
      .then(done)
      .catch(done.fail);
  });

  it('shows comments message, with old mergeRequestDiff', done => {
    vm.$store.state.diffs.mergeRequestDiff = { latest: false };
    vm.$store.state.diffs.targetBranch = 'master';

    vm.$nextTick()
      .then(() => {
        expect(vm.$el).toContainText(
          "Not all comments are displayed because you're viewing an old version of the diff.",
        );
      })
      .then(done)
      .catch(done.fail);
  });

  it('shows comments message, with startVersion', done => {
    vm.$store.state.diffs.startVersion = 'test';

    vm.$nextTick()
      .then(() => {
        expect(vm.$el).toContainText(
          "Not all comments are displayed because you're comparing two versions of the diff.",
        );
      })
      .then(done)
      .catch(done.fail);
  });
});