Commit ec85e345 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'jestodus-license-management' into 'master'

Migrate license management specs to Jest

See merge request gitlab-org/gitlab!25721
parents 3a348de0 7be68e87
...@@ -2,7 +2,7 @@ import Vue from 'vue'; ...@@ -2,7 +2,7 @@ import Vue from 'vue';
import $ from 'jquery'; import $ from 'jquery';
import Dropdown from 'ee/vue_shared/license_management/components/add_license_form_dropdown.vue'; import Dropdown from 'ee/vue_shared/license_management/components/add_license_form_dropdown.vue';
import { KNOWN_LICENSES } from 'ee/vue_shared/license_management/constants'; import { KNOWN_LICENSES } from 'ee/vue_shared/license_management/constants';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
describe('AddLicenseFormDropdown', () => { describe('AddLicenseFormDropdown', () => {
const Component = Vue.extend(Dropdown); const Component = Vue.extend(Dropdown);
...@@ -14,7 +14,7 @@ describe('AddLicenseFormDropdown', () => { ...@@ -14,7 +14,7 @@ describe('AddLicenseFormDropdown', () => {
it('emits `input` invent on change', () => { it('emits `input` invent on change', () => {
vm = mountComponent(Component); vm = mountComponent(Component);
spyOn(vm, '$emit'); jest.spyOn(vm, '$emit').mockImplementation(() => {});
$(vm.$el) $(vm.$el)
.val('LGPL') .val('LGPL')
...@@ -48,8 +48,8 @@ describe('AddLicenseFormDropdown', () => { ...@@ -48,8 +48,8 @@ describe('AddLicenseFormDropdown', () => {
const options = $('.select2-drop .select2-result'); const options = $('.select2-drop .select2-result');
expect(KNOWN_LICENSES.length).toEqual(options.length); expect(KNOWN_LICENSES.length).toEqual(options.length);
options.each(function() { options.each((index, optionEl) => {
expect(KNOWN_LICENSES).toContain($(this).text()); expect(KNOWN_LICENSES).toContain($(optionEl).text());
}); });
done(); done();
}); });
......
import Vue from 'vue'; import Vue from 'vue';
import LicenseIssueBody from 'ee/vue_shared/license_management/components/add_license_form.vue'; import LicenseIssueBody from 'ee/vue_shared/license_management/components/add_license_form.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants'; import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants';
describe('AddLicenseForm', () => { describe('AddLicenseForm', () => {
...@@ -18,7 +18,7 @@ describe('AddLicenseForm', () => { ...@@ -18,7 +18,7 @@ describe('AddLicenseForm', () => {
describe('interaction', () => { describe('interaction', () => {
it('clicking the Submit button submits the data and closes the form', done => { it('clicking the Submit button submits the data and closes the form', done => {
const name = 'LICENSE_TEST'; const name = 'LICENSE_TEST';
spyOn(vm, '$emit'); jest.spyOn(vm, '$emit').mockImplementation(() => {});
vm.approvalStatus = LICENSE_APPROVAL_STATUS.APPROVED; vm.approvalStatus = LICENSE_APPROVAL_STATUS.APPROVED;
vm.licenseName = name; vm.licenseName = name;
...@@ -38,7 +38,7 @@ describe('AddLicenseForm', () => { ...@@ -38,7 +38,7 @@ describe('AddLicenseForm', () => {
it('clicking the Cancel button closes the form', () => { it('clicking the Cancel button closes the form', () => {
const linkEl = vm.$el.querySelector('.js-cancel'); const linkEl = vm.$el.querySelector('.js-cancel');
spyOn(vm, '$emit'); jest.spyOn(vm, '$emit').mockImplementation(() => {});
linkEl.click(); linkEl.click();
expect(vm.$emit).toHaveBeenCalledWith('closeForm'); expect(vm.$emit).toHaveBeenCalledWith('closeForm');
......
...@@ -4,12 +4,14 @@ import Vuex from 'vuex'; ...@@ -4,12 +4,14 @@ import Vuex from 'vuex';
import AdminLicenseManagementRow from 'ee/vue_shared/license_management/components/admin_license_management_row.vue'; import AdminLicenseManagementRow from 'ee/vue_shared/license_management/components/admin_license_management_row.vue';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants'; import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import { approvedLicense } from 'ee_spec/license_management/mock_data'; import { approvedLicense } from '../mock_data';
const visibleClass = 'visible'; const visibleClass = 'visible';
const invisibleClass = 'invisible'; const invisibleClass = 'invisible';
Vue.use(Vuex);
describe('AdminLicenseManagementRow', () => { describe('AdminLicenseManagementRow', () => {
const Component = Vue.extend(AdminLicenseManagementRow); const Component = Vue.extend(AdminLicenseManagementRow);
...@@ -22,9 +24,9 @@ describe('AdminLicenseManagementRow', () => { ...@@ -22,9 +24,9 @@ describe('AdminLicenseManagementRow', () => {
beforeEach(() => { beforeEach(() => {
actions = { actions = {
setLicenseInModal: jasmine.createSpy('setLicenseInModal'), setLicenseInModal: jest.fn(),
approveLicense: jasmine.createSpy('approveLicense'), approveLicense: jest.fn(),
blacklistLicense: jasmine.createSpy('blacklistLicense'), blacklistLicense: jest.fn(),
}; };
store = new Vuex.Store({ store = new Vuex.Store({
......
...@@ -2,9 +2,11 @@ import Vue from 'vue'; ...@@ -2,9 +2,11 @@ import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import DeleteConfirmationModal from 'ee/vue_shared/license_management/components/delete_confirmation_modal.vue'; import DeleteConfirmationModal from 'ee/vue_shared/license_management/components/delete_confirmation_modal.vue';
import { trimText } from 'spec/helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import { approvedLicense } from 'ee_spec/license_management/mock_data'; import { approvedLicense } from '../mock_data';
Vue.use(Vuex);
describe('DeleteConfirmationModal', () => { describe('DeleteConfirmationModal', () => {
const Component = Vue.extend(DeleteConfirmationModal); const Component = Vue.extend(DeleteConfirmationModal);
...@@ -14,8 +16,8 @@ describe('DeleteConfirmationModal', () => { ...@@ -14,8 +16,8 @@ describe('DeleteConfirmationModal', () => {
beforeEach(() => { beforeEach(() => {
actions = { actions = {
resetLicenseInModal: jasmine.createSpy('resetLicenseInModal'), resetLicenseInModal: jest.fn(),
deleteLicense: jasmine.createSpy('deleteLicense'), deleteLicense: jest.fn(),
}; };
store = new Vuex.Store({ store = new Vuex.Store({
...@@ -94,7 +96,7 @@ describe('DeleteConfirmationModal', () => { ...@@ -94,7 +96,7 @@ describe('DeleteConfirmationModal', () => {
linkEl.click(); linkEl.click();
expect(actions.deleteLicense).toHaveBeenCalledWith( expect(actions.deleteLicense).toHaveBeenCalledWith(
jasmine.any(Object), expect.any(Object),
store.state.licenseManagement.currentLicenseInModal, store.state.licenseManagement.currentLicenseInModal,
undefined, undefined,
); );
......
import Vue from 'vue'; import Vue from 'vue';
import LicenseIssueBody from 'ee/vue_shared/license_management/components/license_issue_body.vue'; import LicenseIssueBody from 'ee/vue_shared/license_management/components/license_issue_body.vue';
import { trimText } from 'spec/helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import createStore from 'ee/vue_shared/license_management/store'; import createStore from 'ee/vue_shared/license_management/store';
import { licenseReport } from 'ee_spec/license_management/mock_data'; import { licenseReport } from '../mock_data';
describe('LicenseIssueBody', () => { describe('LicenseIssueBody', () => {
const issue = licenseReport[0]; const issue = licenseReport[0];
......
import Vue from 'vue'; import Vue from 'vue';
import LicensePackages from 'ee/vue_shared/license_management/components/license_packages.vue'; import LicensePackages from 'ee/vue_shared/license_management/components/license_packages.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import { licenseReport } from 'ee_spec/license_management/mock_data'; import { licenseReport } from '../mock_data';
const examplePackages = licenseReport[0].packages; const examplePackages = licenseReport[0].packages;
......
...@@ -3,9 +3,11 @@ import Vuex from 'vuex'; ...@@ -3,9 +3,11 @@ import Vuex from 'vuex';
import SetApprovalModal from 'ee/vue_shared/license_management/components/set_approval_status_modal.vue'; import SetApprovalModal from 'ee/vue_shared/license_management/components/set_approval_status_modal.vue';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants'; import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants';
import { trimText } from 'spec/helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import { licenseReport } from 'ee_spec/license_management/mock_data'; import { licenseReport } from '../mock_data';
Vue.use(Vuex);
describe('SetApprovalModal', () => { describe('SetApprovalModal', () => {
const Component = Vue.extend(SetApprovalModal); const Component = Vue.extend(SetApprovalModal);
...@@ -16,9 +18,9 @@ describe('SetApprovalModal', () => { ...@@ -16,9 +18,9 @@ describe('SetApprovalModal', () => {
beforeEach(() => { beforeEach(() => {
actions = { actions = {
resetLicenseInModal: jasmine.createSpy('resetLicenseInModal'), resetLicenseInModal: jest.fn(),
approveLicense: jasmine.createSpy('approveLicense'), approveLicense: jest.fn(),
blacklistLicense: jasmine.createSpy('blacklistLicense'), blacklistLicense: jest.fn(),
}; };
store = new Vuex.Store({ store = new Vuex.Store({
...@@ -296,7 +298,7 @@ describe('SetApprovalModal', () => { ...@@ -296,7 +298,7 @@ describe('SetApprovalModal', () => {
linkEl.click(); linkEl.click();
expect(actions.approveLicense).toHaveBeenCalledWith( expect(actions.approveLicense).toHaveBeenCalledWith(
jasmine.any(Object), expect.any(Object),
store.state.licenseManagement.currentLicenseInModal, store.state.licenseManagement.currentLicenseInModal,
undefined, undefined,
); );
...@@ -309,7 +311,7 @@ describe('SetApprovalModal', () => { ...@@ -309,7 +311,7 @@ describe('SetApprovalModal', () => {
linkEl.click(); linkEl.click();
expect(actions.blacklistLicense).toHaveBeenCalledWith( expect(actions.blacklistLicense).toHaveBeenCalledWith(
jasmine.any(Object), expect.any(Object),
store.state.licenseManagement.currentLicenseInModal, store.state.licenseManagement.currentLicenseInModal,
undefined, undefined,
); );
......
...@@ -3,13 +3,13 @@ import Vuex from 'vuex'; ...@@ -3,13 +3,13 @@ import Vuex from 'vuex';
import LicenseManagement from 'ee/vue_shared/license_management/mr_widget_license_report.vue'; import LicenseManagement from 'ee/vue_shared/license_management/mr_widget_license_report.vue';
import { LOADING, ERROR, SUCCESS } from 'ee/vue_shared/security_reports/store/constants'; import { LOADING, ERROR, SUCCESS } from 'ee/vue_shared/security_reports/store/constants';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import { import {
approvedLicense, approvedLicense,
blacklistedLicense, blacklistedLicense,
licenseReport as licenseReportMock, licenseReport as licenseReportMock,
} from 'ee_spec/license_management/mock_data'; } from './mock_data';
describe('License Report MR Widget', () => { describe('License Report MR Widget', () => {
const Component = Vue.extend(LicenseManagement); const Component = Vue.extend(LicenseManagement);
...@@ -223,15 +223,13 @@ describe('License Report MR Widget', () => { ...@@ -223,15 +223,13 @@ describe('License Report MR Widget', () => {
it('should init store after mount', () => { it('should init store after mount', () => {
const actions = { const actions = {
setAPISettings: jasmine.createSpy('setAPISettings').and.callFake(() => {}), setAPISettings: jest.fn(() => {}),
fetchParsedLicenseReport: jasmine fetchParsedLicenseReport: jest.fn(() => {}),
.createSpy('fetchParsedLicenseReport')
.and.callFake(() => {}),
}; };
vm = mountComponent({ actions }); vm = mountComponent({ actions });
expect(actions.setAPISettings).toHaveBeenCalledWith( expect(actions.setAPISettings).toHaveBeenCalledWith(
jasmine.any(Object), expect.any(Object),
{ {
apiUrlManageLicenses: apiUrl, apiUrlManageLicenses: apiUrl,
licensesApiPath: defaultProps.licensesApiPath, licensesApiPath: defaultProps.licensesApiPath,
...@@ -241,7 +239,7 @@ describe('License Report MR Widget', () => { ...@@ -241,7 +239,7 @@ describe('License Report MR Widget', () => {
); );
expect(actions.fetchParsedLicenseReport).toHaveBeenCalledWith( expect(actions.fetchParsedLicenseReport).toHaveBeenCalledWith(
jasmine.any(Object), expect.any(Object),
undefined, undefined,
undefined, undefined,
); );
......
...@@ -4,8 +4,8 @@ import * as mutationTypes from 'ee/vue_shared/license_management/store/mutation_ ...@@ -4,8 +4,8 @@ import * as mutationTypes from 'ee/vue_shared/license_management/store/mutation_
import createState from 'ee/vue_shared/license_management/store/state'; import createState from 'ee/vue_shared/license_management/store/state';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants'; import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import testAction from 'spec/helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import { approvedLicense, blacklistedLicense } from 'ee_spec/license_management/mock_data'; import { approvedLicense, blacklistedLicense } from '../mock_data';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
describe('License store actions', () => { describe('License store actions', () => {
...@@ -169,7 +169,7 @@ describe('License store actions', () => { ...@@ -169,7 +169,7 @@ describe('License store actions', () => {
[], [],
[ [
{ type: 'requestDeleteLicense' }, { type: 'requestDeleteLicense' },
{ type: 'receiveDeleteLicenseError', payload: jasmine.any(Error) }, { type: 'receiveDeleteLicenseError', payload: expect.any(Error) },
], ],
) )
.then(done) .then(done)
...@@ -239,7 +239,7 @@ describe('License store actions', () => { ...@@ -239,7 +239,7 @@ describe('License store actions', () => {
describe('setLicenseApproval', () => { describe('setLicenseApproval', () => {
const newStatus = 'FAKE_STATUS'; const newStatus = 'FAKE_STATUS';
describe('uses POST endpoint for existing licenses;', function() { describe('uses POST endpoint for existing licenses;', () => {
let putEndpointMock; let putEndpointMock;
let newLicense; let newLicense;
...@@ -282,7 +282,7 @@ describe('License store actions', () => { ...@@ -282,7 +282,7 @@ describe('License store actions', () => {
[], [],
[ [
{ type: 'requestSetLicenseApproval' }, { type: 'requestSetLicenseApproval' },
{ type: 'receiveSetLicenseApprovalError', payload: jasmine.any(Error) }, { type: 'receiveSetLicenseApprovalError', payload: expect.any(Error) },
], ],
) )
.then(done) .then(done)
...@@ -290,7 +290,7 @@ describe('License store actions', () => { ...@@ -290,7 +290,7 @@ describe('License store actions', () => {
}); });
}); });
describe('uses PATCH endpoint for existing licenses;', function() { describe('uses PATCH endpoint for existing licenses;', () => {
let patchEndpointMock; let patchEndpointMock;
let licenseUrl; let licenseUrl;
...@@ -333,7 +333,7 @@ describe('License store actions', () => { ...@@ -333,7 +333,7 @@ describe('License store actions', () => {
[], [],
[ [
{ type: 'requestSetLicenseApproval' }, { type: 'requestSetLicenseApproval' },
{ type: 'receiveSetLicenseApprovalError', payload: jasmine.any(Error) }, { type: 'receiveSetLicenseApprovalError', payload: expect.any(Error) },
], ],
) )
.then(done) .then(done)
...@@ -494,7 +494,7 @@ describe('License store actions', () => { ...@@ -494,7 +494,7 @@ describe('License store actions', () => {
[], [],
[ [
{ type: 'requestManagedLicenses' }, { type: 'requestManagedLicenses' },
{ type: 'receiveManagedLicensesError', payload: jasmine.any(Error) }, { type: 'receiveManagedLicensesError', payload: expect.any(Error) },
], ],
) )
.then(done) .then(done)
...@@ -613,7 +613,7 @@ describe('License store actions', () => { ...@@ -613,7 +613,7 @@ describe('License store actions', () => {
[], [],
[ [
{ type: 'requestParsedLicenseReport' }, { type: 'requestParsedLicenseReport' },
{ type: 'receiveParsedLicenseReportError', payload: jasmine.any(Error) }, { type: 'receiveParsedLicenseReportError', payload: expect.any(Error) },
], ],
) )
.then(done) .then(done)
......
import createState from 'ee/vue_shared/license_management/store/state'; import createState from 'ee/vue_shared/license_management/store/state';
import * as getters from 'ee/vue_shared/license_management/store/getters'; import * as getters from 'ee/vue_shared/license_management/store/getters';
import { licenseReport as licenseReportMock } from 'ee_spec/license_management/mock_data'; import { licenseReport as licenseReportMock } from '../mock_data';
describe('getters', () => { describe('getters', () => {
let state; let state;
......
...@@ -3,7 +3,7 @@ import * as types from 'ee/vue_shared/license_management/store/mutation_types'; ...@@ -3,7 +3,7 @@ import * as types from 'ee/vue_shared/license_management/store/mutation_types';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants'; import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import { approvedLicense } from 'ee_spec/license_management/mock_data'; import { approvedLicense } from '../mock_data';
describe('License store mutations', () => { describe('License store mutations', () => {
let store; let store;
......
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
convertToOldReportFormat, convertToOldReportFormat,
} from 'ee/vue_shared/license_management/store/utils'; } from 'ee/vue_shared/license_management/store/utils';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants'; import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants';
import { licenseReport } from 'ee_spec/license_management/mock_data'; import { licenseReport } from '../mock_data';
import { STATUS_FAILED, STATUS_NEUTRAL, STATUS_SUCCESS } from '~/reports/constants'; import { STATUS_FAILED, STATUS_NEUTRAL, STATUS_SUCCESS } from '~/reports/constants';
describe('utils', () => { describe('utils', () => {
......
export * from '../../frontend/license_management/mock_data';
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