2020-03-13 15:44:24 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import DeploymentViewButton from '~/vue_merge_request_widget/components/deployment/deployment_view_button.vue';
|
|
|
|
import ReviewAppLink from '~/vue_merge_request_widget/components/review_app_link.vue';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { deploymentMockData } from './deployment_mock_data';
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
const appButtonText = {
|
|
|
|
text: 'View app',
|
|
|
|
tooltip: 'View the latest successful deployment to this environment',
|
|
|
|
};
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
describe('Deployment View App button', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const factory = (options = {}) => {
|
2020-03-13 15:44:24 +05:30
|
|
|
wrapper = mount(DeploymentViewButton, {
|
2020-01-01 13:55:28 +05:30
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
deployment: deploymentMockData,
|
2020-03-13 15:44:24 +05:30
|
|
|
appButtonText,
|
2020-01-01 13:55:28 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('text', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
it('renders text as passed', () => {
|
|
|
|
expect(wrapper.find(ReviewAppLink).text()).toContain(appButtonText.text);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without changes', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
deployment: { ...deploymentMockData, changes: null },
|
2020-03-13 15:44:24 +05:30
|
|
|
appButtonText,
|
2020-01-01 13:55:28 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the link to the review app without dropdown', () => {
|
|
|
|
expect(wrapper.find('.js-mr-wigdet-deployment-dropdown').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with a single change', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
deployment: { ...deploymentMockData, changes: [deploymentMockData.changes[0]] },
|
2020-03-13 15:44:24 +05:30
|
|
|
appButtonText,
|
2020-01-01 13:55:28 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the link to the review app without dropdown', () => {
|
|
|
|
expect(wrapper.find('.js-mr-wigdet-deployment-dropdown').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the link to the review app linked to to the first change', () => {
|
|
|
|
const expectedUrl = deploymentMockData.changes[0].external_url;
|
|
|
|
const deployUrl = wrapper.find('.js-deploy-url');
|
|
|
|
|
|
|
|
expect(deployUrl.attributes().href).not.toBeNull();
|
|
|
|
expect(deployUrl.attributes().href).toEqual(expectedUrl);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with multiple changes', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
deployment: deploymentMockData,
|
2020-03-13 15:44:24 +05:30
|
|
|
appButtonText,
|
2020-01-01 13:55:28 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the link to the review app with dropdown', () => {
|
|
|
|
expect(wrapper.find('.js-mr-wigdet-deployment-dropdown').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders all the links to the review apps', () => {
|
|
|
|
const allUrls = wrapper.findAll('.js-deploy-url-menu-item').wrappers;
|
|
|
|
const expectedUrls = deploymentMockData.changes.map(change => change.external_url);
|
|
|
|
|
|
|
|
expectedUrls.forEach((expectedUrl, idx) => {
|
|
|
|
const deployUrl = allUrls[idx];
|
|
|
|
|
|
|
|
expect(deployUrl.attributes().href).not.toBeNull();
|
|
|
|
expect(deployUrl.attributes().href).toEqual(expectedUrl);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|