summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/components/ide_status_list_spec.js
blob: 02b5dc19bd886d69e37d51aa3c28c5bba83d7eef (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import Vuex from 'vuex';
import { createLocalVue, shallowMount } from '@vue/test-utils';
import { GlLink } from '@gitlab/ui';
import IdeStatusList from '~/ide/components/ide_status_list.vue';
import TerminalSyncStatusSafe from '~/ide/components/terminal_sync/terminal_sync_status_safe.vue';

const TEST_FILE = {
  name: 'lorem.md',
  content: 'abc\nndef',
  permalink: '/lorem.md',
};
const TEST_FILE_EDITOR = {
  fileLanguage: 'markdown',
  editorRow: 3,
  editorColumn: 23,
};
const TEST_EDITOR_POSITION = `${TEST_FILE_EDITOR.editorRow}:${TEST_FILE_EDITOR.editorColumn}`;

const localVue = createLocalVue();
localVue.use(Vuex);

describe('ide/components/ide_status_list', () => {
  let activeFileEditor;
  let activeFile;
  let store;
  let wrapper;

  const findLink = () => wrapper.find(GlLink);
  const createComponent = (options = {}) => {
    store = new Vuex.Store({
      getters: {
        activeFile: () => activeFile,
      },
      modules: {
        editor: {
          namespaced: true,
          getters: {
            activeFileEditor: () => activeFileEditor,
          },
        },
      },
    });

    wrapper = shallowMount(IdeStatusList, {
      localVue,
      store,
      ...options,
    });
  };

  beforeEach(() => {
    activeFile = TEST_FILE;
    activeFileEditor = TEST_FILE_EDITOR;
  });

  afterEach(() => {
    wrapper.destroy();

    store = null;
    wrapper = null;
  });

  describe('with regular file', () => {
    beforeEach(() => {
      createComponent();
    });

    it('shows a link to the file that contains the file name', () => {
      expect(findLink().attributes('href')).toBe(TEST_FILE.permalink);
      expect(findLink().text()).toBe(TEST_FILE.name);
    });

    it('shows file eol', () => {
      expect(wrapper.text()).not.toContain('CRLF');
      expect(wrapper.text()).toContain('LF');
    });

    it('shows file editor position', () => {
      expect(wrapper.text()).toContain(TEST_EDITOR_POSITION);
    });

    it('shows file language', () => {
      expect(wrapper.text()).toContain(TEST_FILE_EDITOR.fileLanguage);
    });
  });

  describe('with binary file', () => {
    beforeEach(() => {
      activeFile.name = 'abc.dat';
      activeFile.content = '🐱'; // non-ascii binary content
      createComponent();
    });

    it('does not show file editor position', () => {
      expect(wrapper.text()).not.toContain(TEST_EDITOR_POSITION);
    });
  });

  it('renders terminal sync status', () => {
    createComponent();

    expect(wrapper.find(TerminalSyncStatusSafe).exists()).toBe(true);
  });
});