diff options
Diffstat (limited to 'spec/frontend/token_access/outbound_token_access_spec.js')
-rw-r--r-- | spec/frontend/token_access/outbound_token_access_spec.js | 125 |
1 files changed, 25 insertions, 100 deletions
diff --git a/spec/frontend/token_access/outbound_token_access_spec.js b/spec/frontend/token_access/outbound_token_access_spec.js index 7f321495d72..f9eb201eb5c 100644 --- a/spec/frontend/token_access/outbound_token_access_spec.js +++ b/spec/frontend/token_access/outbound_token_access_spec.js @@ -6,7 +6,6 @@ import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_help import waitForPromises from 'helpers/wait_for_promises'; import { createAlert } from '~/alert'; import OutboundTokenAccess from '~/token_access/components/outbound_token_access.vue'; -import addProjectCIJobTokenScopeMutation from '~/token_access/graphql/mutations/add_project_ci_job_token_scope.mutation.graphql'; import removeProjectCIJobTokenScopeMutation from '~/token_access/graphql/mutations/remove_project_ci_job_token_scope.mutation.graphql'; import updateCIJobTokenScopeMutation from '~/token_access/graphql/mutations/update_ci_job_token_scope.mutation.graphql'; import getCIJobTokenScopeQuery from '~/token_access/graphql/queries/get_ci_job_token_scope.query.graphql'; @@ -15,7 +14,6 @@ import { enabledJobTokenScope, disabledJobTokenScope, projectsWithScope, - addProjectSuccess, removeProjectSuccess, updateScopeSuccess, } from './mock_data'; @@ -34,16 +32,13 @@ describe('TokenAccess component', () => { const enabledJobTokenScopeHandler = jest.fn().mockResolvedValue(enabledJobTokenScope); const disabledJobTokenScopeHandler = jest.fn().mockResolvedValue(disabledJobTokenScope); const getProjectsWithScopeHandler = jest.fn().mockResolvedValue(projectsWithScope); - const addProjectSuccessHandler = jest.fn().mockResolvedValue(addProjectSuccess); const removeProjectSuccessHandler = jest.fn().mockResolvedValue(removeProjectSuccess); const updateScopeSuccessHandler = jest.fn().mockResolvedValue(updateScopeSuccess); const failureHandler = jest.fn().mockRejectedValue(error); const findToggle = () => wrapper.findComponent(GlToggle); const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); - const findAddProjectBtn = () => wrapper.findByRole('button', { name: 'Add project' }); const findRemoveProjectBtn = () => wrapper.findByRole('button', { name: 'Remove access' }); - const findTokenDisabledAlert = () => wrapper.findByTestId('token-disabled-alert'); const findDeprecationAlert = () => wrapper.findByTestId('deprecation-alert'); const findProjectPathInput = () => wrapper.findByTestId('project-path-input'); @@ -51,19 +46,10 @@ describe('TokenAccess component', () => { return createMockApollo(requestHandlers); }; - const createComponent = ( - requestHandlers, - mountFn = shallowMountExtended, - frozenOutboundJobTokenScopes = false, - frozenOutboundJobTokenScopesOverride = false, - ) => { + const createComponent = (requestHandlers, mountFn = shallowMountExtended) => { wrapper = mountFn(OutboundTokenAccess, { provide: { fullPath: projectPath, - glFeatures: { - frozenOutboundJobTokenScopes, - frozenOutboundJobTokenScopesOverride, - }, }, apolloProvider: createMockApolloProvider(requestHandlers), data() { @@ -141,19 +127,6 @@ describe('TokenAccess component', () => { await waitForPromises(); expect(findToggle().props('value')).toBe(true); - expect(findTokenDisabledAlert().exists()).toBe(false); - }); - - it('the toggle is off and the alert is visible', async () => { - createComponent([ - [getCIJobTokenScopeQuery, disabledJobTokenScopeHandler], - [getProjectsWithCIJobTokenScopeQuery, getProjectsWithScopeHandler], - ]); - - await waitForPromises(); - - expect(findToggle().props('value')).toBe(false); - expect(findTokenDisabledAlert().exists()).toBe(true); }); describe('update ci job token scope', () => { @@ -196,48 +169,37 @@ describe('TokenAccess component', () => { expect(createAlert).toHaveBeenCalledWith({ message }); }); }); - }); - describe('add project', () => { - it('calls add project mutation', async () => { + it('the toggle is off and the deprecation alert is visible', async () => { createComponent( [ - [getCIJobTokenScopeQuery, enabledJobTokenScopeHandler], + [getCIJobTokenScopeQuery, disabledJobTokenScopeHandler], [getProjectsWithCIJobTokenScopeQuery, getProjectsWithScopeHandler], - [addProjectCIJobTokenScopeMutation, addProjectSuccessHandler], ], - mountExtended, + shallowMountExtended, + true, ); await waitForPromises(); - findAddProjectBtn().trigger('click'); - - expect(addProjectSuccessHandler).toHaveBeenCalledWith({ - input: { - projectPath, - targetProjectPath: 'root/test', - }, - }); + expect(findToggle().props('value')).toBe(false); + expect(findToggle().props('disabled')).toBe(true); + expect(findDeprecationAlert().exists()).toBe(true); }); - it('add project handles error correctly', async () => { + it('contains a warning message about disabling the current configuration', async () => { createComponent( [ - [getCIJobTokenScopeQuery, enabledJobTokenScopeHandler], + [getCIJobTokenScopeQuery, disabledJobTokenScopeHandler], [getProjectsWithCIJobTokenScopeQuery, getProjectsWithScopeHandler], - [addProjectCIJobTokenScopeMutation, failureHandler], ], mountExtended, + true, ); await waitForPromises(); - findAddProjectBtn().trigger('click'); - - await waitForPromises(); - - expect(createAlert).toHaveBeenCalledWith({ message }); + expect(findToggle().text()).toContain('Disabling this feature is a permanent change.'); }); }); @@ -284,58 +246,21 @@ describe('TokenAccess component', () => { }); }); - describe('with the frozenOutboundJobTokenScopes feature flag enabled', () => { - describe('toggle', () => { - it('the toggle is off and the deprecation alert is visible', async () => { - createComponent( - [ - [getCIJobTokenScopeQuery, disabledJobTokenScopeHandler], - [getProjectsWithCIJobTokenScopeQuery, getProjectsWithScopeHandler], - ], - shallowMountExtended, - true, - ); - - await waitForPromises(); - - expect(findToggle().props('value')).toBe(false); - expect(findToggle().props('disabled')).toBe(true); - expect(findDeprecationAlert().exists()).toBe(true); - expect(findTokenDisabledAlert().exists()).toBe(false); - }); - - it('contains a warning message about disabling the current configuration', async () => { - createComponent( - [ - [getCIJobTokenScopeQuery, disabledJobTokenScopeHandler], - [getProjectsWithCIJobTokenScopeQuery, getProjectsWithScopeHandler], - ], - mountExtended, - true, - ); - - await waitForPromises(); - - expect(findToggle().text()).toContain('Disabling this feature is a permanent change.'); - }); - }); - - describe('adding a new project', () => { - it('disables the input to add new projects', async () => { - createComponent( - [ - [getCIJobTokenScopeQuery, disabledJobTokenScopeHandler], - [getProjectsWithCIJobTokenScopeQuery, getProjectsWithScopeHandler], - ], - mountExtended, - true, - false, - ); + describe('adding a new project', () => { + it('disables the input to add new projects', async () => { + createComponent( + [ + [getCIJobTokenScopeQuery, disabledJobTokenScopeHandler], + [getProjectsWithCIJobTokenScopeQuery, getProjectsWithScopeHandler], + ], + mountExtended, + true, + false, + ); - await waitForPromises(); + await waitForPromises(); - expect(findProjectPathInput().attributes('disabled')).toBe('disabled'); - }); + expect(findProjectPathInput().attributes('disabled')).toBe('disabled'); }); }); }); |