Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes remote content browsing skipped tests #10580

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* `usePinnedDevices` composable function mock.
*
* If default values are sufficient for tests,
* you only need call `jest.mock('<usePinnedDevices file path>')`
* at the top of a test file.
*
* If you need to override some default values from some tests,
* you can import a helper function `usePinnedDevicesMock` that accepts
* an object with values to be overriden and use it together
* with `mockImplementation` as follows:
*
* ```
* // eslint-disable-next-line import/named
* import usePinnedDevices, { usePinnedDevicesMock } from '<usePinnedDevices file path>';
*
* jest.mock('<usePinnedDevices file path>')
*
* it('test', () => {
* usePinnedDevices.mockImplementation(
* () => usePinnedDevicesMock({ channels: [{ id: 'channel-1' }] })
* );
* })
* ```
*
* You can reset your mock implementation back to default values
* for other tests by calling the following in `beforeEach`:
*
* ```
* usePinnedDevices.mockImplementation(() => usePinnedDevicesMock())
* ```
*/

const MOCK_DEFAULTS = {
createPinForUser: jest.fn(() => ''),
deletePinForUser: jest.fn(() => ''),
fetchPinsForUser: jest.fn(() => []),
};

export function usePinnedDevicesMock(overrides = {}) {
return {
...MOCK_DEFAULTS,
...overrides,
};
}

export default jest.fn(() => usePinnedDevicesMock());
17 changes: 9 additions & 8 deletions kolibri/plugins/learn/assets/test/views/library-page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ const mockStore = new Vuex.Store({
},
});

jest.mock('../../src/composables/useChannels');
jest.mock('../../src/composables/useDevices');
jest.mock('../../src/composables/useSearch');
jest.mock('../../src/composables/useLearnerResources');
jest.mock('../../src/composables/useLearningActivities');
jest.mock('../../src/composables/usePinnedDevices');
jest.mock('../../src/composables/useContentLink');
jest.mock('../../src/composables/usePinnedDevices');
jest.mock('kolibri-design-system/lib/useKResponsiveWindow');
jest.mock('kolibri.resources');
jest.mock('kolibri.urls');

//ToDo: fix tests suit, overhaul could be require here
describe('LibraryPage', () => {
describe('filters button', () => {
it.skip('is visible when the page is not large', () => {
it('is visible when the page is not large', () => {
useKResponsiveWindow.mockImplementation(() => ({
windowIsLarge: false,
}));
Expand All @@ -57,7 +58,7 @@ describe('LibraryPage', () => {
});
expect(wrapper.find('[data-test="filter-button"').element).toBeTruthy();
});
it.skip('is hidden when the page is large', () => {
it('is hidden when the page is large', () => {
useKResponsiveWindow.mockImplementation(() => ({
windowIsLarge: true,
}));
Expand All @@ -70,7 +71,7 @@ describe('LibraryPage', () => {
});

describe('when user clicks the filters button', () => {
it.skip('displays the filters side panel, which is not displayed by default', async () => {
it('displays the filters side panel, which is not displayed by default', async () => {
useKResponsiveWindow.mockImplementation(() => ({
windowIsLarge: false,
}));
Expand All @@ -91,15 +92,15 @@ describe('LibraryPage', () => {

describe('displaying channels and recent/popular content ', () => {
/** useSearch#displayingSearchResults is falsy and there are rootNodes.length */
it.skip('displays a grid of channel cards', () => {
it('displays a grid of channel cards', () => {
useSearch.mockImplementation(() => useSearchMock({ displayingSearchResults: false }));
const wrapper = shallowMount(LibraryPage, {
localVue,
store: mockStore,
});
expect(wrapper.find("[data-test='channel-cards']").exists()).toBe(true);
});
it.skip('displays a ResumableContentGrid', () => {
it('displays a ResumableContentGrid', () => {
useSearch.mockImplementation(() => useSearchMock({ displayingSearchResults: false }));
const wrapper = shallowMount(LibraryPage, {
localVue,
Expand All @@ -110,7 +111,7 @@ describe('LibraryPage', () => {
});

describe('when page is loading', () => {
it.skip('shows a KCircularLoader', () => {
it('shows a KCircularLoader', () => {
useSearch.mockImplementation(() => useSearchMock({ searchLoading: true }));
const wrapper = shallowMount(LibraryPage, {
localVue,
Expand Down