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