summaryrefslogtreecommitdiff
path: root/spec/frontend/environments
diff options
context:
space:
mode:
authorNathan Friend <nathan@gitlab.com>2019-08-12 15:22:58 -0400
committerNathan Friend <nathan@gitlab.com>2019-08-12 15:22:58 -0400
commitda306cdb0f3125d0b9682d11c2ec007cdfd1746f (patch)
tree8873c93631737d1989703c9d52b1de34ab133446 /spec/frontend/environments
parent22f3142b83fb08589eb1212cc378996975b2157f (diff)
downloadgitlab-ce-da306cdb0f3125d0b9682d11c2ec007cdfd1746f.tar.gz
Convert spec/javascripts/environments/*rollback* tests to Jest61800-migrate-environment-rollback-tests-to-jest
This commit converts two Jasmine tests into Jest tests.
Diffstat (limited to 'spec/frontend/environments')
-rw-r--r--spec/frontend/environments/confirm_rollback_modal_spec.js70
-rw-r--r--spec/frontend/environments/environment_rollback_spec.js53
2 files changed, 123 insertions, 0 deletions
diff --git a/spec/frontend/environments/confirm_rollback_modal_spec.js b/spec/frontend/environments/confirm_rollback_modal_spec.js
new file mode 100644
index 00000000000..a1a22274e8f
--- /dev/null
+++ b/spec/frontend/environments/confirm_rollback_modal_spec.js
@@ -0,0 +1,70 @@
+import { shallowMount } from '@vue/test-utils';
+import { GlModal } from '@gitlab/ui';
+import ConfirmRollbackModal from '~/environments/components/confirm_rollback_modal.vue';
+import eventHub from '~/environments/event_hub';
+
+describe('Confirm Rollback Modal Component', () => {
+ let environment;
+
+ beforeEach(() => {
+ environment = {
+ name: 'test',
+ last_deployment: {
+ commit: {
+ short_id: 'abc0123',
+ },
+ },
+ modalId: 'test',
+ };
+ });
+
+ it('should show "Rollback" when isLastDeployment is false', () => {
+ const component = shallowMount(ConfirmRollbackModal, {
+ propsData: {
+ environment: {
+ ...environment,
+ isLastDeployment: false,
+ },
+ },
+ });
+ const modal = component.find(GlModal);
+
+ expect(modal.attributes('title')).toContain('Rollback');
+ expect(modal.attributes('title')).toContain('test');
+ expect(modal.attributes('ok-title')).toBe('Rollback');
+ 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', () => {
+ const component = shallowMount(ConfirmRollbackModal, {
+ propsData: {
+ environment: {
+ ...environment,
+ isLastDeployment: true,
+ },
+ },
+ });
+ const modal = component.find(GlModal);
+
+ expect(modal.attributes('title')).toContain('Re-deploy');
+ expect(modal.attributes('title')).toContain('test');
+ expect(modal.attributes('ok-title')).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', () => {
+ environment = { ...environment, isLastDeployment: true };
+ const component = shallowMount(ConfirmRollbackModal, {
+ propsData: {
+ environment,
+ },
+ });
+ const eventHubSpy = jest.spyOn(eventHub, '$emit');
+ const modal = component.find(GlModal);
+ modal.vm.$emit('ok');
+
+ expect(eventHubSpy).toHaveBeenCalledWith('rollbackEnvironment', environment);
+ });
+});
diff --git a/spec/frontend/environments/environment_rollback_spec.js b/spec/frontend/environments/environment_rollback_spec.js
new file mode 100644
index 00000000000..fb62a096c3d
--- /dev/null
+++ b/spec/frontend/environments/environment_rollback_spec.js
@@ -0,0 +1,53 @@
+import { shallowMount, mount } from '@vue/test-utils';
+import { GlButton } from '@gitlab/ui';
+import eventHub from '~/environments/event_hub';
+import RollbackComponent from '~/environments/components/environment_rollback.vue';
+
+describe('Rollback Component', () => {
+ const retryUrl = 'https://gitlab.com/retry';
+
+ it('Should render Re-deploy label when isLastDeployment is true', () => {
+ const wrapper = mount(RollbackComponent, {
+ propsData: {
+ retryUrl,
+ isLastDeployment: true,
+ environment: {},
+ },
+ });
+
+ expect(wrapper.element).toHaveSpriteIcon('repeat');
+ });
+
+ it('Should render Rollback label when isLastDeployment is false', () => {
+ const wrapper = mount(RollbackComponent, {
+ propsData: {
+ retryUrl,
+ isLastDeployment: false,
+ environment: {},
+ },
+ });
+
+ expect(wrapper.element).toHaveSpriteIcon('redo');
+ });
+
+ it('should emit a "rollback" event on button click', () => {
+ const eventHubSpy = jest.spyOn(eventHub, '$emit');
+ const wrapper = shallowMount(RollbackComponent, {
+ propsData: {
+ retryUrl,
+ environment: {
+ name: 'test',
+ },
+ },
+ });
+ const button = wrapper.find(GlButton);
+
+ button.vm.$emit('click');
+
+ expect(eventHubSpy).toHaveBeenCalledWith('requestRollbackEnvironment', {
+ retryUrl,
+ isLastDeployment: true,
+ name: 'test',
+ });
+ });
+});