2022-05-31 23:09:43 -04:00
|
|
|
import { GlPath, GlSkeletonLoader } from '@gitlab/ui';
|
2021-06-02 05:09:46 -04:00
|
|
|
import { mount } from '@vue/test-utils';
|
2021-06-03 05:10:18 -04:00
|
|
|
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
|
2021-06-02 05:09:46 -04:00
|
|
|
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
|
|
|
|
import Component from '~/cycle_analytics/components/path_navigation.vue';
|
|
|
|
import { transformedProjectStagePathData, selectedStage } from './mock_data';
|
|
|
|
|
|
|
|
describe('Project PathNavigation', () => {
|
|
|
|
let wrapper = null;
|
2021-06-03 05:10:18 -04:00
|
|
|
let trackingSpy = null;
|
2021-06-02 05:09:46 -04:00
|
|
|
|
|
|
|
const createComponent = (props) => {
|
|
|
|
return extendedWrapper(
|
|
|
|
mount(Component, {
|
|
|
|
propsData: {
|
|
|
|
stages: transformedProjectStagePathData,
|
|
|
|
selectedStage,
|
|
|
|
loading: false,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const findPathNavigation = () => {
|
|
|
|
return wrapper.findByTestId('gl-path-nav');
|
|
|
|
};
|
|
|
|
|
|
|
|
const findPathNavigationItems = () => {
|
|
|
|
return findPathNavigation().findAll('li');
|
|
|
|
};
|
|
|
|
|
|
|
|
const findPathNavigationTitles = () => {
|
|
|
|
return findPathNavigation()
|
|
|
|
.findAll('li button')
|
|
|
|
.wrappers.map((w) => w.html());
|
|
|
|
};
|
|
|
|
|
|
|
|
const clickItemAt = (index) => {
|
|
|
|
findPathNavigationItems().at(index).find('button').trigger('click');
|
|
|
|
};
|
|
|
|
|
|
|
|
const pathItemContent = () => findPathNavigationItems().wrappers.map(extendedWrapper);
|
|
|
|
const firstPopover = () => wrapper.findAllByTestId('stage-item-popover').at(0);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent();
|
2021-06-03 05:10:18 -04:00
|
|
|
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
|
2021-06-02 05:09:46 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2021-06-03 05:10:18 -04:00
|
|
|
unmockTracking();
|
2021-06-02 05:09:46 -04:00
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('displays correctly', () => {
|
|
|
|
it('has the correct props', () => {
|
|
|
|
expect(wrapper.find(GlPath).props('items')).toMatchObject(transformedProjectStagePathData);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('contains all the expected stages', () => {
|
|
|
|
const stageContent = findPathNavigationTitles();
|
|
|
|
transformedProjectStagePathData.forEach((stage, index) => {
|
|
|
|
expect(stageContent[index]).toContain(stage.title);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('loading', () => {
|
|
|
|
describe('is false', () => {
|
|
|
|
it('displays the gl-path component', () => {
|
|
|
|
expect(wrapper.find(GlPath).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('hides the gl-skeleton-loading component', () => {
|
2022-05-31 23:09:43 -04:00
|
|
|
expect(wrapper.find(GlSkeletonLoader).exists()).toBe(false);
|
2021-06-02 05:09:46 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders each stage', () => {
|
|
|
|
const result = findPathNavigationTitles();
|
|
|
|
expect(result.length).toBe(transformedProjectStagePathData.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders each stage with its median', () => {
|
|
|
|
const result = findPathNavigationTitles();
|
|
|
|
transformedProjectStagePathData.forEach(({ title, metric }, index) => {
|
|
|
|
expect(result[index]).toContain(title);
|
|
|
|
expect(result[index]).toContain(metric);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('popovers', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({ stages: transformedProjectStagePathData });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders popovers for all stages', () => {
|
|
|
|
pathItemContent().forEach((stage) => {
|
|
|
|
expect(stage.findByTestId('stage-item-popover').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the median stage time for the first stage item', () => {
|
|
|
|
expect(firstPopover().text()).toContain('Stage time (median)');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('is true', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({ loading: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('hides the gl-path component', () => {
|
|
|
|
expect(wrapper.find(GlPath).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the gl-skeleton-loading component', () => {
|
2022-05-31 23:09:43 -04:00
|
|
|
expect(wrapper.find(GlSkeletonLoader).exists()).toBe(true);
|
2021-06-02 05:09:46 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('event handling', () => {
|
|
|
|
it('emits the selected event', () => {
|
|
|
|
expect(wrapper.emitted('selected')).toBeUndefined();
|
|
|
|
|
|
|
|
clickItemAt(0);
|
|
|
|
clickItemAt(1);
|
|
|
|
clickItemAt(2);
|
|
|
|
|
|
|
|
expect(wrapper.emitted().selected).toEqual([
|
|
|
|
[transformedProjectStagePathData[0]],
|
|
|
|
[transformedProjectStagePathData[1]],
|
|
|
|
[transformedProjectStagePathData[2]],
|
|
|
|
]);
|
|
|
|
});
|
2021-06-03 05:10:18 -04:00
|
|
|
|
|
|
|
it('sends tracking information', () => {
|
|
|
|
clickItemAt(0);
|
|
|
|
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_path_navigation', {
|
|
|
|
extra: { stage_id: selectedStage.slug },
|
|
|
|
});
|
|
|
|
});
|
2021-06-02 05:09:46 -04:00
|
|
|
});
|
|
|
|
});
|