Commit aced436b authored by Phil Hughes's avatar Phil Hughes

Merge branch 'himkp-jest-webide' into 'master'

Migrate some IDE component specs to Jest

See merge request gitlab-org/gitlab!31263
parents 32f85452 049d9b7c
import Vue from 'vue'; import Vue from 'vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
import { resetStore } from 'spec/ide/helpers'; import { resetStore } from 'jest/ide/helpers';
import store from '~/ide/stores'; import store from '~/ide/stores';
import radioGroup from '~/ide/components/commit_sidebar/radio_group.vue'; import radioGroup from '~/ide/components/commit_sidebar/radio_group.vue';
...@@ -41,13 +41,8 @@ describe('IDE commit sidebar radio group', () => { ...@@ -41,13 +41,8 @@ describe('IDE commit sidebar radio group', () => {
radioGroup, radioGroup,
}, },
store, store,
template: ` render: createElement =>
<radio-group createElement('radio-group', { props: { value: '1' } }, 'Testing slot'),
value="1"
>
Testing slot
</radio-group>
`,
}); });
vm.$mount(); vm.$mount();
......
import Vue from 'vue'; import Vue from 'vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
import { createStore } from '~/ide/stores'; import { createStore } from '~/ide/stores';
import FileRowExtra from '~/ide/components/file_row_extra.vue'; import FileRowExtra from '~/ide/components/file_row_extra.vue';
import { file, resetStore } from '../helpers'; import { file, resetStore } from '../helpers';
...@@ -23,9 +23,9 @@ describe('IDE extra file row component', () => { ...@@ -23,9 +23,9 @@ describe('IDE extra file row component', () => {
dropdownOpen: false, dropdownOpen: false,
}); });
spyOnProperty(vm, 'getUnstagedFilesCountForPath').and.returnValue(() => unstagedFilesCount); jest.spyOn(vm, 'getUnstagedFilesCountForPath', 'get').mockReturnValue(() => unstagedFilesCount);
spyOnProperty(vm, 'getStagedFilesCountForPath').and.returnValue(() => stagedFilesCount); jest.spyOn(vm, 'getStagedFilesCountForPath', 'get').mockReturnValue(() => stagedFilesCount);
spyOnProperty(vm, 'getChangesInFolder').and.returnValue(() => changesCount); jest.spyOn(vm, 'getChangesInFolder', 'get').mockReturnValue(() => changesCount);
vm.$mount(); vm.$mount();
}); });
......
import Vue from 'vue'; import Vue from 'vue';
import IdeReview from '~/ide/components/ide_review.vue'; import IdeReview from '~/ide/components/ide_review.vue';
import store from '~/ide/stores'; import { createStore } from '~/ide/stores';
import { createComponentWithStore } from '../../helpers/vue_mount_component_helper'; import { createComponentWithStore } from '../../helpers/vue_mount_component_helper';
import { trimText } from '../../helpers/text_helper'; import { trimText } from '../../helpers/text_helper';
import { resetStore, file } from '../helpers'; import { resetStore, file } from '../helpers';
...@@ -9,8 +9,10 @@ import { projectData } from '../mock_data'; ...@@ -9,8 +9,10 @@ import { projectData } from '../mock_data';
describe('IDE review mode', () => { describe('IDE review mode', () => {
const Component = Vue.extend(IdeReview); const Component = Vue.extend(IdeReview);
let vm; let vm;
let store;
beforeEach(() => { beforeEach(() => {
store = createStore();
store.state.currentProjectId = 'abcproject'; store.state.currentProjectId = 'abcproject';
store.state.currentBranchId = 'master'; store.state.currentBranchId = 'master';
store.state.projects.abcproject = Object.assign({}, projectData); store.state.projects.abcproject = Object.assign({}, projectData);
...@@ -33,14 +35,14 @@ describe('IDE review mode', () => { ...@@ -33,14 +35,14 @@ describe('IDE review mode', () => {
}); });
describe('merge request', () => { describe('merge request', () => {
beforeEach(done => { beforeEach(() => {
store.state.currentMergeRequestId = '1'; store.state.currentMergeRequestId = '1';
store.state.projects.abcproject.mergeRequests['1'] = { store.state.projects.abcproject.mergeRequests['1'] = {
iid: 123, iid: 123,
web_url: 'testing123', web_url: 'testing123',
}; };
vm.$nextTick(done); return vm.$nextTick();
}); });
it('renders edit dropdown', () => { it('renders edit dropdown', () => {
...@@ -48,21 +50,23 @@ describe('IDE review mode', () => { ...@@ -48,21 +50,23 @@ describe('IDE review mode', () => {
}); });
it('renders merge request link & IID', () => { it('renders merge request link & IID', () => {
const link = vm.$el.querySelector('.ide-review-sub-header'); store.state.viewer = 'mrdiff';
expect(link.querySelector('a').getAttribute('href')).toBe('testing123'); return vm.$nextTick(() => {
expect(trimText(link.textContent)).toBe('Merge request (!123)'); const link = vm.$el.querySelector('.ide-review-sub-header');
expect(link.querySelector('a').getAttribute('href')).toBe('testing123');
expect(trimText(link.textContent)).toBe('Merge request (!123)');
});
}); });
it('changes text to latest changes when viewer is not mrdiff', done => { it('changes text to latest changes when viewer is not mrdiff', () => {
store.state.viewer = 'diff'; store.state.viewer = 'diff';
vm.$nextTick(() => { return vm.$nextTick(() => {
expect(trimText(vm.$el.querySelector('.ide-review-sub-header').textContent)).toBe( expect(trimText(vm.$el.querySelector('.ide-review-sub-header').textContent)).toBe(
'Latest changes', 'Latest changes',
); );
done();
}); });
}); });
}); });
......
import Vue from 'vue'; import Vue from 'vue';
import _ from 'lodash'; import _ from 'lodash';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from '../../helpers/test_constants';
import { createStore } from '~/ide/stores'; import { createStore } from '~/ide/stores';
import IdeStatusBar from '~/ide/components/ide_status_bar.vue'; import IdeStatusBar from '~/ide/components/ide_status_bar.vue';
import { rightSidebarViews } from '~/ide/constants'; import { rightSidebarViews } from '~/ide/constants';
...@@ -45,26 +45,24 @@ describe('ideStatusBar', () => { ...@@ -45,26 +45,24 @@ describe('ideStatusBar', () => {
}); });
describe('commitAgeUpdate', () => { describe('commitAgeUpdate', () => {
beforeEach(function() { beforeEach(() => {
jasmine.clock().install(); jest.spyOn(vm, 'commitAgeUpdate').mockImplementation(() => {});
spyOn(vm, 'commitAgeUpdate').and.callFake(() => {});
vm.startTimer();
}); });
afterEach(function() { afterEach(() => {
jasmine.clock().uninstall(); jest.clearAllTimers();
}); });
it('gets called every second', () => { it('gets called every second', () => {
expect(vm.commitAgeUpdate).not.toHaveBeenCalled(); expect(vm.commitAgeUpdate).not.toHaveBeenCalled();
jasmine.clock().tick(1100); jest.advanceTimersByTime(1000);
expect(vm.commitAgeUpdate.calls.count()).toEqual(1); expect(vm.commitAgeUpdate.mock.calls.length).toEqual(1);
jasmine.clock().tick(1000); jest.advanceTimersByTime(1000);
expect(vm.commitAgeUpdate.calls.count()).toEqual(2); expect(vm.commitAgeUpdate.mock.calls.length).toEqual(2);
}); });
}); });
...@@ -76,7 +74,7 @@ describe('ideStatusBar', () => { ...@@ -76,7 +74,7 @@ describe('ideStatusBar', () => {
describe('pipeline status', () => { describe('pipeline status', () => {
it('opens right sidebar on clicking icon', done => { it('opens right sidebar on clicking icon', done => {
spyOn(vm, 'openRightPane'); jest.spyOn(vm, 'openRightPane').mockImplementation(() => {});
Vue.set(vm.$store.state.pipelines, 'latestPipeline', { Vue.set(vm.$store.state.pipelines, 'latestPipeline', {
details: { details: {
status: { status: {
......
...@@ -33,7 +33,7 @@ describe('IDE merge request item', () => { ...@@ -33,7 +33,7 @@ describe('IDE merge request item', () => {
`/project/${vm.item.projectPathWithNamespace}/merge_requests/${vm.item.iid}`, `/project/${vm.item.projectPathWithNamespace}/merge_requests/${vm.item.iid}`,
).href; ).href;
expect(vm.$el).toMatch('a'); expect(vm.$el.tagName.toLowerCase()).toBe('a');
expect(vm.$el).toHaveAttr('href', expectedHref); expect(vm.$el).toHaveAttr('href', expectedHref);
}); });
......
import Vue from 'vue'; import Vue from 'vue';
import createComponent from 'spec/helpers/vue_mount_component_helper'; import createComponent from 'helpers/vue_mount_component_helper';
import upload from '~/ide/components/new_dropdown/upload.vue'; import upload from '~/ide/components/new_dropdown/upload.vue';
describe('new dropdown upload', () => { describe('new dropdown upload', () => {
...@@ -14,7 +14,7 @@ describe('new dropdown upload', () => { ...@@ -14,7 +14,7 @@ describe('new dropdown upload', () => {
vm.entryName = 'testing'; vm.entryName = 'testing';
spyOn(vm, '$emit').and.callThrough(); jest.spyOn(vm, '$emit');
}); });
afterEach(() => { afterEach(() => {
...@@ -25,22 +25,22 @@ describe('new dropdown upload', () => { ...@@ -25,22 +25,22 @@ describe('new dropdown upload', () => {
it('calls for each file', () => { it('calls for each file', () => {
const files = ['test', 'test2', 'test3']; const files = ['test', 'test2', 'test3'];
spyOn(vm, 'readFile'); jest.spyOn(vm, 'readFile').mockImplementation(() => {});
spyOnProperty(vm.$refs.fileUpload, 'files').and.returnValue(files); jest.spyOn(vm.$refs.fileUpload, 'files', 'get').mockReturnValue(files);
vm.openFile(); vm.openFile();
expect(vm.readFile.calls.count()).toBe(3); expect(vm.readFile.mock.calls.length).toBe(3);
files.forEach((file, i) => { files.forEach((file, i) => {
expect(vm.readFile.calls.argsFor(i)).toEqual([file]); expect(vm.readFile.mock.calls[i]).toEqual([file]);
}); });
}); });
}); });
describe('readFile', () => { describe('readFile', () => {
beforeEach(() => { beforeEach(() => {
spyOn(FileReader.prototype, 'readAsDataURL'); jest.spyOn(FileReader.prototype, 'readAsDataURL').mockImplementation(() => {});
}); });
it('calls readAsDataURL for all files', () => { it('calls readAsDataURL for all files', () => {
...@@ -69,7 +69,7 @@ describe('new dropdown upload', () => { ...@@ -69,7 +69,7 @@ describe('new dropdown upload', () => {
}; };
beforeEach(() => { beforeEach(() => {
spyOn(FileReader.prototype, 'readAsText').and.callThrough(); jest.spyOn(FileReader.prototype, 'readAsText');
}); });
it('calls readAsText and creates file in plain text (without encoding) if the file content is plain text', done => { it('calls readAsText and creates file in plain text (without encoding) if the file content is plain text', done => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment