Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-01-10 15:15:34 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-01-10 15:15:34 +0300
commitd85be261b2898166676be4f329a548f61e2917f4 (patch)
tree393faefd792483f15860dd184b524ac597295ae1 /spec/frontend/security_configuration
parent75330c963b9e949443b1e4ab2e5770879d395158 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/security_configuration')
-rw-r--r--spec/frontend/security_configuration/components/training_provider_list_spec.js192
-rw-r--r--spec/frontend/security_configuration/mock_data.js7
2 files changed, 134 insertions, 65 deletions
diff --git a/spec/frontend/security_configuration/components/training_provider_list_spec.js b/spec/frontend/security_configuration/components/training_provider_list_spec.js
index 183deec0f10..578248e696f 100644
--- a/spec/frontend/security_configuration/components/training_provider_list_spec.js
+++ b/spec/frontend/security_configuration/components/training_provider_list_spec.js
@@ -1,4 +1,4 @@
-import { GlLink, GlToggle, GlCard, GlSkeletonLoader } from '@gitlab/ui';
+import { GlAlert, GlLink, GlToggle, GlCard, GlSkeletonLoader } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
@@ -8,7 +8,7 @@ import configureSecurityTrainingProvidersMutation from '~/security_configuration
import waitForPromises from 'helpers/wait_for_promises';
import {
securityTrainingProviders,
- mockResolvers,
+ createMockResolvers,
testProjectPath,
textProviderIds,
} from '../mock_data';
@@ -17,113 +17,177 @@ Vue.use(VueApollo);
describe('TrainingProviderList component', () => {
let wrapper;
- let mockApollo;
- let mockSecurityTrainingProvidersData;
+ let apolloProvider;
- const createComponent = () => {
- mockApollo = createMockApollo([], mockResolvers);
+ const createApolloProvider = ({ resolvers } = {}) => {
+ apolloProvider = createMockApollo([], createMockResolvers({ resolvers }));
+ };
+ const createComponent = () => {
wrapper = shallowMount(TrainingProviderList, {
provide: {
projectPath: testProjectPath,
},
- apolloProvider: mockApollo,
+ apolloProvider,
});
};
const waitForQueryToBeLoaded = () => waitForPromises();
+ const waitForMutationToBeLoaded = waitForQueryToBeLoaded;
const findCards = () => wrapper.findAllComponents(GlCard);
const findLinks = () => wrapper.findAllComponents(GlLink);
const findToggles = () => wrapper.findAllComponents(GlToggle);
+ const findFirstToggle = () => findToggles().at(0);
const findLoader = () => wrapper.findComponent(GlSkeletonLoader);
+ const findErrorAlert = () => wrapper.findComponent(GlAlert);
- beforeEach(() => {
- mockSecurityTrainingProvidersData = jest.fn();
- mockSecurityTrainingProvidersData.mockResolvedValue(securityTrainingProviders);
-
- createComponent();
- });
+ const toggleFirstProvider = () => findFirstToggle().vm.$emit('change');
afterEach(() => {
wrapper.destroy();
- mockApollo = null;
+ apolloProvider = null;
});
- describe('when loading', () => {
- it('shows the loader', () => {
- expect(findLoader().exists()).toBe(true);
+ describe('with a successful response', () => {
+ beforeEach(() => {
+ createApolloProvider();
+ createComponent();
});
- it('does not show the cards', () => {
- expect(findCards().exists()).toBe(false);
- });
- });
-
- describe('basic structure', () => {
- beforeEach(async () => {
- await waitForQueryToBeLoaded();
- });
+ describe('when loading', () => {
+ it('shows the loader', () => {
+ expect(findLoader().exists()).toBe(true);
+ });
- it('renders correct amount of cards', () => {
- expect(findCards()).toHaveLength(securityTrainingProviders.length);
+ it('does not show the cards', () => {
+ expect(findCards().exists()).toBe(false);
+ });
});
- securityTrainingProviders.forEach(({ name, description, url, isEnabled }, index) => {
- it(`shows the name for card ${index}`, () => {
- expect(findCards().at(index).text()).toContain(name);
+ describe('basic structure', () => {
+ beforeEach(async () => {
+ await waitForQueryToBeLoaded();
});
- it(`shows the description for card ${index}`, () => {
- expect(findCards().at(index).text()).toContain(description);
+ it('renders correct amount of cards', () => {
+ expect(findCards()).toHaveLength(securityTrainingProviders.length);
});
- it(`shows the learn more link for card ${index}`, () => {
- expect(findLinks().at(index).attributes()).toEqual({
- target: '_blank',
- href: url,
+ securityTrainingProviders.forEach(({ name, description, url, isEnabled }, index) => {
+ it(`shows the name for card ${index}`, () => {
+ expect(findCards().at(index).text()).toContain(name);
+ });
+
+ it(`shows the description for card ${index}`, () => {
+ expect(findCards().at(index).text()).toContain(description);
+ });
+
+ it(`shows the learn more link for card ${index}`, () => {
+ expect(findLinks().at(index).attributes()).toEqual({
+ target: '_blank',
+ href: url,
+ });
+ });
+
+ it(`shows the toggle with the correct value for card ${index}`, () => {
+ expect(findToggles().at(index).props('value')).toEqual(isEnabled);
+ });
+
+ it('does not show loader when query is populated', () => {
+ expect(findLoader().exists()).toBe(false);
});
});
+ });
+
+ describe('storing training provider settings', () => {
+ beforeEach(async () => {
+ jest.spyOn(apolloProvider.defaultClient, 'mutate');
- it(`shows the toggle with the correct value for card ${index}`, () => {
- expect(findToggles().at(index).props('value')).toEqual(isEnabled);
+ await waitForMutationToBeLoaded();
+
+ toggleFirstProvider();
});
- it('does not show loader when query is populated', () => {
- expect(findLoader().exists()).toBe(false);
+ it.each`
+ loading | wait | desc
+ ${true} | ${false} | ${'enables loading of GlToggle when mutation is called'}
+ ${false} | ${true} | ${'disables loading of GlToggle when mutation is complete'}
+ `('$desc', async ({ loading, wait }) => {
+ if (wait) {
+ await waitForMutationToBeLoaded();
+ }
+ expect(findFirstToggle().props('isLoading')).toBe(loading);
+ });
+
+ it('calls mutation when toggle is changed', () => {
+ expect(apolloProvider.defaultClient.mutate).toHaveBeenCalledWith(
+ expect.objectContaining({
+ mutation: configureSecurityTrainingProvidersMutation,
+ variables: { input: { enabledProviders: textProviderIds, fullPath: testProjectPath } },
+ }),
+ );
});
});
});
- describe('success mutation', () => {
- const firstToggle = () => findToggles().at(0);
+ describe('with errors', () => {
+ const expectErrorAlertToExist = () => {
+ expect(findErrorAlert().props()).toMatchObject({
+ dismissible: false,
+ variant: 'danger',
+ });
+ };
+
+ describe('when fetching training providers', () => {
+ beforeEach(async () => {
+ createApolloProvider({
+ resolvers: {
+ Query: {
+ securityTrainingProviders: jest.fn().mockReturnValue(new Error()),
+ },
+ },
+ });
+ createComponent();
- beforeEach(async () => {
- jest.spyOn(mockApollo.defaultClient, 'mutate');
+ await waitForQueryToBeLoaded();
+ });
- await waitForQueryToBeLoaded();
+ it('shows an non-dismissible error alert', () => {
+ expectErrorAlertToExist();
+ });
- firstToggle().vm.$emit('change');
+ it('shows an error description', () => {
+ expect(findErrorAlert().text()).toBe(TrainingProviderList.i18n.providerQueryErrorMessage);
+ });
});
- it('calls mutation when toggle is changed', () => {
- expect(mockApollo.defaultClient.mutate).toHaveBeenCalledWith(
- expect.objectContaining({
- mutation: configureSecurityTrainingProvidersMutation,
- variables: { input: { enabledProviders: textProviderIds, fullPath: testProjectPath } },
- }),
- );
- });
+ describe('when storing training provider configurations', () => {
+ beforeEach(async () => {
+ createApolloProvider({
+ resolvers: {
+ Mutation: {
+ configureSecurityTrainingProviders: () => ({
+ errors: ['something went wrong!'],
+ securityTrainingProviders: [],
+ }),
+ },
+ },
+ });
+ createComponent();
- it.each`
- loading | wait | desc
- ${true} | ${false} | ${'enables loading of GlToggle when mutation is called'}
- ${false} | ${true} | ${'disables loading of GlToggle when mutation is complete'}
- `('$desc', async ({ loading, wait }) => {
- if (wait) {
- await waitForPromises();
- }
- expect(firstToggle().props('isLoading')).toBe(loading);
+ await waitForQueryToBeLoaded();
+ toggleFirstProvider();
+ await waitForMutationToBeLoaded();
+ });
+
+ it('shows an non-dismissible error alert', () => {
+ expectErrorAlertToExist();
+ });
+
+ it('shows an error description', () => {
+ expect(findErrorAlert().text()).toBe(TrainingProviderList.i18n.configMutationErrorMessage);
+ });
});
});
});
diff --git a/spec/frontend/security_configuration/mock_data.js b/spec/frontend/security_configuration/mock_data.js
index b01dd1fc07b..32b1a0bff06 100644
--- a/spec/frontend/security_configuration/mock_data.js
+++ b/spec/frontend/security_configuration/mock_data.js
@@ -25,10 +25,15 @@ export const securityTrainingProvidersResponse = {
},
};
-export const mockResolvers = {
+const defaultMockResolvers = {
Query: {
securityTrainingProviders() {
return securityTrainingProviders;
},
},
};
+
+export const createMockResolvers = ({ resolvers: customMockResolvers = {} } = {}) => ({
+ ...defaultMockResolvers,
+ ...customMockResolvers,
+});