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

feat: create frontend mock endpoint for get codelists #14513

Closed
Closed
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
33 changes: 33 additions & 0 deletions frontend/packages/shared/src/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,36 @@ export const getProcessTaskType = (org: string, app: string, taskId: string) =>

// Contact Page
export const fetchBelongsToGiteaOrg = () => get(belongsToOrg());

// Org level code lists
const orgLevelCodeListsMock: OptionListsResponse[] = [
[
{
title: 'title1',
data: [
{ label: 'label1', value: 'value1' },
{ label: 'label2', value: 'value2' },
],
hasError: false,
},
{
title: 'title2',
data: [],
hasError: false,
},
],
[
{
title: 'title3',
data: [],
hasError: false,
},
],
];
export const getOrgLevelCodeLists = async (org: string): Promise<OptionListsResponse[]> =>
// TODO: Replace with endpoint when it is ready in backend. https://github.com/Altinn/altinn-studio/issues/14482
new Promise((resolve) => {
setTimeout(() => {
resolve(orgLevelCodeListsMock);
}, 200);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { queriesMock } from 'app-shared/mocks/queriesMock';
import { renderHookWithProviders } from 'app-shared/mocks/renderHookWithProviders';
import { waitFor } from '@testing-library/react';
import { useOrgLevelCodeListsQuery } from './useOrgLevelCodeListsQuery';

describe('useOrgLevelCodeListsQuery', () => {
it('calls getOrgLevelCodeLists with the correct parameters', () => {
render();
expect(queriesMock.getOrgLevelCodeLists).toHaveBeenCalledWith();
expect(queriesMock.getOrgLevelCodeLists).toHaveBeenCalledTimes(1);
});
});

const render = async () => {
const { result } = renderHookWithProviders(() => useOrgLevelCodeListsQuery());
await waitFor(() => expect(result.current.isSuccess).toBe(true));
return result;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useQuery } from '@tanstack/react-query';
import { QueryKey } from 'app-shared/types/QueryKey';
import { useServicesContext } from 'app-shared/contexts/ServicesContext';
import type { OptionListsResponse } from 'app-shared/types/api/OptionListsResponse';

export const useOrgLevelCodeListsQuery = () => {
const { getOrgLevelCodeLists } = useServicesContext();
return useQuery<OptionListsResponse[]>({
queryKey: [QueryKey.OrgLevelCodeLists],
queryFn: () => getOrgLevelCodeLists(),

Check failure on line 10 in frontend/packages/shared/src/hooks/queries/useOrgLevelCodeListsQuery.ts

View workflow job for this annotation

GitHub Actions / Typechecking and linting

Expected 1 arguments, but got 0.
});
};
1 change: 1 addition & 0 deletions frontend/packages/shared/src/mocks/queriesMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import type { OptionListsResponse } from 'app-shared/types/api/OptionListsRespon

export const queriesMock: ServicesContextProps = {
// Queries
getOrgLevelCodeLists: jest.fn().mockImplementation(() => Promise.resolve([])),
getAppMetadataModelIds: jest.fn().mockImplementation(() => Promise.resolve<string[]>([])),
getAppReleases: jest
.fn()
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/shared/src/types/QueryKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export enum QueryKey {
AppScopes = 'AppScopes',
SelectedAppScopes = 'SelectedAppScopes',
DataType = 'DataType',
OrgLevelCodeLists = 'OrgLevelCodeLists',

// Resourceadm
ResourceList = 'ResourceList',
Expand Down
Loading