2020-04-08 14:13:33 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-04-29 21:17:54 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2021-11-18 22:05:49 +05:30
|
|
|
import oneReleaseQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/one_release.query.graphql.json';
|
2021-04-29 21:17:54 +05:30
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2022-04-04 11:22:00 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { createAlert } from '~/alert';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { popCreateReleaseNotification } from '~/releases/release_notification_service';
|
2020-04-08 14:13:33 +05:30
|
|
|
import ReleaseShowApp from '~/releases/components/app_show.vue';
|
|
|
|
import ReleaseBlock from '~/releases/components/release_block.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import ReleaseSkeletonLoader from '~/releases/components/release_skeleton_loader.vue';
|
2021-06-08 01:23:25 +05:30
|
|
|
import oneReleaseQuery from '~/releases/graphql/queries/one_release.query.graphql';
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
jest.mock('~/alert');
|
2023-04-23 21:23:45 +05:30
|
|
|
jest.mock('~/releases/release_notification_service');
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
|
|
|
const EXPECTED_ERROR_MESSAGE = 'Something went wrong while getting the release details.';
|
|
|
|
const MOCK_FULL_PATH = 'project/full/path';
|
|
|
|
const MOCK_TAG_NAME = 'test-tag-name';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
describe('Release show component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
const createComponent = ({ apolloProvider }) => {
|
|
|
|
wrapper = shallowMount(ReleaseShowApp, {
|
|
|
|
provide: {
|
|
|
|
fullPath: MOCK_FULL_PATH,
|
|
|
|
tagName: MOCK_TAG_NAME,
|
2020-04-08 14:13:33 +05:30
|
|
|
},
|
2021-04-29 21:17:54 +05:30
|
|
|
apolloProvider,
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const findLoadingSkeleton = () => wrapper.findComponent(ReleaseSkeletonLoader);
|
|
|
|
const findReleaseBlock = () => wrapper.findComponent(ReleaseBlock);
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
const expectLoadingIndicator = () => {
|
|
|
|
it('renders a loading indicator', () => {
|
|
|
|
expect(findLoadingSkeleton().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectNoLoadingIndicator = () => {
|
|
|
|
it('does not render a loading indicator', () => {
|
|
|
|
expect(findLoadingSkeleton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectNoFlash = () => {
|
2023-05-27 22:25:52 +05:30
|
|
|
it('does not show an alert message', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(createAlert).not.toHaveBeenCalled();
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectFlashWithMessage = (message) => {
|
2023-05-27 22:25:52 +05:30
|
|
|
it(`shows an alert message that reads "${message}"`, () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(createAlert).toHaveBeenCalledWith({
|
2021-04-29 21:17:54 +05:30
|
|
|
message,
|
|
|
|
captureError: true,
|
|
|
|
error: expect.any(Error),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectReleaseBlock = () => {
|
|
|
|
it('renders a release block', () => {
|
|
|
|
expect(findReleaseBlock().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectNoReleaseBlock = () => {
|
|
|
|
it('does not render a release block', () => {
|
|
|
|
expect(findReleaseBlock().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('GraphQL query variables', () => {
|
|
|
|
const queryHandler = jest.fn().mockResolvedValueOnce(oneReleaseQueryResponse);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const apolloProvider = createMockApollo([[oneReleaseQuery, queryHandler]]);
|
|
|
|
|
|
|
|
createComponent({ apolloProvider });
|
|
|
|
});
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it('shows info notification on mount', () => {
|
|
|
|
expect(popCreateReleaseNotification).toHaveBeenCalledTimes(1);
|
|
|
|
expect(popCreateReleaseNotification).toHaveBeenCalledWith(MOCK_FULL_PATH);
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it('builds a GraphQL with the expected variables', () => {
|
|
|
|
expect(queryHandler).toHaveBeenCalledTimes(1);
|
|
|
|
expect(queryHandler).toHaveBeenCalledWith({
|
|
|
|
fullPath: MOCK_FULL_PATH,
|
|
|
|
tagName: MOCK_TAG_NAME,
|
|
|
|
});
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('when the component is loading data', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const apolloProvider = createMockApollo([
|
|
|
|
[oneReleaseQuery, jest.fn().mockReturnValueOnce(new Promise(() => {}))],
|
|
|
|
]);
|
|
|
|
|
|
|
|
createComponent({ apolloProvider });
|
|
|
|
});
|
|
|
|
|
|
|
|
expectLoadingIndicator();
|
|
|
|
expectNoFlash();
|
|
|
|
expectNoReleaseBlock();
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('when the component has successfully loaded the release', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
const apolloProvider = createMockApollo([
|
|
|
|
[oneReleaseQuery, jest.fn().mockResolvedValueOnce(oneReleaseQueryResponse)],
|
|
|
|
]);
|
|
|
|
|
|
|
|
createComponent({ apolloProvider });
|
2022-04-04 11:22:00 +05:30
|
|
|
await waitForPromises();
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expectNoLoadingIndicator();
|
|
|
|
expectNoFlash();
|
|
|
|
expectReleaseBlock();
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('when the request succeeded, but the returned "project" key was null', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
const apolloProvider = createMockApollo([
|
|
|
|
[oneReleaseQuery, jest.fn().mockResolvedValueOnce({ data: { project: null } })],
|
|
|
|
]);
|
|
|
|
|
|
|
|
createComponent({ apolloProvider });
|
2022-04-04 11:22:00 +05:30
|
|
|
await waitForPromises();
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expectNoLoadingIndicator();
|
|
|
|
expectFlashWithMessage(EXPECTED_ERROR_MESSAGE);
|
|
|
|
expectNoReleaseBlock();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the request succeeded, but the returned "project.release" key was null', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
// As we return a release as `null`, Apollo also throws an error to the console
|
|
|
|
// about the missing field. We need to suppress console.error in order to check
|
2023-05-27 22:25:52 +05:30
|
|
|
// that alert message was called
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error = jest.fn();
|
2021-04-29 21:17:54 +05:30
|
|
|
const apolloProvider = createMockApollo([
|
|
|
|
[
|
|
|
|
oneReleaseQuery,
|
|
|
|
jest.fn().mockResolvedValueOnce({ data: { project: { release: null } } }),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
createComponent({ apolloProvider });
|
2022-04-04 11:22:00 +05:30
|
|
|
await waitForPromises();
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expectNoLoadingIndicator();
|
|
|
|
expectFlashWithMessage(EXPECTED_ERROR_MESSAGE);
|
|
|
|
expectNoReleaseBlock();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when an error occurs while loading the release', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
const apolloProvider = createMockApollo([
|
|
|
|
[oneReleaseQuery, jest.fn().mockRejectedValueOnce('An error occurred!')],
|
|
|
|
]);
|
|
|
|
|
|
|
|
createComponent({ apolloProvider });
|
2022-04-04 11:22:00 +05:30
|
|
|
await waitForPromises();
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expectNoLoadingIndicator();
|
|
|
|
expectFlashWithMessage(EXPECTED_ERROR_MESSAGE);
|
|
|
|
expectNoReleaseBlock();
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
});
|