2020-04-08 14:13:33 +05:30
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { getJSONFixture } from 'helpers/fixtures';
|
2020-04-08 14:13:33 +05:30
|
|
|
import ReleaseShowApp from '~/releases/components/app_show.vue';
|
2021-01-03 14:25:43 +05:30
|
|
|
import ReleaseSkeletonLoader from '~/releases/components/release_skeleton_loader.vue';
|
2020-04-08 14:13:33 +05:30
|
|
|
import ReleaseBlock from '~/releases/components/release_block.vue';
|
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|