2021-05-05 09:10:02 +00:00
|
|
|
import { createLocalVue, mount, shallowMount } from '@vue/test-utils';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-07-02 12:08:31 +00:00
|
|
|
import createFlash from '~/flash';
|
2021-05-05 09:10:02 +00:00
|
|
|
|
2021-06-07 15:09:56 +00:00
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
2021-05-05 09:10:02 +00:00
|
|
|
import RunnerTypeBadge from '~/runner/components/runner_type_badge.vue';
|
|
|
|
import getRunnerQuery from '~/runner/graphql/get_runner.query.graphql';
|
|
|
|
import RunnerDetailsApp from '~/runner/runner_details/runner_details_app.vue';
|
2021-07-02 12:08:31 +00:00
|
|
|
import { captureException } from '~/runner/sentry_utils';
|
2021-05-05 09:10:02 +00:00
|
|
|
|
2021-06-07 15:09:56 +00:00
|
|
|
import { runnerData } from '../mock_data';
|
|
|
|
|
2021-07-02 12:08:31 +00:00
|
|
|
jest.mock('~/flash');
|
|
|
|
jest.mock('~/runner/sentry_utils');
|
|
|
|
|
2021-06-07 15:09:56 +00:00
|
|
|
const mockRunnerGraphqlId = runnerData.data.runner.id;
|
|
|
|
const mockRunnerId = `${getIdFromGraphQLId(mockRunnerGraphqlId)}`;
|
2021-05-05 09:10:02 +00:00
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(VueApollo);
|
|
|
|
|
|
|
|
describe('RunnerDetailsApp', () => {
|
|
|
|
let wrapper;
|
|
|
|
let mockRunnerQuery;
|
|
|
|
|
|
|
|
const findRunnerTypeBadge = () => wrapper.findComponent(RunnerTypeBadge);
|
|
|
|
|
|
|
|
const createComponentWithApollo = ({ props = {}, mountFn = shallowMount } = {}) => {
|
|
|
|
wrapper = mountFn(RunnerDetailsApp, {
|
|
|
|
localVue,
|
2021-07-02 12:08:31 +00:00
|
|
|
apolloProvider: createMockApollo([[getRunnerQuery, mockRunnerQuery]]),
|
2021-05-05 09:10:02 +00:00
|
|
|
propsData: {
|
|
|
|
runnerId: mockRunnerId,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return waitForPromises();
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2021-06-07 15:09:56 +00:00
|
|
|
mockRunnerQuery = jest.fn().mockResolvedValue(runnerData);
|
2021-05-05 09:10:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mockRunnerQuery.mockReset();
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('expect GraphQL ID to be requested', async () => {
|
|
|
|
await createComponentWithApollo();
|
|
|
|
|
2021-06-07 15:09:56 +00:00
|
|
|
expect(mockRunnerQuery).toHaveBeenCalledWith({ id: mockRunnerGraphqlId });
|
2021-05-05 09:10:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the runner id', async () => {
|
|
|
|
await createComponentWithApollo();
|
|
|
|
|
2021-06-07 15:09:56 +00:00
|
|
|
expect(wrapper.text()).toContain(`Runner #${mockRunnerId}`);
|
2021-05-05 09:10:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the runner type', async () => {
|
|
|
|
await createComponentWithApollo({ mountFn: mount });
|
|
|
|
|
|
|
|
expect(findRunnerTypeBadge().text()).toBe('shared');
|
|
|
|
});
|
2021-07-02 12:08:31 +00:00
|
|
|
|
|
|
|
describe('When there is an error', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
mockRunnerQuery = jest.fn().mockRejectedValueOnce(new Error('Error!'));
|
|
|
|
await createComponentWithApollo();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('error is reported to sentry', async () => {
|
|
|
|
expect(captureException).toHaveBeenCalledWith({
|
|
|
|
error: new Error('Network error: Error!'),
|
|
|
|
component: 'RunnerDetailsApp',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('error is shown to the user', async () => {
|
|
|
|
expect(createFlash).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2021-05-05 09:10:02 +00:00
|
|
|
});
|