2021-01-11 13:10:43 -05:00
|
|
|
import { GlSprintf } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { nextTick } from 'vue';
|
2021-01-11 13:10:43 -05:00
|
|
|
import StatusBox from '~/merge_request/components/status_box.vue';
|
|
|
|
import mrEventHub from '~/merge_request/eventhub';
|
|
|
|
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
function factory(propsData) {
|
|
|
|
wrapper = shallowMount(StatusBox, { propsData, stubs: { GlSprintf } });
|
|
|
|
}
|
|
|
|
|
|
|
|
const testCases = [
|
|
|
|
{
|
|
|
|
name: 'Open',
|
|
|
|
state: 'opened',
|
|
|
|
class: 'status-box-open',
|
|
|
|
icon: 'issue-open-m',
|
|
|
|
},
|
2021-01-21 13:09:11 -05:00
|
|
|
{
|
|
|
|
name: 'Open',
|
|
|
|
state: 'locked',
|
|
|
|
class: 'status-box-open',
|
|
|
|
icon: 'issue-open-m',
|
|
|
|
},
|
2021-01-11 13:10:43 -05:00
|
|
|
{
|
|
|
|
name: 'Closed',
|
|
|
|
state: 'closed',
|
|
|
|
class: 'status-box-mr-closed',
|
|
|
|
icon: 'close',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Merged',
|
|
|
|
state: 'merged',
|
|
|
|
class: 'status-box-mr-merged',
|
|
|
|
icon: 'git-merge',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
describe('Merge request status box component', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
testCases.forEach((testCase) => {
|
|
|
|
describe(`when merge request is ${testCase.name}`, () => {
|
|
|
|
it('renders human readable test', () => {
|
|
|
|
factory({
|
|
|
|
initialState: testCase.state,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain(testCase.name);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets css class', () => {
|
|
|
|
factory({
|
|
|
|
initialState: testCase.state,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.classes()).toContain(testCase.class);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders icon', () => {
|
|
|
|
factory({
|
|
|
|
initialState: testCase.state,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find('[data-testid="status-icon"]').props('name')).toBe(testCase.icon);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates with eventhub event', async () => {
|
|
|
|
factory({
|
|
|
|
initialState: 'opened',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('Open');
|
|
|
|
|
2021-01-13 07:10:27 -05:00
|
|
|
mrEventHub.$emit('mr.state.updated', { state: 'closed' });
|
2021-01-11 13:10:43 -05:00
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('Closed');
|
|
|
|
});
|
|
|
|
});
|