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

110 lines
2.8 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { createLocalVue, mount } from '@vue/test-utils';
2018-10-15 14:42:47 +05:30
import Vue 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';
2021-01-03 14:25:43 +05:30
const localVue = createLocalVue();
localVue.use(Vuex);
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';
store.state.currentBranchId = 'master';
2020-05-24 23:13:21 +05:30
store.state.projects.abcproject = { ...projectData };
2018-10-15 14:42:47 +05:30
Vue.set(store.state.trees, 'abcproject/master', {
tree: [file('fileName')],
loading: false,
});
2021-01-03 14:25:43 +05:30
wrapper = mount(keepAlive(IdeReview), {
store,
localVue,
});
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', () => {
2020-05-24 23:13:21 +05:30
beforeEach(() => {
2018-10-15 14:42:47 +05:30
store.state.currentMergeRequestId = '1';
store.state.projects.abcproject.mergeRequests['1'] = {
iid: 123,
web_url: 'testing123',
};
2021-01-03 14:25:43 +05:30
return wrapper.vm.$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
2021-01-03 14:25:43 +05:30
await wrapper.vm.$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';
2021-01-03 14:25:43 +05:30
await wrapper.vm.$nextTick();
expect(wrapper.text()).toContain('Latest changes');
2018-10-15 14:42:47 +05:30
});
});
});