diff --git a/src/components/sectionList/types.ts b/src/components/sectionList/types.ts index e776e422..d3b33099 100644 --- a/src/components/sectionList/types.ts +++ b/src/components/sectionList/types.ts @@ -1,5 +1,3 @@ -import { IdentifiableObject } from '../../types/generated' - export type SelectedColumn = { label: string path: string diff --git a/src/pages/dataElements/List.spec.tsx b/src/pages/dataElements/List.spec.tsx index 18d7c05e..44c41b1c 100644 --- a/src/pages/dataElements/List.spec.tsx +++ b/src/pages/dataElements/List.spec.tsx @@ -1,3 +1,4 @@ +import { FetchError } from '@dhis2/app-runtime' import { render, waitForElementToBeRemoved, @@ -9,6 +10,7 @@ import React from 'react' import dataElementsMock from '../../__mocks__/gists/dataElementsMock.json' import filteredDataElementsMock from '../../__mocks__/gists/filteredDataElementsMock.json' import dataElementSchemaMock from '../../__mocks__/schema/dataElementsSchema.json' +import { useModelListView } from '../../components/sectionList/listView' import { SECTIONS_MAP } from '../../lib' import { useSchemaStore } from '../../lib/schemas/schemaStore' import { ModelSchemas } from '../../lib/useLoadApp' @@ -37,10 +39,19 @@ const renderSection = async (customData: CustomData) => { return result } +// userDataStore returns 404 if user hasnt edited a view, this is expected behaviour +const error404 = new FetchError({ + type: 'unknown', + message: '404 not found', + details: { httpStatusCode: 404 } as FetchError['details'], +}) +const defaultUserDataStoreData = () => Promise.reject(new FetchError(error404)) + describe('Data Elements List', () => { + const originalWarn = console.warn jest.spyOn(console, 'warn').mockImplementation((value) => { if (!value.match(/No server timezone/)) { - console.warn(value) + originalWarn(value) } }) @@ -53,7 +64,7 @@ describe('Data Elements List', () => { it('should show the list of elements', async () => { const customData = { 'dataElements/gist': dataElementsMock, - userDataStore: {}, + userDataStore: defaultUserDataStoreData, } const { getByText, getByTestId } = await renderSection(customData) @@ -70,7 +81,7 @@ describe('Data Elements List', () => { it('should display all the columns', async () => { const customData = { 'dataElements/gist': dataElementsMock, - userDataStore: {}, + userDataStore: defaultUserDataStoreData, } const { getByText } = await renderSection(customData) const columns = [ @@ -87,7 +98,7 @@ describe('Data Elements List', () => { }) it('should allow searching for value', async () => { const customData = { - userDataStore: {}, + userDataStore: defaultUserDataStoreData, 'dataElements/gist': ( resource: string, r: { params: { filter: string[] } } @@ -118,7 +129,7 @@ describe('Data Elements List', () => { it('should display error when an API call fails', async () => { const customData = { - userDataStore: {}, + userDataStore: defaultUserDataStoreData, 'dataElements/gist': () => { return Promise.reject('401 backend error') }, @@ -136,7 +147,7 @@ describe('Data Elements List', () => { const renderWithPager = async () => { const customData = { - userDataStore: {}, + userDataStore: defaultUserDataStoreData, 'dataElements/gist': ( resource: string, r: { params: { filter: string[]; page: number } } @@ -240,7 +251,7 @@ describe('Data Elements List', () => { // I tried different approaches and failed. Leaving it here temporarily in case someone want to give it a go. it.skip('should not show next in last page', async () => { const { getByTestId, findByText } = await renderSection({ - userDataStore: {}, + userDataStore: defaultUserDataStoreData, 'dataElements/gist': { pager: { page: 54, @@ -275,7 +286,7 @@ describe('Data Elements List', () => { // select all it('should allow selecting all items', async () => { const customData = { - userDataStore: {}, + userDataStore: defaultUserDataStoreData, 'dataElements/gist': dataElementsMock, } const { getByTestId, queryAllByTestId } = await renderSection( @@ -298,7 +309,7 @@ describe('Data Elements List', () => { // empty list it('should allow selecting all items', async () => { const customData = { - userDataStore: {}, + userDataStore: defaultUserDataStoreData, 'dataElements/gist': { ...dataElementsMock, result: [] }, } const { getByTestId } = await renderSection(customData) diff --git a/src/pages/dataElements/List.tsx b/src/pages/dataElements/List.tsx index d9b3fe48..9a9ec85a 100644 --- a/src/pages/dataElements/List.tsx +++ b/src/pages/dataElements/List.tsx @@ -36,6 +36,7 @@ export const Component = () => { // refetched on mount by effect below { lazy: true } ) + useEffect(() => { // wait to fetch until selected-columns are loaded // so we dont fetch data multiple times