diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 09:07:48 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 09:07:48 +0000 |
commit | 5bd24a54ef4ce3a38a860eb53b66d062c2382971 (patch) | |
tree | 5f5e65571dfcb2c62c27600ee7655dec4b44c923 /spec/frontend | |
parent | 74673d04d25ffed35cbcf17cd42969bed0a4e705 (diff) | |
download | gitlab-ce-5bd24a54ef4ce3a38a860eb53b66d062c2382971.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
18 files changed, 206 insertions, 56 deletions
diff --git a/spec/frontend/boards/boards_store_spec.js b/spec/frontend/boards/boards_store_spec.js index 3588197ebdc..bf3d81d3117 100644 --- a/spec/frontend/boards/boards_store_spec.js +++ b/spec/frontend/boards/boards_store_spec.js @@ -41,7 +41,6 @@ describe('boardsStore', () => { afterEach(() => { axiosMock.restore(); - jest.clearAllMocks(); }); const setupDefaultResponses = () => { diff --git a/spec/frontend/clusters/clusters_bundle_spec.js b/spec/frontend/clusters/clusters_bundle_spec.js index 7b1d96c8da5..d7c648bcd20 100644 --- a/spec/frontend/clusters/clusters_bundle_spec.js +++ b/spec/frontend/clusters/clusters_bundle_spec.js @@ -46,7 +46,6 @@ describe('Clusters', () => { afterEach(() => { cluster.destroy(); mock.restore(); - jest.clearAllMocks(); }); describe('class constructor', () => { diff --git a/spec/frontend/clusters/components/__snapshots__/remove_cluster_confirmation_spec.js.snap b/spec/frontend/clusters/components/__snapshots__/remove_cluster_confirmation_spec.js.snap new file mode 100644 index 00000000000..8f406c62824 --- /dev/null +++ b/spec/frontend/clusters/components/__snapshots__/remove_cluster_confirmation_spec.js.snap @@ -0,0 +1,80 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Remove cluster confirmation modal renders splitbutton with modal included 1`] = ` +<div> + <div + class="dropdown btn-group b-dropdown gl-dropdown" + > + <button + class="btn btn-danger" + type="button" + > + + Remove integration and resources + + <!----> + </button> + <button + aria-expanded="false" + aria-haspopup="true" + class="btn dropdown-toggle btn-danger dropdown-toggle-split" + type="button" + > + <span + class="sr-only" + > + Toggle Dropdown + </span> + </button> + <ul + class="dropdown-menu dropdown-menu-selectable dropdown-menu-large" + role="menu" + tabindex="-1" + > + <li> + <button + class="dropdown-item is-active" + role="menuitem" + type="button" + > + <strong> + Remove integration and resources + </strong> + + <div> + Deletes all GitLab resources attached to this cluster during removal + </div> + </button> + </li> + + <li> + <hr + aria-orientation="horizontal" + class="dropdown-divider" + role="separator" + /> + </li> + <li> + <button + class="dropdown-item" + role="menuitem" + type="button" + > + <strong> + Remove integration + </strong> + + <div> + Removes cluster from project but keeps associated resources + </div> + </button> + </li> + + <!----> + + </ul> + </div> + + <!----> +</div> +`; diff --git a/spec/frontend/clusters/components/remove_cluster_confirmation_spec.js b/spec/frontend/clusters/components/remove_cluster_confirmation_spec.js new file mode 100644 index 00000000000..b5aead238ad --- /dev/null +++ b/spec/frontend/clusters/components/remove_cluster_confirmation_spec.js @@ -0,0 +1,57 @@ +import { mount } from '@vue/test-utils'; +import { GlModal } from '@gitlab/ui'; +import SplitButton from '~/vue_shared/components/split_button.vue'; +import RemoveClusterConfirmation from '~/clusters/components/remove_cluster_confirmation.vue'; + +describe('Remove cluster confirmation modal', () => { + let wrapper; + + const createComponent = (props = {}) => { + wrapper = mount(RemoveClusterConfirmation, { + propsData: { + clusterPath: 'clusterPath', + clusterName: 'clusterName', + ...props, + }, + sync: false, + }); + }; + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + }); + + it('renders splitbutton with modal included', () => { + createComponent(); + expect(wrapper.element).toMatchSnapshot(); + }); + + describe('split button dropdown', () => { + const findModal = () => wrapper.find(GlModal).vm; + const findSplitButton = () => wrapper.find(SplitButton).vm; + + beforeEach(() => { + createComponent({ clusterName: 'my-test-cluster' }); + jest.spyOn(findModal(), 'show').mockReturnValue(); + }); + + it('opens modal with "cleanup" option', () => { + findSplitButton().$emit('remove-cluster-and-cleanup'); + + return wrapper.vm.$nextTick().then(() => { + expect(findModal().show).toHaveBeenCalled(); + expect(wrapper.vm.confirmCleanup).toEqual(true); + }); + }); + + it('opens modal without "cleanup" option', () => { + findSplitButton().$emit('remove-cluster'); + + return wrapper.vm.$nextTick().then(() => { + expect(findModal().show).toHaveBeenCalled(); + expect(wrapper.vm.confirmCleanup).toEqual(false); + }); + }); + }); +}); diff --git a/spec/frontend/commit/commit_pipeline_status_component_spec.js b/spec/frontend/commit/commit_pipeline_status_component_spec.js index 36fc6ee52a8..a2a6d405eab 100644 --- a/spec/frontend/commit/commit_pipeline_status_component_spec.js +++ b/spec/frontend/commit/commit_pipeline_status_component_spec.js @@ -44,7 +44,6 @@ describe('Commit pipeline status component', () => { afterEach(() => { wrapper.destroy(); wrapper = null; - jest.clearAllMocks(); }); describe('Visibility management', () => { diff --git a/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js b/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js index fda1f71b1f9..1139f094705 100644 --- a/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js +++ b/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js @@ -272,14 +272,11 @@ describe('EKS Cluster Store Actions', () => { payload = { name: ['Create cluster failed'] }; }); - it('commits createClusterError mutation', () => { + it('commits createClusterError mutation and displays flash message', () => testAction(actions.createClusterError, payload, state, [ { type: CREATE_CLUSTER_ERROR, payload }, - ]); - }); - - it('creates a flash that displays the create cluster error', () => { - expect(createFlash).toHaveBeenCalledWith(payload.name[0]); - }); + ]).then(() => { + expect(createFlash).toHaveBeenCalledWith(payload.name[0]); + })); }); }); diff --git a/spec/frontend/ide/components/preview/clientside_spec.js b/spec/frontend/ide/components/preview/clientside_spec.js index 6a33f4998c5..5cb9e598fc4 100644 --- a/spec/frontend/ide/components/preview/clientside_spec.js +++ b/spec/frontend/ide/components/preview/clientside_spec.js @@ -68,10 +68,6 @@ describe('IDE clientside preview', () => { jest.useRealTimers(); }); - beforeEach(() => { - jest.clearAllMocks(); - }); - afterEach(() => { wrapper.destroy(); }); diff --git a/spec/frontend/ide/stores/modules/pipelines/actions_spec.js b/spec/frontend/ide/stores/modules/pipelines/actions_spec.js index a58c7b8f819..b08d1cd01da 100644 --- a/spec/frontend/ide/stores/modules/pipelines/actions_spec.js +++ b/spec/frontend/ide/stores/modules/pipelines/actions_spec.js @@ -111,8 +111,6 @@ describe('IDE pipelines actions', () => { }); describe('fetchLatestPipeline', () => { - beforeEach(() => {}); - afterEach(() => { stopPipelinePolling(); clearEtagPoll(); diff --git a/spec/frontend/issuables_list/components/issuables_list_app_spec.js b/spec/frontend/issuables_list/components/issuables_list_app_spec.js index 666ccc07416..621e8b8aa54 100644 --- a/spec/frontend/issuables_list/components/issuables_list_app_spec.js +++ b/spec/frontend/issuables_list/components/issuables_list_app_spec.js @@ -72,7 +72,6 @@ describe('Issuables list component', () => { afterEach(() => { wrapper.destroy(); mockAxios.restore(); - jest.clearAllMocks(); window.location = oldLocation; }); diff --git a/spec/frontend/jest_self_check/mocks_spec.js b/spec/frontend/jest_self_check/mocks_spec.js new file mode 100644 index 00000000000..f1e9e12e633 --- /dev/null +++ b/spec/frontend/jest_self_check/mocks_spec.js @@ -0,0 +1,43 @@ +import * as textUtils from '~/lib/utils/text_utility'; + +jest.mock('~/lib/utils/text_utility'); + +describe('does restore mocks config work?', () => { + describe('shared spy', () => { + const spy = jest.fn(); + + beforeEach(() => { + spy(); + }); + + it('is only called once', () => { + expect(spy).toHaveBeenCalledTimes(1); + }); + + it('is only called once B', () => { + expect(spy).toHaveBeenCalledTimes(1); + }); + + it('is only called once C', () => { + expect(spy).toHaveBeenCalledTimes(1); + }); + }); + + describe('module mock', () => { + beforeEach(() => { + textUtils.humanize(''); + }); + + it('is only called once', () => { + expect(textUtils.humanize).toHaveBeenCalledTimes(1); + }); + + it('is only called once B', () => { + expect(textUtils.humanize).toHaveBeenCalledTimes(1); + }); + + it('is only called once C', () => { + expect(textUtils.humanize).toHaveBeenCalledTimes(1); + }); + }); +}); diff --git a/spec/frontend/notes/components/comment_form_spec.js b/spec/frontend/notes/components/comment_form_spec.js index 10d92e9535c..7652f48474d 100644 --- a/spec/frontend/notes/components/comment_form_spec.js +++ b/spec/frontend/notes/components/comment_form_spec.js @@ -50,7 +50,6 @@ describe('issue_comment_form component', () => { afterEach(() => { axiosMock.restore(); wrapper.destroy(); - jest.clearAllMocks(); }); describe('user is logged in', () => { diff --git a/spec/frontend/pages/admin/users/components/user_modal_manager_spec.js b/spec/frontend/pages/admin/users/components/user_modal_manager_spec.js index 7653fffc502..c88a182660d 100644 --- a/spec/frontend/pages/admin/users/components/user_modal_manager_spec.js +++ b/spec/frontend/pages/admin/users/components/user_modal_manager_spec.js @@ -83,10 +83,6 @@ describe('Users admin page Modal Manager', () => { jest.spyOn(document, 'removeEventListener'); }); - afterEach(() => { - jest.clearAllMocks(); - }); - afterAll(() => { jest.restoreAllMocks(); }); diff --git a/spec/frontend/project_find_file_spec.js b/spec/frontend/project_find_file_spec.js index b697ca01046..b4c6d202e14 100644 --- a/spec/frontend/project_find_file_spec.js +++ b/spec/frontend/project_find_file_spec.js @@ -42,21 +42,23 @@ describe('ProjectFindFile', () => { })); const files = [ - 'fileA.txt', - 'fileB.txt', - 'fi#leC.txt', - 'folderA/fileD.txt', - 'folder#B/fileE.txt', - 'folde?rC/fil#F.txt', + { path: 'fileA.txt', escaped: 'fileA.txt' }, + { path: 'fileB.txt', escaped: 'fileB.txt' }, + { path: 'fi#leC.txt', escaped: 'fi%23leC.txt' }, + { path: 'folderA/fileD.txt', escaped: 'folderA/fileD.txt' }, + { path: 'folder#B/fileE.txt', escaped: 'folder%23B/fileE.txt' }, + { path: 'folde?rC/fil#F.txt', escaped: 'folde%3FrC/fil%23F.txt' }, ]; - beforeEach(() => { + beforeEach(done => { // Create a mock adapter for stubbing axios API requests mock = new MockAdapter(axios); element = $(TEMPLATE); - mock.onGet(FILE_FIND_URL).replyOnce(200, files); + mock.onGet(FILE_FIND_URL).replyOnce(200, files.map(x => x.path)); getProjectFindFileInstance(); // This triggers a load / axios call + subsequent render in the constructor + + setImmediate(done); }); afterEach(() => { @@ -65,26 +67,19 @@ describe('ProjectFindFile', () => { sanitize.mockClear(); }); - it('loads and renders elements from remote server', done => { - setImmediate(() => { - expect(findFiles()).toEqual( - files.map(text => ({ - text, - href: `${BLOB_URL_TEMPLATE}/${encodeURIComponent(text)}`, - })), - ); - - done(); - }); + it('loads and renders elements from remote server', () => { + expect(findFiles()).toEqual( + files.map(({ path, escaped }) => ({ + text: path, + href: `${BLOB_URL_TEMPLATE}/${escaped}`, + })), + ); }); - it('sanitizes search text', done => { + it('sanitizes search text', () => { const searchText = element.find('.file-finder-input').val(); - setImmediate(() => { - expect(sanitize).toHaveBeenCalledTimes(1); - expect(sanitize).toHaveBeenCalledWith(searchText); - done(); - }); + expect(sanitize).toHaveBeenCalledTimes(1); + expect(sanitize).toHaveBeenCalledWith(searchText); }); }); diff --git a/spec/frontend/registry/list/components/app_spec.js b/spec/frontend/registry/list/components/app_spec.js index f2733ac9fef..5072a285f83 100644 --- a/spec/frontend/registry/list/components/app_spec.js +++ b/spec/frontend/registry/list/components/app_spec.js @@ -52,7 +52,6 @@ describe('Registry List', () => { }); afterEach(() => { - jest.clearAllMocks(); Vue.config.silent = false; wrapper.destroy(); }); diff --git a/spec/frontend/repository/components/table/row_spec.js b/spec/frontend/repository/components/table/row_spec.js index aa0b9385f1a..94fa8b1e363 100644 --- a/spec/frontend/repository/components/table/row_spec.js +++ b/spec/frontend/repository/components/table/row_spec.js @@ -35,7 +35,6 @@ function factory(propsData = {}) { describe('Repository table row component', () => { afterEach(() => { vm.destroy(); - jest.clearAllMocks(); }); it('renders table row', () => { diff --git a/spec/frontend/sentry/sentry_config_spec.js b/spec/frontend/sentry/sentry_config_spec.js index 62b8bbd50a2..bcc7f29b98d 100644 --- a/spec/frontend/sentry/sentry_config_spec.js +++ b/spec/frontend/sentry/sentry_config_spec.js @@ -54,8 +54,7 @@ describe('SentryConfig', () => { }); it('should not call setUser if there is no current user ID', () => { - jest.clearAllMocks(); - + SentryConfig.setUser.mockClear(); options.currentUserId = undefined; SentryConfig.init(options); @@ -167,8 +166,6 @@ describe('SentryConfig', () => { describe('if no err is provided', () => { beforeEach(() => { - jest.clearAllMocks(); - SentryConfig.handleSentryErrors(event, req, config); }); @@ -191,8 +188,6 @@ describe('SentryConfig', () => { beforeEach(() => { req.responseText = undefined; - jest.clearAllMocks(); - SentryConfig.handleSentryErrors(event, req, config, err); }); diff --git a/spec/frontend/sidebar/confidential_issue_sidebar_spec.js b/spec/frontend/sidebar/confidential_issue_sidebar_spec.js index 68dde14880a..432ec111e52 100644 --- a/spec/frontend/sidebar/confidential_issue_sidebar_spec.js +++ b/spec/frontend/sidebar/confidential_issue_sidebar_spec.js @@ -42,7 +42,6 @@ describe('Confidential Issue Sidebar Block', () => { }; beforeEach(() => { - jest.clearAllMocks(); jest.spyOn(window.location, 'reload').mockImplementation(); }); diff --git a/spec/frontend/vue_shared/components/__snapshots__/split_button_spec.js.snap b/spec/frontend/vue_shared/components/__snapshots__/split_button_spec.js.snap index 95296de5a5d..530428ef27c 100644 --- a/spec/frontend/vue_shared/components/__snapshots__/split_button_spec.js.snap +++ b/spec/frontend/vue_shared/components/__snapshots__/split_button_spec.js.snap @@ -5,6 +5,7 @@ exports[`SplitButton renders actionItems 1`] = ` menu-class="dropdown-menu-selectable " split="true" text="professor" + variant="secondary" > <gldropdownitem-stub active="true" |