diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-25 18:12:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-25 18:12:32 +0300 |
commit | 7d8d5a3dab415672a41ab29c3bfa9581f275dc50 (patch) | |
tree | 7b9249d8ca8c12ad899b4e6d968193d58e63f458 /spec/frontend/deploy_keys | |
parent | 868c8c35fbddd439f4df76a5954e2a1caa2af3cc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/deploy_keys')
-rw-r--r-- | spec/frontend/deploy_keys/components/action_btn_spec.js | 15 | ||||
-rw-r--r-- | spec/frontend/deploy_keys/components/app_spec.js | 114 | ||||
-rw-r--r-- | spec/frontend/deploy_keys/components/key_spec.js | 14 |
3 files changed, 62 insertions, 81 deletions
diff --git a/spec/frontend/deploy_keys/components/action_btn_spec.js b/spec/frontend/deploy_keys/components/action_btn_spec.js index 6ac68061518..c4c7a9aea2d 100644 --- a/spec/frontend/deploy_keys/components/action_btn_spec.js +++ b/spec/frontend/deploy_keys/components/action_btn_spec.js @@ -1,5 +1,6 @@ import { GlButton } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; +import { nextTick } from 'vue'; import data from 'test_fixtures/deploy_keys/keys.json'; import actionBtn from '~/deploy_keys/components/action_btn.vue'; import eventHub from '~/deploy_keys/eventhub'; @@ -37,21 +38,19 @@ describe('Deploy keys action btn', () => { }); }); - it('sends eventHub event with btn type', () => { + it('sends eventHub event with btn type', async () => { jest.spyOn(eventHub, '$emit').mockImplementation(() => {}); findButton().vm.$emit('click'); - return wrapper.vm.$nextTick().then(() => { - expect(eventHub.$emit).toHaveBeenCalledWith('enable.key', deployKey, expect.anything()); - }); + await nextTick(); + expect(eventHub.$emit).toHaveBeenCalledWith('enable.key', deployKey, expect.anything()); }); - it('shows loading spinner after click', () => { + it('shows loading spinner after click', async () => { findButton().vm.$emit('click'); - return wrapper.vm.$nextTick().then(() => { - expect(findButton().props('loading')).toBe(true); - }); + await nextTick(); + expect(findButton().props('loading')).toBe(true); }); }); diff --git a/spec/frontend/deploy_keys/components/app_spec.js b/spec/frontend/deploy_keys/components/app_spec.js index 598b7a0f173..79a9aaa9184 100644 --- a/spec/frontend/deploy_keys/components/app_spec.js +++ b/spec/frontend/deploy_keys/components/app_spec.js @@ -1,5 +1,6 @@ import { mount } from '@vue/test-utils'; import MockAdapter from 'axios-mock-adapter'; +import { nextTick } from 'vue'; import data from 'test_fixtures/deploy_keys/keys.json'; import waitForPromises from 'helpers/wait_for_promises'; import { TEST_HOST } from 'spec/test_constants'; @@ -39,20 +40,18 @@ describe('Deploy keys app component', () => { const findKeyPanels = () => wrapper.findAll('.deploy-keys .gl-tabs-nav li'); const findModal = () => wrapper.findComponent(ConfirmModal); - it('renders loading icon while waiting for request', () => { + it('renders loading icon while waiting for request', async () => { mock.onGet(TEST_ENDPOINT).reply(() => new Promise()); mountComponent(); - return wrapper.vm.$nextTick().then(() => { - expect(findLoadingIcon().exists()).toBe(true); - }); + await nextTick(); + expect(findLoadingIcon().exists()).toBe(true); }); - it('renders keys panels', () => { - return mountComponent().then(() => { - expect(findKeyPanels().length).toBe(3); - }); + it('renders keys panels', async () => { + await mountComponent(); + expect(findKeyPanels().length).toBe(3); }); it.each` @@ -75,72 +74,55 @@ describe('Deploy keys app component', () => { }); }); - it('re-fetches deploy keys when enabling a key', () => { + it('re-fetches deploy keys when enabling a key', async () => { const key = data.public_keys[0]; - return mountComponent() - .then(() => { - jest.spyOn(wrapper.vm.service, 'getKeys').mockImplementation(() => {}); - jest.spyOn(wrapper.vm.service, 'enableKey').mockImplementation(() => Promise.resolve()); - - eventHub.$emit('enable.key', key); - - return wrapper.vm.$nextTick(); - }) - .then(() => { - expect(wrapper.vm.service.enableKey).toHaveBeenCalledWith(key.id); - expect(wrapper.vm.service.getKeys).toHaveBeenCalled(); - }); + await mountComponent(); + jest.spyOn(wrapper.vm.service, 'getKeys').mockImplementation(() => {}); + jest.spyOn(wrapper.vm.service, 'enableKey').mockImplementation(() => Promise.resolve()); + + eventHub.$emit('enable.key', key); + + await nextTick(); + expect(wrapper.vm.service.enableKey).toHaveBeenCalledWith(key.id); + expect(wrapper.vm.service.getKeys).toHaveBeenCalled(); }); - it('re-fetches deploy keys when disabling a key', () => { + it('re-fetches deploy keys when disabling a key', async () => { const key = data.public_keys[0]; - return mountComponent() - .then(() => { - jest.spyOn(wrapper.vm.service, 'getKeys').mockImplementation(() => {}); - jest.spyOn(wrapper.vm.service, 'disableKey').mockImplementation(() => Promise.resolve()); - - eventHub.$emit('disable.key', key, () => {}); - - return wrapper.vm.$nextTick(); - }) - .then(() => { - expect(findModal().props('visible')).toBe(true); - findModal().vm.$emit('remove'); - - return wrapper.vm.$nextTick(); - }) - .then(() => { - expect(wrapper.vm.service.disableKey).toHaveBeenCalledWith(key.id); - expect(wrapper.vm.service.getKeys).toHaveBeenCalled(); - }); + await mountComponent(); + jest.spyOn(wrapper.vm.service, 'getKeys').mockImplementation(() => {}); + jest.spyOn(wrapper.vm.service, 'disableKey').mockImplementation(() => Promise.resolve()); + + eventHub.$emit('disable.key', key, () => {}); + + await nextTick(); + expect(findModal().props('visible')).toBe(true); + findModal().vm.$emit('remove'); + + await nextTick(); + expect(wrapper.vm.service.disableKey).toHaveBeenCalledWith(key.id); + expect(wrapper.vm.service.getKeys).toHaveBeenCalled(); }); - it('calls disableKey when removing a key', () => { + it('calls disableKey when removing a key', async () => { const key = data.public_keys[0]; - return mountComponent() - .then(() => { - jest.spyOn(wrapper.vm.service, 'getKeys').mockImplementation(() => {}); - jest.spyOn(wrapper.vm.service, 'disableKey').mockImplementation(() => Promise.resolve()); - - eventHub.$emit('remove.key', key, () => {}); - - return wrapper.vm.$nextTick(); - }) - .then(() => { - expect(findModal().props('visible')).toBe(true); - findModal().vm.$emit('remove'); - - return wrapper.vm.$nextTick(); - }) - .then(() => { - expect(wrapper.vm.service.disableKey).toHaveBeenCalledWith(key.id); - expect(wrapper.vm.service.getKeys).toHaveBeenCalled(); - }); + await mountComponent(); + jest.spyOn(wrapper.vm.service, 'getKeys').mockImplementation(() => {}); + jest.spyOn(wrapper.vm.service, 'disableKey').mockImplementation(() => Promise.resolve()); + + eventHub.$emit('remove.key', key, () => {}); + + await nextTick(); + expect(findModal().props('visible')).toBe(true); + findModal().vm.$emit('remove'); + + await nextTick(); + expect(wrapper.vm.service.disableKey).toHaveBeenCalledWith(key.id); + expect(wrapper.vm.service.getKeys).toHaveBeenCalled(); }); - it('hasKeys returns true when there are keys', () => { - return mountComponent().then(() => { - expect(wrapper.vm.hasKeys).toEqual(3); - }); + it('hasKeys returns true when there are keys', async () => { + await mountComponent(); + expect(wrapper.vm.hasKeys).toEqual(3); }); }); diff --git a/spec/frontend/deploy_keys/components/key_spec.js b/spec/frontend/deploy_keys/components/key_spec.js index 51c120d8213..8599c55c908 100644 --- a/spec/frontend/deploy_keys/components/key_spec.js +++ b/spec/frontend/deploy_keys/components/key_spec.js @@ -1,4 +1,5 @@ import { mount } from '@vue/test-utils'; +import { nextTick } from 'vue'; import data from 'test_fixtures/deploy_keys/keys.json'; import key from '~/deploy_keys/components/key.vue'; import DeployKeysStore from '~/deploy_keys/store'; @@ -95,18 +96,17 @@ describe('Deploy keys key', () => { expect(labels.at(1).attributes('title')).toContain('Expand'); }); - it('expands all project labels after click', () => { + it('expands all project labels after click', async () => { createComponent({ deployKey }); const { length } = deployKey.deploy_keys_projects; wrapper.findAll('.deploy-project-label').at(1).trigger('click'); - return wrapper.vm.$nextTick().then(() => { - const labels = wrapper.findAll('.deploy-project-label'); + await nextTick(); + const labels = wrapper.findAll('.deploy-project-label'); - expect(labels.length).toBe(length); - expect(labels.at(1).text()).not.toContain(`+${length} others`); - expect(labels.at(1).attributes('title')).not.toContain('Expand'); - }); + expect(labels.length).toBe(length); + expect(labels.at(1).text()).not.toContain(`+${length} others`); + expect(labels.at(1).attributes('title')).not.toContain('Expand'); }); it('shows two projects', () => { |