2022-01-25 07:14:14 -05:00
|
|
|
import Vue, { nextTick } from 'vue';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
|
2022-01-10 07:15:34 -05:00
|
|
|
import { GlBreakpointInstance } from '@gitlab/ui/dist/utils';
|
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import getPipelineQuery from '~/jobs/bridge/graphql/queries/pipeline.query.graphql';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-12-10 13:14:42 -05:00
|
|
|
import BridgeApp from '~/jobs/bridge/app.vue';
|
|
|
|
import BridgeEmptyState from '~/jobs/bridge/components/empty_state.vue';
|
|
|
|
import BridgeSidebar from '~/jobs/bridge/components/sidebar.vue';
|
2022-01-10 07:15:34 -05:00
|
|
|
import CiHeader from '~/vue_shared/components/header_ci_component.vue';
|
|
|
|
import {
|
|
|
|
MOCK_BUILD_ID,
|
|
|
|
MOCK_PIPELINE_IID,
|
|
|
|
MOCK_PROJECT_FULL_PATH,
|
|
|
|
mockPipelineQueryResponse,
|
|
|
|
} from './mock_data';
|
|
|
|
|
2021-12-10 13:14:42 -05:00
|
|
|
describe('Bridge Show Page', () => {
|
|
|
|
let wrapper;
|
2022-01-10 07:15:34 -05:00
|
|
|
let mockApollo;
|
|
|
|
let mockPipelineQuery;
|
|
|
|
|
|
|
|
const createComponent = (options) => {
|
|
|
|
wrapper = shallowMount(BridgeApp, {
|
|
|
|
provide: {
|
|
|
|
buildId: MOCK_BUILD_ID,
|
|
|
|
projectFullPath: MOCK_PROJECT_FULL_PATH,
|
|
|
|
pipelineIid: MOCK_PIPELINE_IID,
|
|
|
|
},
|
|
|
|
mocks: {
|
|
|
|
$apollo: {
|
|
|
|
queries: {
|
|
|
|
pipeline: {
|
|
|
|
loading: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
2021-12-10 13:14:42 -05:00
|
|
|
|
2022-01-10 07:15:34 -05:00
|
|
|
const createComponentWithApollo = () => {
|
|
|
|
const handlers = [[getPipelineQuery, mockPipelineQuery]];
|
2022-01-25 07:14:14 -05:00
|
|
|
Vue.use(VueApollo);
|
2022-01-10 07:15:34 -05:00
|
|
|
mockApollo = createMockApollo(handlers);
|
|
|
|
|
|
|
|
createComponent({
|
|
|
|
apolloProvider: mockApollo,
|
|
|
|
mocks: {},
|
|
|
|
});
|
2021-12-10 13:14:42 -05:00
|
|
|
};
|
|
|
|
|
2022-01-10 07:15:34 -05:00
|
|
|
const findCiHeader = () => wrapper.findComponent(CiHeader);
|
2021-12-10 13:14:42 -05:00
|
|
|
const findEmptyState = () => wrapper.findComponent(BridgeEmptyState);
|
2022-01-10 07:15:34 -05:00
|
|
|
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
|
2021-12-10 13:14:42 -05:00
|
|
|
const findSidebar = () => wrapper.findComponent(BridgeSidebar);
|
|
|
|
|
2022-01-10 07:15:34 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
mockPipelineQuery = jest.fn();
|
|
|
|
});
|
|
|
|
|
2021-12-10 13:14:42 -05:00
|
|
|
afterEach(() => {
|
2022-01-10 07:15:34 -05:00
|
|
|
mockPipelineQuery.mockReset();
|
2021-12-10 13:14:42 -05:00
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2022-01-10 07:15:34 -05:00
|
|
|
describe('while pipeline query is loading', () => {
|
2021-12-10 13:14:42 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
2022-01-10 07:15:34 -05:00
|
|
|
it('renders loading icon', () => {
|
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('after pipeline query is loaded', () => {
|
2022-01-24 16:14:06 -05:00
|
|
|
beforeEach(async () => {
|
2022-01-10 07:15:34 -05:00
|
|
|
mockPipelineQuery.mockResolvedValue(mockPipelineQueryResponse);
|
|
|
|
createComponentWithApollo();
|
2022-01-24 16:14:06 -05:00
|
|
|
await waitForPromises();
|
2022-01-10 07:15:34 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('query is called with correct variables', async () => {
|
|
|
|
expect(mockPipelineQuery).toHaveBeenCalledTimes(1);
|
|
|
|
expect(mockPipelineQuery).toHaveBeenCalledWith({
|
|
|
|
fullPath: MOCK_PROJECT_FULL_PATH,
|
|
|
|
iid: MOCK_PIPELINE_IID,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders CI header state', () => {
|
|
|
|
expect(findCiHeader().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2021-12-10 13:14:42 -05:00
|
|
|
it('renders empty state', () => {
|
|
|
|
expect(findEmptyState().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders sidebar', () => {
|
|
|
|
expect(findSidebar().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2022-01-10 07:15:34 -05:00
|
|
|
|
|
|
|
describe('sidebar expansion', () => {
|
2022-01-24 16:14:06 -05:00
|
|
|
beforeEach(async () => {
|
2022-01-10 07:15:34 -05:00
|
|
|
mockPipelineQuery.mockResolvedValue(mockPipelineQueryResponse);
|
|
|
|
createComponentWithApollo();
|
2022-01-24 16:14:06 -05:00
|
|
|
await waitForPromises();
|
2022-01-10 07:15:34 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('on resize', () => {
|
|
|
|
it.each`
|
|
|
|
breakpoint | isSidebarExpanded
|
|
|
|
${'xs'} | ${false}
|
|
|
|
${'sm'} | ${false}
|
|
|
|
${'md'} | ${true}
|
|
|
|
${'lg'} | ${true}
|
|
|
|
${'xl'} | ${true}
|
|
|
|
`(
|
|
|
|
'sets isSidebarExpanded to `$isSidebarExpanded` when the breakpoint is "$breakpoint"',
|
|
|
|
async ({ breakpoint, isSidebarExpanded }) => {
|
|
|
|
jest.spyOn(GlBreakpointInstance, 'getBreakpointSize').mockReturnValue(breakpoint);
|
|
|
|
|
|
|
|
window.dispatchEvent(new Event('resize'));
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(findSidebar().exists()).toBe(isSidebarExpanded);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles expansion on button click', async () => {
|
|
|
|
expect(findSidebar().exists()).toBe(true);
|
|
|
|
|
|
|
|
wrapper.vm.toggleSidebar();
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(findSidebar().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2021-12-10 13:14:42 -05:00
|
|
|
});
|