Skip to content

Commit

Permalink
chore: update SWR to version 2.x and add KenyaEMR link unit test (#8)
Browse files Browse the repository at this point in the history
* chore: update swr to version 2.x

* add Unit test for KenyaEMR link
  • Loading branch information
donaldkibet authored Feb 17, 2023
1 parent e87f4fd commit 3c9bacb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"extract-translations": "lerna run extract-translations -- --config ../../tools/i18next-parser.config.js"
},
"dependencies": {
"swr": "^1.0.1"
"swr": "2.0.1"
},
"devDependencies": {
"@babel/core": "^7.11.6",
Expand Down
7 changes: 5 additions & 2 deletions packages/esm-patient-flags-app/src/hooks/usePatientFlags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ interface PatientFlagsReturnType {
*/
export const usePatientFlags = (patientUuid: string): PatientFlagsReturnType => {
const patientFlagsUrl = `/ws/rest/v1/kenyaemr/flags?patientUuid=${patientUuid}`;
const { data, mutate, error } = useSWR<{ data: { results: Array<string> } }>(patientFlagsUrl, openmrsFetch);
const { data, mutate, error, isLoading } = useSWR<{ data: { results: Array<string> } }>(
patientFlagsUrl,
openmrsFetch,
);
const patientFlags = typeof data?.data === 'string' ? [] : data?.data?.results ?? [];
return { patientFlags, isLoading: !data && !error, error };
return { patientFlags, isLoading, error };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import KenyaEMRLink from './kenyaemr-link.component';
import { render, screen } from '@testing-library/react';

describe('KenyaEMR Link', () => {
test('should display the KenyaEMR link to SPA', () => {
render(<KenyaEMRLink />);

const kenyaEMRLink = screen.getByRole('link', { name: /KenyaEMR/i });
expect(kenyaEMRLink).toBeInTheDocument();
expect(kenyaEMRLink).toHaveAttribute('href', '/openmrs/kenyaemr/userHome.page?');
});
});
32 changes: 26 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4123,7 +4123,7 @@ __metadata:
react-router-dom: ^6.3.0
sass: ^1.29.0
sass-loader: ^10.1.0
swr: ^1.0.1
swr: 2.0.1
turbo: ^1.2.2
typedoc: ^0.22.15
typescript: ^4.0.3
Expand Down Expand Up @@ -10454,7 +10454,7 @@ __metadata:

"fsevents@patch:fsevents@^2.3.2#~builtin<compat/fsevents>, fsevents@patch:fsevents@~2.3.2#~builtin<compat/fsevents>":
version: 2.3.2
resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=18f3a7"
resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=df0bf1"
dependencies:
node-gyp: latest
conditions: os=darwin
Expand Down Expand Up @@ -17024,7 +17024,7 @@ __metadata:

"resolve@patch:resolve@^1.10.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.14.2#~builtin<compat/resolve>, resolve@patch:resolve@^1.19.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.20.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.9.0#~builtin<compat/resolve>":
version: 1.22.1
resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin<compat/resolve>::version=1.22.1&hash=07638b"
resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin<compat/resolve>::version=1.22.1&hash=c3c19d"
dependencies:
is-core-module: ^2.9.0
path-parse: ^1.0.7
Expand Down Expand Up @@ -18456,7 +18456,18 @@ __metadata:
languageName: node
linkType: hard

"swr@npm:^1.0.1, swr@npm:^1.2.2":
"swr@npm:2.0.1":
version: 2.0.1
resolution: "swr@npm:2.0.1"
dependencies:
use-sync-external-store: ^1.2.0
peerDependencies:
react: ^16.11.0 || ^17.0.0 || ^18.0.0
checksum: 5466e46a80bccf722c212ea3f14668b4e7f047d958f3da7252fba3529e6b1773a1762aa4bbf43aec104cc50625dbd55380539eeef59fd5ad9ebca6ad0552f45d
languageName: node
linkType: hard

"swr@npm:^1.2.2":
version: 1.3.0
resolution: "swr@npm:1.3.0"
peerDependencies:
Expand Down Expand Up @@ -19253,7 +19264,7 @@ __metadata:

"typescript@patch:typescript@^4.0.3#~builtin<compat/typescript>, typescript@patch:typescript@^4.2.4#~builtin<compat/typescript>":
version: 4.7.4
resolution: "typescript@patch:typescript@npm%3A4.7.4#~builtin<compat/typescript>::version=4.7.4&hash=a1c5e5"
resolution: "typescript@patch:typescript@npm%3A4.7.4#~builtin<compat/typescript>::version=4.7.4&hash=65a307"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
Expand All @@ -19263,7 +19274,7 @@ __metadata:

"typescript@patch:typescript@~4.5.2#~builtin<compat/typescript>":
version: 4.5.5
resolution: "typescript@patch:typescript@npm%3A4.5.5#~builtin<compat/typescript>::version=4.5.5&hash=a1c5e5"
resolution: "typescript@patch:typescript@npm%3A4.5.5#~builtin<compat/typescript>::version=4.5.5&hash=bcec9a"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
Expand Down Expand Up @@ -19511,6 +19522,15 @@ __metadata:
languageName: node
linkType: hard

"use-sync-external-store@npm:^1.2.0":
version: 1.2.0
resolution: "use-sync-external-store@npm:1.2.0"
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0
checksum: 5c639e0f8da3521d605f59ce5be9e094ca772bd44a4ce7322b055a6f58eeed8dda3c94cabd90c7a41fb6fa852210092008afe48f7038792fd47501f33299116a
languageName: node
linkType: hard

"use@npm:^3.1.0":
version: 3.1.1
resolution: "use@npm:3.1.1"
Expand Down

0 comments on commit 3c9bacb

Please sign in to comment.