2022-04-04 11:22:00 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
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';
|
2022-01-26 12:08:38 +05:30
|
|
|
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-03-02 08:16:31 +05:30
|
|
|
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';
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
describe('Bridge Show Page', () => {
|
|
|
|
let wrapper;
|
2022-03-02 08:16:31 +05:30
|
|
|
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,
|
|
|
|
});
|
|
|
|
};
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
const createComponentWithApollo = () => {
|
|
|
|
const handlers = [[getPipelineQuery, mockPipelineQuery]];
|
2022-04-04 11:22:00 +05:30
|
|
|
Vue.use(VueApollo);
|
2022-03-02 08:16:31 +05:30
|
|
|
mockApollo = createMockApollo(handlers);
|
|
|
|
|
|
|
|
createComponent({
|
|
|
|
apolloProvider: mockApollo,
|
|
|
|
mocks: {},
|
|
|
|
});
|
2022-01-26 12:08:38 +05:30
|
|
|
};
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
const findCiHeader = () => wrapper.findComponent(CiHeader);
|
2022-01-26 12:08:38 +05:30
|
|
|
const findEmptyState = () => wrapper.findComponent(BridgeEmptyState);
|
2022-03-02 08:16:31 +05:30
|
|
|
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
|
2022-01-26 12:08:38 +05:30
|
|
|
const findSidebar = () => wrapper.findComponent(BridgeSidebar);
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
mockPipelineQuery = jest.fn();
|
|
|
|
});
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
afterEach(() => {
|
2022-03-02 08:16:31 +05:30
|
|
|
mockPipelineQuery.mockReset();
|
2022-01-26 12:08:38 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
describe('while pipeline query is loading', () => {
|
2022-01-26 12:08:38 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it('renders loading icon', () => {
|
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('after pipeline query is loaded', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2022-03-02 08:16:31 +05:30
|
|
|
mockPipelineQuery.mockResolvedValue(mockPipelineQueryResponse);
|
|
|
|
createComponentWithApollo();
|
2022-04-04 11:22:00 +05:30
|
|
|
await waitForPromises();
|
2022-03-02 08:16:31 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it('renders empty state', () => {
|
|
|
|
expect(findEmptyState().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders sidebar', () => {
|
|
|
|
expect(findSidebar().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
describe('sidebar expansion', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2022-03-02 08:16:31 +05:30
|
|
|
mockPipelineQuery.mockResolvedValue(mockPipelineQueryResponse);
|
|
|
|
createComponentWithApollo();
|
2022-04-04 11:22:00 +05:30
|
|
|
await waitForPromises();
|
2022-03-02 08:16:31 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2022-01-26 12:08:38 +05:30
|
|
|
});
|