diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/frontend/runner/admin_runner_edit/admin_runner_edit_app_spec.js | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) | |
download | gitlab-ce-edaa33dee2ff2f7ea3fac488d41558eb5f86d68c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/frontend/runner/admin_runner_edit/admin_runner_edit_app_spec.js')
-rw-r--r-- | spec/frontend/runner/admin_runner_edit/admin_runner_edit_app_spec.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/spec/frontend/runner/admin_runner_edit/admin_runner_edit_app_spec.js b/spec/frontend/runner/admin_runner_edit/admin_runner_edit_app_spec.js new file mode 100644 index 00000000000..ad0bce5c9af --- /dev/null +++ b/spec/frontend/runner/admin_runner_edit/admin_runner_edit_app_spec.js @@ -0,0 +1,88 @@ +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'; +import { createAlert } from '~/flash'; + +import { getIdFromGraphQLId } from '~/graphql_shared/utils'; +import RunnerHeader from '~/runner/components/runner_header.vue'; +import getRunnerQuery from '~/runner/graphql/get_runner.query.graphql'; +import AdminRunnerEditApp from '~//runner/admin_runner_edit/admin_runner_edit_app.vue'; +import { captureException } from '~/runner/sentry_utils'; + +import { runnerData } from '../mock_data'; + +jest.mock('~/flash'); +jest.mock('~/runner/sentry_utils'); + +const mockRunnerGraphqlId = runnerData.data.runner.id; +const mockRunnerId = `${getIdFromGraphQLId(mockRunnerGraphqlId)}`; + +const localVue = createLocalVue(); +localVue.use(VueApollo); + +describe('AdminRunnerEditApp', () => { + let wrapper; + let mockRunnerQuery; + + const findRunnerHeader = () => wrapper.findComponent(RunnerHeader); + + const createComponentWithApollo = ({ props = {}, mountFn = shallowMount } = {}) => { + wrapper = mountFn(AdminRunnerEditApp, { + localVue, + apolloProvider: createMockApollo([[getRunnerQuery, mockRunnerQuery]]), + propsData: { + runnerId: mockRunnerId, + ...props, + }, + }); + + return waitForPromises(); + }; + + beforeEach(() => { + mockRunnerQuery = jest.fn().mockResolvedValue(runnerData); + }); + + afterEach(() => { + mockRunnerQuery.mockReset(); + wrapper.destroy(); + }); + + it('expect GraphQL ID to be requested', async () => { + await createComponentWithApollo(); + + expect(mockRunnerQuery).toHaveBeenCalledWith({ id: mockRunnerGraphqlId }); + }); + + it('displays the runner id', async () => { + await createComponentWithApollo({ mountFn: mount }); + + expect(findRunnerHeader().text()).toContain(`Runner #${mockRunnerId} created`); + }); + + it('displays the runner type and status', async () => { + await createComponentWithApollo({ mountFn: mount }); + + expect(findRunnerHeader().text()).toContain(`never contacted`); + expect(findRunnerHeader().text()).toContain(`shared`); + }); + + describe('When there is an error', () => { + beforeEach(async () => { + mockRunnerQuery = jest.fn().mockRejectedValueOnce(new Error('Error!')); + await createComponentWithApollo(); + }); + + it('error is reported to sentry', () => { + expect(captureException).toHaveBeenCalledWith({ + error: new Error('Network error: Error!'), + component: 'AdminRunnerEditApp', + }); + }); + + it('error is shown to the user', () => { + expect(createAlert).toHaveBeenCalled(); + }); + }); +}); |