debian-mirror-gitlab/spec/frontend/releases/components/app_show_spec.js

64 lines
2 KiB
JavaScript
Raw Normal View History

2020-04-08 14:13:33 +05:30
import { shallowMount } from '@vue/test-utils';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
2021-01-03 14:25:43 +05:30
import { getJSONFixture } from 'helpers/fixtures';
2021-03-11 19:13:27 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2020-04-08 14:13:33 +05:30
import ReleaseShowApp from '~/releases/components/app_show.vue';
import ReleaseBlock from '~/releases/components/release_block.vue';
2021-03-11 19:13:27 +05:30
import ReleaseSkeletonLoader from '~/releases/components/release_skeleton_loader.vue';
2020-04-08 14:13:33 +05:30
2021-01-03 14:25:43 +05:30
const originalRelease = getJSONFixture('api/releases/release.json');
2020-04-08 14:13:33 +05:30
describe('Release show component', () => {
let wrapper;
let release;
let actions;
beforeEach(() => {
release = convertObjectPropsToCamelCase(originalRelease);
});
2021-03-08 18:12:59 +05:30
const factory = (state) => {
2020-04-08 14:13:33 +05:30
actions = {
fetchRelease: jest.fn(),
};
const store = new Vuex.Store({
modules: {
detail: {
namespaced: true,
actions,
state,
},
},
});
wrapper = shallowMount(ReleaseShowApp, { store });
};
2021-01-03 14:25:43 +05:30
const findLoadingSkeleton = () => wrapper.find(ReleaseSkeletonLoader);
2020-04-08 14:13:33 +05:30
const findReleaseBlock = () => wrapper.find(ReleaseBlock);
it('calls fetchRelease when the component is created', () => {
factory({ release });
expect(actions.fetchRelease).toHaveBeenCalledTimes(1);
});
it('shows a loading skeleton and hides the release block while the API call is in progress', () => {
factory({ isFetchingRelease: true });
expect(findLoadingSkeleton().exists()).toBe(true);
expect(findReleaseBlock().exists()).toBe(false);
});
it('hides the loading skeleton and shows the release block when the API call finishes successfully', () => {
factory({ isFetchingRelease: false });
expect(findLoadingSkeleton().exists()).toBe(false);
expect(findReleaseBlock().exists()).toBe(true);
});
it('hides both the loading skeleton and the release block when the API call fails', () => {
factory({ fetchError: new Error('Uh oh') });
expect(findLoadingSkeleton().exists()).toBe(false);
expect(findReleaseBlock().exists()).toBe(false);
});
});