debian-mirror-gitlab/spec/frontend/mr_popover/mr_popover_spec.js

81 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-07-07 11:18:12 +05:30
import { shallowMount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2020-03-13 15:44:24 +05:30
import MRPopover from '~/mr_popover/components/mr_popover.vue';
import CiIcon from '~/vue_shared/components/ci_icon.vue';
2019-07-07 11:18:12 +05:30
describe('MR Popover', () => {
let wrapper;
beforeEach(() => {
wrapper = shallowMount(MRPopover, {
propsData: {
target: document.createElement('a'),
projectPath: 'foo/bar',
mergeRequestIID: '1',
mergeRequestTitle: 'MR Title',
},
mocks: {
$apollo: {
2022-01-26 12:08:38 +05:30
queries: {
mergeRequest: {
loading: false,
},
},
2019-07-07 11:18:12 +05:30
},
},
});
});
2022-04-04 11:22:00 +05:30
it('shows skeleton-loader while apollo is loading', async () => {
2022-01-26 12:08:38 +05:30
wrapper.vm.$apollo.queries.mergeRequest.loading = true;
2019-07-07 11:18:12 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.element).toMatchSnapshot();
2019-07-07 11:18:12 +05:30
});
describe('loaded state', () => {
2022-04-04 11:22:00 +05:30
it('matches the snapshot', async () => {
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2019-07-07 11:18:12 +05:30
wrapper.setData({
mergeRequest: {
2022-01-26 12:08:38 +05:30
title: 'Updated Title',
2019-07-07 11:18:12 +05:30
state: 'opened',
createdAt: new Date(),
headPipeline: {
detailedStatus: {
group: 'success',
status: 'status_success',
},
},
},
});
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.element).toMatchSnapshot();
2019-07-07 11:18:12 +05:30
});
2022-04-04 11:22:00 +05:30
it('does not show CI Icon if there is no pipeline data', async () => {
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2019-07-07 11:18:12 +05:30
wrapper.setData({
mergeRequest: {
state: 'opened',
headPipeline: null,
stateHumanName: 'Open',
title: 'Merge Request Title',
createdAt: new Date(),
},
});
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.find(CiIcon).exists()).toBe(false);
2019-07-07 11:18:12 +05:30
});
2022-01-26 12:08:38 +05:30
2022-04-04 11:22:00 +05:30
it('falls back to cached MR title when request fails', async () => {
await nextTick();
expect(wrapper.text()).toContain('MR Title');
2022-01-26 12:08:38 +05:30
});
2019-07-07 11:18:12 +05:30
});
});