Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vasharma05 committed May 7, 2024
1 parent fb8ac71 commit 8b0e16a
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 355 deletions.
84 changes: 84 additions & 0 deletions packages/apps/esm-login-app/__mocks__/locations.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,87 @@ export const mockLoginLocations = {
],
},
};

export const validLocationResponse = {
ok: true,
data: {
resourceType: 'Bundle',
id: 'e3c2aa40-21b0-4671-a492-bb7e7f16cc46',
meta: {
lastUpdated: '2023-11-08T08:45:48.967+00:00',
},
type: 'searchset',
total: 1,
link: [
{
relation: 'self',
url: 'https://dev3.openmrs.org/openmrs/ws/fhir2/R4/Location?_id=1ce1b7d4-c865-4178-82b0-5932e51503d6',
},
],
entry: [
{
fullUrl: 'https://dev3.openmrs.org/openmrs/ws/fhir2/R4/Location/1ce1b7d4-c865-4178-82b0-5932e51503d6',
resource: {
resourceType: 'Location',
id: '1ce1b7d4-c865-4178-82b0-5932e51503d6',
meta: {
lastUpdated: '2023-09-05T15:20:51.000+00:00',
tag: [
{
system: 'http://fhir.openmrs.org/ext/location-tag',
code: 'Login Location',
display: 'When a user logs in and chooses a session location, they may only choose one with this tag',
},
],
},
text: {
status: 'generated',
div: '<div xmlns="http://www.w3.org/1999/xhtml"><h2>Community Outreach</h2></div>',
},
status: 'active',
name: 'Community Outreach',
description: 'Community Outreach',
},
},
],
},
};

export const emptyLocationResponse = {
ok: true,
data: {
resourceType: 'Bundle',
id: 'e3c2aa40-21b0-4671-a492-bb7e7f16cc46',
meta: {
lastUpdated: '2023-11-08T08:45:48.967+00:00',
},
type: 'searchset',
total: 0,
link: [
{
relation: 'self',
url: 'https://dev3.openmrs.org/openmrs/ws/fhir2/R4/Location?_id=1ce1b7d4-c865-4178-82b0-5932e51503d6',
},
],
entry: [],
},
};

export const validatingLocationFailureResponse = {
ok: true,
data: {
resourceType: 'Bundle',
id: 'deaa418b-c900-4fd3-bb35-16fe5c2be744',
meta: {
lastUpdated: '2023-11-08T08:45:20.012+00:00',
},
type: 'searchset',
total: 0,
link: [
{
relation: 'self',
url: 'https://dev3.openmrs.org/openmrs/ws/fhir2/R4/Location?_id=8d6c993e-c2cc-11de-8d13-0010c6dffd0',
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import {
useConfig,
useConnectivity,
useSession,
useLocations,
useDebounce,
} from '@openmrs/esm-framework';
import type { LoginReferrer } from '../login/login.component';
import styles from './location-picker.scss';
import { getUserDefaultAndLoggedInLocations } from './location-picker.resource';
import type { ConfigSchema } from '../config-schema';
import { useLoginLocations } from './useLoginLocations.resource';

interface LocationPickerProps {}

Expand Down Expand Up @@ -57,7 +57,7 @@ const LocationPicker: React.FC<LocationPickerProps> = () => {
isDefaultLocationValid,
defaultLocation,
lastLoggedInLocation,
} = useLocations(chooseLocation.useLoginLocationTag, chooseLocation.locationsPerRequest, debouncedSearchTerm);
} = useLoginLocations(chooseLocation.useLoginLocationTag, chooseLocation.locationsPerRequest, debouncedSearchTerm);

const prevUserProperties = user?.userProperties;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import { act, cleanup, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {
useConfig,
useSession,
setSessionLocation,
setUserProperties,
showSnackbar,
useLocations,
} from '@openmrs/esm-framework';
import { useConfig, useSession, setSessionLocation, setUserProperties, showSnackbar } from '@openmrs/esm-framework';
import { mockLoginLocations } from '../../__mocks__/locations.mock';
import { mockConfig } from '../../__mocks__/config.mock';
import renderWithRouter from '../test-helpers/render-with-router';
import LocationPicker from './location-picker.component';
import { useLoginLocations } from './useLoginLocations.resource';

const validLocationUuid = '1ce1b7d4-c865-4178-82b0-5932e51503d6';
const invalidLocationUuid = '2gf1b7d4-c865-4178-82b0-5932e51503d6';

const mockedUseConfig = useConfig as jest.Mock;
const mockUseSession = useSession as jest.Mock;
const mockUseLocations = useLocations as jest.Mock;
const mockUseLoginLocations = useLoginLocations as jest.Mock;

mockedUseConfig.mockReturnValue(mockConfig);
mockUseSession.mockReturnValue({
Expand All @@ -36,14 +30,18 @@ jest.mock('@openmrs/esm-framework', () => ({
navigate: jest.fn(),
showSnackbar: jest.fn(),
useOpenmrsSWR: jest.fn().mockReturnValue({}),
useLocations: jest.fn(),
}));

jest.mock('./useLoginLocations.resource', () => ({
...jest.requireActual('./useLoginLocations.resource'),
useLoginLocations: jest.fn(),
}));

describe('LocationPicker', () => {
beforeEach(() => {
cleanup();
jest.clearAllMocks();
mockUseLocations.mockReturnValue({
mockUseLoginLocations.mockReturnValue({
locations: mockLoginLocations.data.entry,
isLoadingLocations: false,
hasMore: false,
Expand Down Expand Up @@ -156,7 +154,7 @@ describe('LocationPicker', () => {
},
});

mockUseLocations.mockReturnValue({
mockUseLoginLocations.mockReturnValue({
locations: mockLoginLocations.data.entry,
isDefaultLocationValid: true,
defaultLocation: validLocationUuid,
Expand Down Expand Up @@ -194,7 +192,7 @@ describe('LocationPicker', () => {
},
});

mockUseLocations.mockReturnValue({
mockUseLoginLocations.mockReturnValue({
locations: mockLoginLocations.data.entry,
isDefaultLocationValid: false,
defaultLocation: null,
Expand Down Expand Up @@ -230,7 +228,7 @@ describe('LocationPicker', () => {
},
});

mockUseLocations.mockReturnValue({
mockUseLoginLocations.mockReturnValue({
locations: mockLoginLocations.data.entry,
isDefaultLocationValid: true,
defaultLocation: validLocationUuid,
Expand Down Expand Up @@ -264,7 +262,7 @@ describe('LocationPicker', () => {
},
});

mockUseLocations.mockReturnValue({
mockUseLoginLocations.mockReturnValue({
locations: mockLoginLocations.data.entry,
isDefaultLocationValid: true,
defaultLocation: validLocationUuid,
Expand Down Expand Up @@ -320,7 +318,7 @@ describe('LocationPicker', () => {
},
});

mockUseLocations.mockReturnValue({
mockUseLoginLocations.mockReturnValue({
locations: mockLoginLocations.data.entry,
isDefaultLocationValid: true,
defaultLocation: validLocationUuid,
Expand Down
Loading

0 comments on commit 8b0e16a

Please sign in to comment.