Welcome to mirror list, hosted at ThFree Co, Russian Federation.

preview_dropdown_spec.js « components « batch_comments « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bf3bbf4de2613c8ad0aa130d09b9c45ac8460ebd (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
import Vue, { nextTick } from 'vue';
import Vuex from 'vuex';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import PreviewDropdown from '~/batch_comments/components/preview_dropdown.vue';

Vue.use(Vuex);

let wrapper;

const setCurrentFileHash = jest.fn();
const scrollToDraft = jest.fn();

function factory({ viewDiffsFileByFile = false, draftsCount = 1, sortedDrafts = [] } = {}) {
  const store = new Vuex.Store({
    modules: {
      diffs: {
        namespaced: true,
        actions: {
          setCurrentFileHash,
        },
        state: {
          viewDiffsFileByFile,
        },
      },
      batchComments: {
        namespaced: true,
        actions: { scrollToDraft },
        getters: { draftsCount: () => draftsCount, sortedDrafts: () => sortedDrafts },
      },
    },
  });

  wrapper = shallowMountExtended(PreviewDropdown, {
    store,
  });
}

describe('Batch comments preview dropdown', () => {
  afterEach(() => {
    wrapper.destroy();
  });

  describe('clicking draft', () => {
    it('it toggles active file when viewDiffsFileByFile is true', async () => {
      factory({
        viewDiffsFileByFile: true,
        sortedDrafts: [{ id: 1, file_hash: 'hash' }],
      });

      wrapper.findByTestId('preview-item').vm.$emit('click');

      await nextTick();

      expect(setCurrentFileHash).toHaveBeenCalledWith(expect.anything(), 'hash');
      expect(scrollToDraft).toHaveBeenCalledWith(expect.anything(), { id: 1, file_hash: 'hash' });
    });

    it('calls scrollToDraft', async () => {
      factory({
        viewDiffsFileByFile: false,
        sortedDrafts: [{ id: 1 }],
      });

      wrapper.findByTestId('preview-item').vm.$emit('click');

      await nextTick();

      expect(scrollToDraft).toHaveBeenCalledWith(expect.anything(), { id: 1 });
    });
  });
});