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

108 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { mount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
2021-01-03 14:25:43 +05:30
import Vuex from 'vuex';
2021-03-08 18:12:59 +05:30
import { keepAlive } from 'helpers/keep_alive_component_helper';
2021-03-11 19:13:27 +05:30
import { trimText } from 'helpers/text_helper';
2021-01-03 14:25:43 +05:30
import EditorModeDropdown from '~/ide/components/editor_mode_dropdown.vue';
2021-03-11 19:13:27 +05:30
import IdeReview from '~/ide/components/ide_review.vue';
2020-05-24 23:13:21 +05:30
import { createStore } from '~/ide/stores';
2020-10-24 23:57:45 +05:30
import { file } from '../helpers';
2018-10-15 14:42:47 +05:30
import { projectData } from '../mock_data';
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2021-01-03 14:25:43 +05:30
2018-10-15 14:42:47 +05:30
describe('IDE review mode', () => {
2021-01-03 14:25:43 +05:30
let wrapper;
2020-05-24 23:13:21 +05:30
let store;
2018-10-15 14:42:47 +05:30
beforeEach(() => {
2020-05-24 23:13:21 +05:30
store = createStore();
2018-10-15 14:42:47 +05:30
store.state.currentProjectId = 'abcproject';
2021-09-04 01:27:46 +05:30
store.state.currentBranchId = 'main';
2020-05-24 23:13:21 +05:30
store.state.projects.abcproject = { ...projectData };
2021-09-04 01:27:46 +05:30
Vue.set(store.state.trees, 'abcproject/main', {
2018-10-15 14:42:47 +05:30
tree: [file('fileName')],
loading: false,
});
2021-01-03 14:25:43 +05:30
wrapper = mount(keepAlive(IdeReview), {
store,
});
2018-10-15 14:42:47 +05:30
});
afterEach(() => {
2021-01-03 14:25:43 +05:30
wrapper.destroy();
2018-10-15 14:42:47 +05:30
});
it('renders list of files', () => {
2021-01-03 14:25:43 +05:30
expect(wrapper.text()).toContain('fileName');
});
describe('activated', () => {
let inititializeSpy;
beforeEach(async () => {
inititializeSpy = jest.spyOn(wrapper.find(IdeReview).vm, 'initialize');
store.state.viewer = 'editor';
await wrapper.vm.reactivate();
});
it('re initializes the component', () => {
expect(inititializeSpy).toHaveBeenCalled();
});
it('updates viewer to "diff" by default', () => {
expect(store.state.viewer).toBe('diff');
});
describe('merge request is defined', () => {
beforeEach(async () => {
store.state.currentMergeRequestId = '1';
store.state.projects.abcproject.mergeRequests['1'] = {
iid: 123,
web_url: 'testing123',
};
await wrapper.vm.reactivate();
});
it('updates viewer to "mrdiff"', async () => {
expect(store.state.viewer).toBe('mrdiff');
});
});
2018-10-15 14:42:47 +05:30
});
describe('merge request', () => {
2022-04-04 11:22:00 +05:30
beforeEach(async () => {
2018-10-15 14:42:47 +05:30
store.state.currentMergeRequestId = '1';
store.state.projects.abcproject.mergeRequests['1'] = {
iid: 123,
web_url: 'testing123',
};
2022-04-04 11:22:00 +05:30
await nextTick();
2018-10-15 14:42:47 +05:30
});
it('renders edit dropdown', () => {
2021-01-03 14:25:43 +05:30
expect(wrapper.find(EditorModeDropdown).exists()).toBe(true);
2018-10-15 14:42:47 +05:30
});
2021-01-03 14:25:43 +05:30
it('renders merge request link & IID', async () => {
2020-05-24 23:13:21 +05:30
store.state.viewer = 'mrdiff';
2018-10-15 14:42:47 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
expect(trimText(wrapper.text())).toContain('Merge request (!123)');
2018-10-15 14:42:47 +05:30
});
2021-01-03 14:25:43 +05:30
it('changes text to latest changes when viewer is not mrdiff', async () => {
2018-10-15 14:42:47 +05:30
store.state.viewer = 'diff';
2022-04-04 11:22:00 +05:30
await nextTick();
2021-01-03 14:25:43 +05:30
expect(wrapper.text()).toContain('Latest changes');
2018-10-15 14:42:47 +05:30
});
});
});