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

ISSUE-9: Add tests #10

Merged
merged 4 commits into from
Oct 9, 2024
Merged

ISSUE-9: Add tests #10

merged 4 commits into from
Oct 9, 2024

Conversation

reagan-meant
Copy link
Contributor

@reagan-meant reagan-meant commented Oct 8, 2024

Requirements

  • This PR has a title that briefly describes the work done including a conventional commit type prefix and a Jira ticket number if applicable. See existing PR titles for inspiration.

For changes to apps

If applicable

  • My work includes tests or is validated by existing tests.

Summary

Issue: #9

Screenshots

Related Issue

Other

setIps((ps) => ({...ps, history: history, isLoading: isLoading, error: error?.message}));
createIpsResource(uuid, abortController)
.then((response) => {
if (response.status === 200) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if the response is not 200? I think we'd be better served by removing this check.

isLowContrast: true,
kind: 'success',
title: t('ipsCreated', 'IPS'),
title: t('ipsCreationError', 'IPS'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the title here be something like "Error updating IP"

'ipsNowAvailable',
'The IPS has been updated and is now visible in the Patient History.',
'checkForServerAvailability',
'The Fhir server maybe unreachable or the IPS generation process exited with an error!',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FHIR like IPS is an acronym (Fast Healthcare Interoperability Resources)

Suggested change
'The Fhir server maybe unreachable or the IPS generation process exited with an error!',
'The FHIR server maybe unreachable or the IPS generation process exited with an error!',

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to pass through a more detailed error from the backend. At the very least, the message should be logged to the console as an error.

subtitle: t('checkForServerAvailability', 'The Fhir server maybe unreachable or the IPS generation process exited with an error!'),
})
.finally(() => {
abortController.abort();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually kind of dangerous to call abort() on an instance that might be reused since further requests will already be aborted. It's probably better just to remove the abort controller from here altogether.

Comment on lines 27 to 28
const mockUsePatient = jest.mocked(usePatient);
const mockUseIpsResource = jest.mocked(useIpsResource);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not create the mocks once, outside of the it() block and then just change the return value?


describe('Display patient IPS', () => {
beforeEach(() => {
const mockUseParams = useParams as jest.Mock;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const mockUseParams = useParams as jest.Mock;
const mockUseParams = jest.mocked(useParams);

},
};

export const mockIPS = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usual convention would be to put this in a mocks folder rather than directly in src.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use .ts for anything that doesn't actually use JSX.

Copy link
Contributor

@ibacher ibacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically good. Two small things.

@@ -30,4 +33,5 @@ module.exports = {
testEnvironmentOptions: {
url: 'http://localhost/',
},
};
testTimeout: 25000,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
};
};

jest.config.js Outdated
@@ -30,4 +33,5 @@ module.exports = {
testEnvironmentOptions: {
url: 'http://localhost/',
},
};
testTimeout: 25000,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this timeout strictly necessary? Things like this tend to make builds take a long time (since it potentially pauses for 25 seconds for a unit tests, which feels excessive).

@ibacher ibacher merged commit d7ffa28 into main Oct 9, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants