2019-09-04 21:01:54 +05:30
|
|
|
import { mount, shallowMount, createLocalVue } from '@vue/test-utils';
|
2019-07-31 22:56:46 +05:30
|
|
|
import { GlButton, GlLink, GlFormGroup, GlFormInput } from '@gitlab/ui';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2019-07-31 22:56:46 +05:30
|
|
|
import ExternalDashboard from '~/operation_settings/components/external_dashboard.vue';
|
2019-09-04 21:01:54 +05:30
|
|
|
import store from '~/operation_settings/store';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { refreshCurrentPage } from '~/lib/utils/url_utility';
|
|
|
|
import createFlash from '~/flash';
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
jest.mock('~/lib/utils/url_utility');
|
|
|
|
jest.mock('~/flash');
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
describe('operation settings external dashboard component', () => {
|
|
|
|
let wrapper;
|
2019-09-04 21:01:54 +05:30
|
|
|
const operationsSettingsEndpoint = `${TEST_HOST}/mock/ops/settings/endpoint`;
|
|
|
|
const externalDashboardUrl = `http://mock-external-domain.com/external/dashboard/url`;
|
2019-07-31 22:56:46 +05:30
|
|
|
const externalDashboardHelpPagePath = `${TEST_HOST}/help/page/path`;
|
2019-09-04 21:01:54 +05:30
|
|
|
const localVue = createLocalVue();
|
|
|
|
const mountComponent = (shallow = true) => {
|
|
|
|
const config = [
|
|
|
|
ExternalDashboard,
|
|
|
|
{
|
|
|
|
localVue,
|
|
|
|
store: store({
|
|
|
|
operationsSettingsEndpoint,
|
|
|
|
externalDashboardUrl,
|
|
|
|
externalDashboardHelpPagePath,
|
|
|
|
}),
|
2019-07-31 22:56:46 +05:30
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
];
|
|
|
|
wrapper = shallow ? shallowMount(...config) : mount(...config);
|
|
|
|
};
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(axios, 'patch').mockImplementation();
|
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper.destroy) {
|
|
|
|
wrapper.destroy();
|
|
|
|
}
|
|
|
|
axios.patch.mockReset();
|
|
|
|
refreshCurrentPage.mockReset();
|
|
|
|
createFlash.mockReset();
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders header text', () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
mountComponent();
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(wrapper.find('.js-section-header').text()).toBe('External Dashboard');
|
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
describe('expand/collapse button', () => {
|
|
|
|
it('renders as an expand button by default', () => {
|
|
|
|
const button = wrapper.find(GlButton);
|
|
|
|
|
|
|
|
expect(button.text()).toBe('Expand');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
describe('sub-header', () => {
|
|
|
|
let subHeader;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-09-04 21:01:54 +05:30
|
|
|
mountComponent();
|
2019-07-31 22:56:46 +05:30
|
|
|
subHeader = wrapper.find('.js-section-sub-header');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders descriptive text', () => {
|
|
|
|
expect(subHeader.text()).toContain(
|
|
|
|
'Add a button to the metrics dashboard linking directly to your existing external dashboards.',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders help page link', () => {
|
|
|
|
const link = subHeader.find(GlLink);
|
|
|
|
|
|
|
|
expect(link.text()).toBe('Learn more');
|
|
|
|
expect(link.attributes().href).toBe(externalDashboardHelpPagePath);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('form', () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
describe('input label', () => {
|
|
|
|
let formGroup;
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent();
|
|
|
|
formGroup = wrapper.find(GlFormGroup);
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('uses label text', () => {
|
|
|
|
expect(formGroup.attributes().label).toBe('Full dashboard URL');
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('uses description text', () => {
|
|
|
|
expect(formGroup.attributes().description).toBe(
|
|
|
|
'Enter the URL of the dashboard you want to link to',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
describe('input field', () => {
|
|
|
|
let input;
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent();
|
|
|
|
input = wrapper.find(GlFormInput);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('defaults to externalDashboardUrl', () => {
|
|
|
|
expect(input.attributes().value).toBe(externalDashboardUrl);
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('uses a placeholder', () => {
|
|
|
|
expect(input.attributes().placeholder).toBe('https://my-org.gitlab.io/my-dashboards');
|
|
|
|
});
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
describe('submit button', () => {
|
|
|
|
const findSubmitButton = () => wrapper.find('.settings-content form').find(GlButton);
|
|
|
|
|
|
|
|
const endpointRequest = [
|
|
|
|
operationsSettingsEndpoint,
|
|
|
|
{
|
|
|
|
project: {
|
|
|
|
metrics_setting_attributes: {
|
|
|
|
external_dashboard_url: externalDashboardUrl,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
it('renders button label', () => {
|
|
|
|
mountComponent();
|
|
|
|
const submit = findSubmitButton();
|
|
|
|
expect(submit.text()).toBe('Save Changes');
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('submits form on click', () => {
|
|
|
|
mountComponent(false);
|
|
|
|
axios.patch.mockResolvedValue();
|
|
|
|
findSubmitButton().trigger('click');
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(axios.patch).toHaveBeenCalledWith(...endpointRequest);
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
return wrapper.vm.$nextTick().then(() => expect(refreshCurrentPage).toHaveBeenCalled());
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates flash banner on error', () => {
|
|
|
|
mountComponent(false);
|
|
|
|
const message = 'mockErrorMessage';
|
|
|
|
axios.patch.mockRejectedValue({ response: { data: { message } } });
|
|
|
|
findSubmitButton().trigger('click');
|
|
|
|
|
|
|
|
expect(axios.patch).toHaveBeenCalledWith(...endpointRequest);
|
|
|
|
|
|
|
|
return wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(jest.runAllTicks)
|
|
|
|
.then(() =>
|
|
|
|
expect(createFlash).toHaveBeenCalledWith(
|
|
|
|
`There was an error saving your changes. ${message}`,
|
|
|
|
'alert',
|
|
|
|
),
|
|
|
|
);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|