debian-mirror-gitlab/spec/frontend/environments/confirm_rollback_modal_spec.js

105 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-10-27 15:23:28 +05:30
import { GlModal, GlSprintf } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2019-07-07 11:18:12 +05:30
import ConfirmRollbackModal from '~/environments/components/confirm_rollback_modal.vue';
import eventHub from '~/environments/event_hub';
describe('Confirm Rollback Modal Component', () => {
let environment;
2021-10-27 15:23:28 +05:30
let component;
2019-07-07 11:18:12 +05:30
2021-10-27 15:23:28 +05:30
const envWithLastDeployment = {
name: 'test',
last_deployment: {
commit: {
short_id: 'abc0123',
2019-07-07 11:18:12 +05:30
},
2021-10-27 15:23:28 +05:30
},
modalId: 'test',
};
2019-07-07 11:18:12 +05:30
2021-10-27 15:23:28 +05:30
const envWithoutLastDeployment = {
name: 'test',
modalId: 'test',
commitShortSha: 'abc0123',
commitUrl: 'test/-/commit/abc0123',
};
2019-07-07 11:18:12 +05:30
2021-10-27 15:23:28 +05:30
const retryPath = 'test/-/jobs/123/retry';
2019-07-07 11:18:12 +05:30
2021-10-27 15:23:28 +05:30
const createComponent = (props = {}) => {
component = shallowMount(ConfirmRollbackModal, {
2019-07-07 11:18:12 +05:30
propsData: {
2021-10-27 15:23:28 +05:30
...props,
},
stubs: {
GlSprintf,
2019-07-07 11:18:12 +05:30
},
});
2021-10-27 15:23:28 +05:30
};
2019-07-07 11:18:12 +05:30
2021-10-27 15:23:28 +05:30
describe.each`
hasMultipleCommits | environmentData | retryUrl | primaryPropsAttrs
${true} | ${envWithLastDeployment} | ${null} | ${[{ variant: 'danger' }]}
${false} | ${envWithoutLastDeployment} | ${retryPath} | ${[{ variant: 'danger' }, { 'data-method': 'post' }, { href: retryPath }]}
`(
'when hasMultipleCommits=$hasMultipleCommits',
({ hasMultipleCommits, environmentData, retryUrl, primaryPropsAttrs }) => {
beforeEach(() => {
environment = environmentData;
});
2019-07-07 11:18:12 +05:30
2021-10-27 15:23:28 +05:30
it('should show "Rollback" when isLastDeployment is false', () => {
createComponent({
environment: {
...environment,
isLastDeployment: false,
},
hasMultipleCommits,
retryUrl,
});
const modal = component.find(GlModal);
expect(modal.attributes('title')).toContain('Rollback');
expect(modal.attributes('title')).toContain('test');
expect(modal.props('actionPrimary').text).toBe('Rollback');
expect(modal.props('actionPrimary').attributes).toEqual(primaryPropsAttrs);
expect(modal.text()).toContain('commit abc0123');
expect(modal.text()).toContain('Are you sure you want to continue?');
});
it('should show "Re-deploy" when isLastDeployment is true', () => {
createComponent({
environment: {
...environment,
isLastDeployment: true,
},
hasMultipleCommits,
});
const modal = component.find(GlModal);
expect(modal.attributes('title')).toContain('Re-deploy');
expect(modal.attributes('title')).toContain('test');
expect(modal.props('actionPrimary').text).toBe('Re-deploy');
expect(modal.text()).toContain('commit abc0123');
expect(modal.text()).toContain('Are you sure you want to continue?');
});
it('should emit the "rollback" event when "ok" is clicked', () => {
const env = { ...environmentData, isLastDeployment: true };
createComponent({
environment: env,
hasMultipleCommits,
});
const eventHubSpy = jest.spyOn(eventHub, '$emit');
const modal = component.find(GlModal);
modal.vm.$emit('ok');
2019-07-07 11:18:12 +05:30
2021-10-27 15:23:28 +05:30
expect(eventHubSpy).toHaveBeenCalledWith('rollbackEnvironment', env);
});
},
);
2019-07-07 11:18:12 +05:30
});