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

239 requests page tests #241

Merged
merged 7 commits into from
Mar 1, 2023
Merged

239 requests page tests #241

merged 7 commits into from
Mar 1, 2023

Conversation

summer-cook
Copy link
Contributor

@summer-cook summer-cook commented Feb 28, 2023

Story

Checks that loading & error components render correctly on the requests page
Intercepts the make-a-request-ware request and checks that linkedbutton renders

Closes #239

Related:
Component Lib PR: https://github.com/scientist-softserv/webstore-component-library/pull/171/files

Expected Behavior Before Changes

  • loading and error were not being tested
  • make a request general request button was still making an actual api request

Expected Behavior After Changes

  • loading and error are being tested and render correctly depending on mocked api responses
  • tests that linkedbutton exists both with a request list and with 0 requests

Screenshots / Video

image

if ((requestList === undefined) && (loading === true)) {
// reply with an empty response: both data and error will be undefined.
req.reply()
} else if ((requestList === undefined) && (loading === undefined) && (error === true)) {
Copy link
Member

Choose a reason for hiding this comment

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

why does loading equal undefined instead of false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all these variables are doing are switching between the different intercept cases, so it could be either undefined or false, it wouldn't really matter as long as its not true. But, it does make it easier to read to be false so i just changed it

Copy link
Member

Choose a reason for hiding this comment

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

ok.
yes, the test passes either way but I was thinking from the POV of someone who is unfamiliar with this code. just like we check the api specs to see how things work, someone may check these specs. so it's better, imo, to keep the tests in line with what the actual pages are demonstrating.

@@ -69,7 +69,7 @@ export const configureRequests = ({ data, path }) => {
export const configureErrors = (errors) => {
const env = process.env.NODE_ENV
const remainingErrors = errors
.filter(error => Object.keys(error).length)
.filter(error => error && Object.keys(error).length)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.filter(error => error && Object.keys(error).length)
.filter(error => Object.keys(error).length)

Copy link
Member

Choose a reason for hiding this comment

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

we don't have to explicitly check for the truthiness of an error here because Object.keys is handling it.

[{}, false, { a: 'a' }].filter(error => Object.keys(error).length)
=> Array [ { a: "a" } ]

Copy link
Contributor Author

@summer-cook summer-cook Mar 1, 2023

Choose a reason for hiding this comment

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

but what if the array ends up with an item that is undefined? like
[{}, false, { a: 'a' }, undefined]

That is what I was running into in the test that prompted me to change this. idk if its possible for this array of errors to contain one that is undefined, but it was happening in the test. so I figured adding a check there to make sure the error was not undefined was basically some TDD.

Copy link
Contributor Author

@summer-cook summer-cook Mar 1, 2023

Choose a reason for hiding this comment

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

when an error was undefined, Object.keys(error) was v angry

summer-cook and others added 2 commits March 1, 2023 08:30
Co-authored-by: Alisha Evans <alisha@scientist.com>
@summer-cook summer-cook merged commit 2dd1c7e into main Mar 1, 2023
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.

e2e test: requests page
2 participants