debian-mirror-gitlab/spec/frontend/ide/components/ide_status_list_spec.js

105 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-07-28 23:09:34 +05:30
import { GlLink } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { createLocalVue, shallowMount } from '@vue/test-utils';
import Vuex from 'vuex';
2020-03-13 15:44:24 +05:30
import IdeStatusList from '~/ide/components/ide_status_list.vue';
2020-06-23 00:09:42 +05:30
import TerminalSyncStatusSafe from '~/ide/components/terminal_sync/terminal_sync_status_safe.vue';
2019-09-04 21:01:54 +05:30
const TEST_FILE = {
name: 'lorem.md',
2020-06-23 00:09:42 +05:30
content: 'abc\nndef',
2020-07-28 23:09:34 +05:30
permalink: '/lorem.md',
2019-09-04 21:01:54 +05:30
};
2021-01-29 00:20:46 +05:30
const TEST_FILE_EDITOR = {
fileLanguage: 'markdown',
editorRow: 3,
editorColumn: 23,
};
const TEST_EDITOR_POSITION = `${TEST_FILE_EDITOR.editorRow}:${TEST_FILE_EDITOR.editorColumn}`;
2019-09-04 21:01:54 +05:30
const localVue = createLocalVue();
localVue.use(Vuex);
describe('ide/components/ide_status_list', () => {
2021-01-29 00:20:46 +05:30
let activeFileEditor;
2019-09-04 21:01:54 +05:30
let activeFile;
let store;
let wrapper;
2020-07-28 23:09:34 +05:30
const findLink = () => wrapper.find(GlLink);
2019-09-04 21:01:54 +05:30
const createComponent = (options = {}) => {
store = new Vuex.Store({
getters: {
activeFile: () => activeFile,
},
2021-01-29 00:20:46 +05:30
modules: {
editor: {
namespaced: true,
getters: {
activeFileEditor: () => activeFileEditor,
},
},
},
2019-09-04 21:01:54 +05:30
});
2020-03-13 15:44:24 +05:30
wrapper = shallowMount(IdeStatusList, {
2019-09-04 21:01:54 +05:30
localVue,
store,
...options,
});
};
beforeEach(() => {
activeFile = TEST_FILE;
2021-01-29 00:20:46 +05:30
activeFileEditor = TEST_FILE_EDITOR;
2019-09-04 21:01:54 +05:30
});
afterEach(() => {
wrapper.destroy();
store = null;
wrapper = null;
});
describe('with regular file', () => {
beforeEach(() => {
createComponent();
});
2020-07-28 23:09:34 +05:30
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);
2019-09-04 21:01:54 +05:30
});
it('shows file eol', () => {
2020-06-23 00:09:42 +05:30
expect(wrapper.text()).not.toContain('CRLF');
expect(wrapper.text()).toContain('LF');
2019-09-04 21:01:54 +05:30
});
it('shows file editor position', () => {
2021-01-29 00:20:46 +05:30
expect(wrapper.text()).toContain(TEST_EDITOR_POSITION);
2019-09-04 21:01:54 +05:30
});
it('shows file language', () => {
2021-01-29 00:20:46 +05:30
expect(wrapper.text()).toContain(TEST_FILE_EDITOR.fileLanguage);
2019-09-04 21:01:54 +05:30
});
});
describe('with binary file', () => {
beforeEach(() => {
2020-11-24 15:15:51 +05:30
activeFile.name = 'abc.dat';
activeFile.content = '🐱'; // non-ascii binary content
2019-09-04 21:01:54 +05:30
createComponent();
});
it('does not show file editor position', () => {
2021-01-29 00:20:46 +05:30
expect(wrapper.text()).not.toContain(TEST_EDITOR_POSITION);
2019-09-04 21:01:54 +05:30
});
});
2020-06-23 00:09:42 +05:30
it('renders terminal sync status', () => {
createComponent();
2019-09-04 21:01:54 +05:30
2020-06-23 00:09:42 +05:30
expect(wrapper.find(TerminalSyncStatusSafe).exists()).toBe(true);
2019-09-04 21:01:54 +05:30
});
});