diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-04 12:13:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-04 12:13:07 +0300 |
commit | 6cd4578a23ffe0fb94632f83a07a25d01f8d6821 (patch) | |
tree | d21e9881e4ceb8ae6f28451f0797acc59e7cd1e8 /spec/frontend/token_access | |
parent | b6a194f6625042a09e083443c3326cc61aefc4c0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/token_access')
-rw-r--r-- | spec/frontend/token_access/mock_data.js | 26 | ||||
-rw-r--r-- | spec/frontend/token_access/opt_in_jwt_spec.js | 144 | ||||
-rw-r--r-- | spec/frontend/token_access/token_access_app_spec.js | 6 |
3 files changed, 0 insertions, 176 deletions
diff --git a/spec/frontend/token_access/mock_data.js b/spec/frontend/token_access/mock_data.js index 67ee197b831..a4b5532108a 100644 --- a/spec/frontend/token_access/mock_data.js +++ b/spec/frontend/token_access/mock_data.js @@ -121,32 +121,6 @@ export const mockFields = [ }, ]; -export const optInJwtQueryResponse = (optInJwt) => ({ - data: { - project: { - id: '1', - ciCdSettings: { - optInJwt, - __typename: 'ProjectCiCdSetting', - }, - __typename: 'Project', - }, - }, -}); - -export const optInJwtMutationResponse = (optInJwt) => ({ - data: { - projectCiCdSettingsUpdate: { - ciCdSettings: { - optInJwt, - __typename: 'ProjectCiCdSetting', - }, - errors: [], - __typename: 'ProjectCiCdSettingsUpdatePayload', - }, - }, -}); - export const inboundJobTokenScopeEnabledResponse = { data: { project: { diff --git a/spec/frontend/token_access/opt_in_jwt_spec.js b/spec/frontend/token_access/opt_in_jwt_spec.js deleted file mode 100644 index cdb385aa743..00000000000 --- a/spec/frontend/token_access/opt_in_jwt_spec.js +++ /dev/null @@ -1,144 +0,0 @@ -import { GlLink, GlLoadingIcon, GlToggle, GlSprintf } from '@gitlab/ui'; -import Vue from 'vue'; -import VueApollo from 'vue-apollo'; -import createMockApollo from 'helpers/mock_apollo_helper'; -import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; -import waitForPromises from 'helpers/wait_for_promises'; -import { createAlert } from '~/alert'; -import { OPT_IN_JWT_HELP_LINK } from '~/token_access/constants'; -import OptInJwt from '~/token_access/components/opt_in_jwt.vue'; -import getOptInJwtSettingQuery from '~/token_access/graphql/queries/get_opt_in_jwt_setting.query.graphql'; -import updateOptInJwtMutation from '~/token_access/graphql/mutations/update_opt_in_jwt.mutation.graphql'; -import { optInJwtMutationResponse, optInJwtQueryResponse } from './mock_data'; - -const errorMessage = 'An error occurred'; -const error = new Error(errorMessage); - -Vue.use(VueApollo); - -jest.mock('~/alert'); - -describe('OptInJwt component', () => { - let wrapper; - - const failureHandler = jest.fn().mockRejectedValue(error); - const enabledOptInJwtHandler = jest.fn().mockResolvedValue(optInJwtQueryResponse(true)); - const disabledOptInJwtHandler = jest.fn().mockResolvedValue(optInJwtQueryResponse(false)); - const updateOptInJwtHandler = jest.fn().mockResolvedValue(optInJwtMutationResponse(true)); - - const findHelpLink = () => wrapper.findComponent(GlLink); - const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); - const findToggle = () => wrapper.findComponent(GlToggle); - const findOptInJwtExpandedSection = () => wrapper.findByTestId('opt-in-jwt-expanded-section'); - - const createMockApolloProvider = (requestHandlers) => { - return createMockApollo(requestHandlers); - }; - - const createComponent = (requestHandlers, mountFn = shallowMountExtended, options = {}) => { - wrapper = mountFn(OptInJwt, { - provide: { - fullPath: 'root/my-repo', - }, - apolloProvider: createMockApolloProvider(requestHandlers), - data() { - return { - targetProjectPath: 'root/test', - }; - }, - ...options, - }); - }; - - const createShallowComponent = (requestHandlers, options = {}) => - createComponent(requestHandlers, shallowMountExtended, options); - const createFullComponent = (requestHandlers, options = {}) => - createComponent(requestHandlers, mountExtended, options); - - describe('loading state', () => { - it('shows loading state and hides toggle while waiting on query to resolve', async () => { - createShallowComponent([[getOptInJwtSettingQuery, enabledOptInJwtHandler]]); - - expect(findLoadingIcon().exists()).toBe(true); - expect(findToggle().exists()).toBe(false); - - await waitForPromises(); - - expect(findLoadingIcon().exists()).toBe(false); - expect(findToggle().exists()).toBe(true); - }); - }); - - describe('template', () => { - it('renders help link', async () => { - createShallowComponent([[getOptInJwtSettingQuery, enabledOptInJwtHandler]], { - stubs: { - GlToggle, - GlSprintf, - GlLink, - }, - }); - await waitForPromises(); - - expect(findHelpLink().exists()).toBe(true); - expect(findHelpLink().attributes('href')).toBe(OPT_IN_JWT_HELP_LINK); - }); - }); - - describe('toggle JWT token access', () => { - it('code instruction is visible when toggle is enabled', async () => { - createShallowComponent([[getOptInJwtSettingQuery, enabledOptInJwtHandler]]); - - await waitForPromises(); - - expect(findToggle().props('value')).toBe(true); - expect(findOptInJwtExpandedSection().exists()).toBe(true); - }); - - it('code instruction is hidden when toggle is disabled', async () => { - createShallowComponent([[getOptInJwtSettingQuery, disabledOptInJwtHandler]]); - - await waitForPromises(); - - expect(findToggle().props('value')).toBe(false); - expect(findOptInJwtExpandedSection().exists()).toBe(false); - }); - - describe('update JWT token access', () => { - it('calls updateOptInJwtMutation with correct arguments', async () => { - createFullComponent([ - [getOptInJwtSettingQuery, disabledOptInJwtHandler], - [updateOptInJwtMutation, updateOptInJwtHandler], - ]); - - await waitForPromises(); - - findToggle().vm.$emit('change', true); - - expect(updateOptInJwtHandler).toHaveBeenCalledWith({ - input: { - fullPath: 'root/my-repo', - optInJwt: true, - }, - }); - }); - - it('handles update error', async () => { - createFullComponent([ - [getOptInJwtSettingQuery, enabledOptInJwtHandler], - [updateOptInJwtMutation, failureHandler], - ]); - - await waitForPromises(); - - findToggle().vm.$emit('change', false); - - await waitForPromises(); - - expect(createAlert).toHaveBeenCalledWith({ - message: 'An error occurred while update the setting. Please try again.', - }); - }); - }); - }); -}); diff --git a/spec/frontend/token_access/token_access_app_spec.js b/spec/frontend/token_access/token_access_app_spec.js index cff16fd125c..77356f1b839 100644 --- a/spec/frontend/token_access/token_access_app_spec.js +++ b/spec/frontend/token_access/token_access_app_spec.js @@ -1,7 +1,6 @@ import { shallowMount } from '@vue/test-utils'; import OutboundTokenAccess from '~/token_access/components/outbound_token_access.vue'; import InboundTokenAccess from '~/token_access/components/inbound_token_access.vue'; -import OptInJwt from '~/token_access/components/opt_in_jwt.vue'; import TokenAccessApp from '~/token_access/components/token_access_app.vue'; describe('TokenAccessApp component', () => { @@ -9,7 +8,6 @@ describe('TokenAccessApp component', () => { const findOutboundTokenAccess = () => wrapper.findComponent(OutboundTokenAccess); const findInboundTokenAccess = () => wrapper.findComponent(InboundTokenAccess); - const findOptInJwt = () => wrapper.findComponent(OptInJwt); const createComponent = () => { wrapper = shallowMount(TokenAccessApp); @@ -20,10 +18,6 @@ describe('TokenAccessApp component', () => { createComponent(); }); - it('renders the opt in jwt component', () => { - expect(findOptInJwt().exists()).toBe(true); - }); - it('renders the outbound token access component', () => { expect(findOutboundTokenAccess().exists()).toBe(true); }); |