2021-06-08 01:23:25 +05:30
|
|
|
import { GlDropdown, GlLink } from '@gitlab/ui';
|
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
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;
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
const createComponent = (options = {}) => {
|
|
|
|
wrapper = mountExtended(DeploymentViewButton, {
|
2020-01-01 13:55:28 +05:30
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-06-08 01:23:25 +05:30
|
|
|
createComponent({
|
2020-01-01 13:55:28 +05:30
|
|
|
propsData: {
|
|
|
|
deployment: deploymentMockData,
|
2020-03-13 15:44:24 +05:30
|
|
|
appButtonText,
|
2020-01-01 13:55:28 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
const findReviewAppLink = () => wrapper.findComponent(ReviewAppLink);
|
|
|
|
const findMrWigdetDeploymentDropdown = () => wrapper.findComponent(GlDropdown);
|
|
|
|
const findMrWigdetDeploymentDropdownIcon = () =>
|
|
|
|
wrapper.findByTestId('mr-wigdet-deployment-dropdown-icon');
|
|
|
|
const findDeployUrlMenuItems = () => wrapper.findAllComponents(GlLink);
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
describe('text', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
it('renders text as passed', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findReviewAppLink().props().display.text).toBe(appButtonText.text);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without changes', () => {
|
|
|
|
beforeEach(() => {
|
2021-06-08 01:23:25 +05:30
|
|
|
createComponent({
|
2020-01-01 13:55:28 +05:30
|
|
|
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', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findMrWigdetDeploymentDropdown().exists()).toBe(false);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with a single change', () => {
|
|
|
|
beforeEach(() => {
|
2021-06-08 01:23:25 +05:30
|
|
|
createComponent({
|
2020-01-01 13:55:28 +05:30
|
|
|
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', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findMrWigdetDeploymentDropdown().exists()).toBe(false);
|
|
|
|
expect(findMrWigdetDeploymentDropdownIcon().exists()).toBe(false);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the link to the review app linked to to the first change', () => {
|
|
|
|
const expectedUrl = deploymentMockData.changes[0].external_url;
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findReviewAppLink().attributes('href')).toBe(expectedUrl);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with multiple changes', () => {
|
|
|
|
beforeEach(() => {
|
2021-06-08 01:23:25 +05:30
|
|
|
createComponent({
|
2020-01-01 13:55:28 +05:30
|
|
|
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', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findMrWigdetDeploymentDropdown().exists()).toBe(true);
|
|
|
|
expect(findMrWigdetDeploymentDropdownIcon().exists()).toBe(true);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders all the links to the review apps', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
const allUrls = findDeployUrlMenuItems().wrappers;
|
2021-03-08 18:12:59 +05:30
|
|
|
const expectedUrls = deploymentMockData.changes.map((change) => change.external_url);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
expectedUrls.forEach((expectedUrl, idx) => {
|
|
|
|
const deployUrl = allUrls[idx];
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(deployUrl.attributes('href')).toBe(expectedUrl);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|