-
Notifications
You must be signed in to change notification settings - Fork 885
fix(site): display correct user_limit on license ui #8118
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { screen } from "@testing-library/react" | ||
import { render } from "../../testHelpers/renderHelpers" | ||
import { LicenseCard } from "./LicenseCard" | ||
import { MockLicenseResponse } from "testHelpers/entities" | ||
|
||
describe("LicenseCard", () => { | ||
it("renders (smoke test)", async () => { | ||
// When | ||
render( | ||
<LicenseCard | ||
license={MockLicenseResponse[0]} | ||
userLimitActual={1} | ||
userLimitLimit={10} | ||
onRemove={() => null} | ||
isRemoving={false} | ||
/>, | ||
) | ||
|
||
// Then | ||
await screen.findByText("#1") | ||
await screen.findByText("1 / 10") | ||
await screen.findByText("Enterprise") | ||
Comment on lines
+20
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't make sense to look at the entire screen for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is ok and a common practice for JS tests when using react testing library There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The practice is fine, but we should limit/scope it to the element under test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean it is safe because if the matcher finds it in multiple elements, it will raise an error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if it finds a static label placed somewhere else on the page, and our license card didn't render at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The storybook should get that. IMO, integration tests should be used to catch network and "actionable" things. Check if things are rendered correctly should be on Storybook but I get your point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is usually a recommendation to use And also in this case we are only rendering the component, there isn't anything else in the screen that could be matched. I have printed the result of a
as you can see, just the component is being rendered. |
||
}) | ||
|
||
it("renders userLimit as unlimited if there is not user limit", async () => { | ||
// When | ||
render( | ||
<LicenseCard | ||
license={MockLicenseResponse[0]} | ||
userLimitActual={1} | ||
userLimitLimit={undefined} | ||
onRemove={() => null} | ||
isRemoving={false} | ||
/>, | ||
) | ||
|
||
// Then | ||
await screen.findByText("#1") | ||
await screen.findByText("1 / Unlimited") | ||
await screen.findByText("Enterprise") | ||
}) | ||
|
||
it("renders license's user_limit when it is available instead of using the default", async () => { | ||
const licenseUserLimit = 3 | ||
const license = { | ||
...MockLicenseResponse[0], | ||
claims: { | ||
...MockLicenseResponse[0].claims, | ||
features: { | ||
...MockLicenseResponse[0].claims.features, | ||
user_limit: licenseUserLimit, | ||
}, | ||
}, | ||
} | ||
|
||
// When | ||
render( | ||
<LicenseCard | ||
license={license} | ||
userLimitActual={1} | ||
userLimitLimit={100} // This should not be used | ||
onRemove={() => null} | ||
isRemoving={false} | ||
/>, | ||
) | ||
|
||
// Then | ||
await screen.findByText("1 / 3") | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import Button from "@mui/material/Button" | ||
import Paper from "@mui/material/Paper" | ||
import { makeStyles } from "@mui/styles" | ||
import { License } from "api/typesGenerated" | ||
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog" | ||
import { Stack } from "components/Stack/Stack" | ||
import dayjs from "dayjs" | ||
import { useState } from "react" | ||
import { Pill } from "components/Pill/Pill" | ||
import { compareAsc } from "date-fns" | ||
import { GetLicensesResponse } from "api/api" | ||
|
||
type LicenseCardProps = { | ||
license: License | ||
license: GetLicensesResponse | ||
userLimitActual?: number | ||
userLimitLimit?: number | ||
onRemove: (licenseId: number) => void | ||
|
@@ -30,6 +30,9 @@ export const LicenseCard = ({ | |
number | undefined | ||
>(undefined) | ||
|
||
const currentUserLimit = | ||
rodrimaia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
license.claims.features["user_limit"] || userLimitLimit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably out of scope of this PR, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it weird as well |
||
|
||
return ( | ||
<Paper key={license.id} elevation={2} className={styles.licenseCard}> | ||
<ConfirmDialog | ||
|
@@ -72,7 +75,7 @@ export const LicenseCard = ({ | |
<Stack direction="column" spacing={0} alignItems="center"> | ||
<span className={styles.secondaryMaincolor}>Users</span> | ||
<span className={styles.userLimit}> | ||
{userLimitActual} {` / ${userLimitLimit || "Unlimited"}`} | ||
{userLimitActual} {` / ${currentUserLimit || "Unlimited"}`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we move the condition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally would rather not doing it since the user limit is a number and here we are dealing with "presentational" logic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Killer argument 👍 |
||
</span> | ||
</Stack> | ||
<Stack | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this type not returned from the typesGenerated.ts? Usually, the API endpoints and resources have generated types that are more trustable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BrunoQuaresma No, the type returned from the typesGenerated is not that strict, check the claims type: