-
Notifications
You must be signed in to change notification settings - Fork 43
test: listing intro test #5550
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
Merged
Merged
test: listing intro test #5550
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
58c5f70
test: listing intro test
emilyjablonski 5c15190
feat: add feature flag for housing developer owner (#5549)
KrissDrawing 1f59535
test: listing intro test
emilyjablonski 8627725
Merge branch 'main' into test/listing-intro
emilyjablonski 7a8feb3
fix: duplicate import
emilyjablonski 6ca1ccf
fix: pr review
emilyjablonski ca84bb3
Merge branch 'main' into test/listing-intro
emilyjablonski 115590c
Merge branch 'main' into test/listing-intro
emilyjablonski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
sites/partners/__tests__/components/listings/PaperListingForm/sections/ListingIntro.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| import React from "react" | ||
| import { rest } from "msw" | ||
| import { setupServer } from "msw/node" | ||
| import userEvent from "@testing-library/user-event" | ||
| import { screen } from "@testing-library/react" | ||
| import { FormProvider, useForm } from "react-hook-form" | ||
| import { | ||
| FeatureFlagEnum, | ||
| Jurisdiction, | ||
| } from "@bloom-housing/shared-helpers/src/types/backend-swagger" | ||
| import { mockNextRouter, render } from "../../../../testUtils" | ||
| import { formDefaults, FormListing } from "../../../../../src/lib/listings/formTypes" | ||
| import ListingIntro from "../../../../../src/components/listings/PaperListingForm/sections/ListingIntro" | ||
|
|
||
| const FormComponent = ({ children, values }: { values?: FormListing; children }) => { | ||
| const formMethods = useForm<FormListing>({ | ||
| defaultValues: { ...formDefaults, ...values }, | ||
| shouldUnregister: false, | ||
| }) | ||
| return <FormProvider {...formMethods}>{children}</FormProvider> | ||
| } | ||
|
|
||
| const server = setupServer() | ||
|
|
||
| // Enable API mocking before tests. | ||
| beforeAll(() => { | ||
| server.listen() | ||
| mockNextRouter() | ||
| }) | ||
|
|
||
| // Reset any runtime request handlers we may add during the tests. | ||
| afterEach(() => server.resetHandlers()) | ||
|
|
||
| // Disable API mocking after the tests are done. | ||
| afterAll(() => server.close()) | ||
|
|
||
| describe("ListingIntro", () => { | ||
| const adminUserWithJurisdictions = { | ||
| jurisdictions: [ | ||
| { | ||
| id: "jurisdiction1", | ||
| name: "jurisdictionWithJurisdictionAdmin", | ||
| featureFlags: [], | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| it("should render the ListingIntro section with one jurisdiction", async () => { | ||
| document.cookie = "access-token-available=True" | ||
| server.use( | ||
| rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => { | ||
| return res(ctx.json(adminUserWithJurisdictions)) | ||
| }) | ||
| ) | ||
|
|
||
| render( | ||
| <FormComponent> | ||
| <ListingIntro | ||
| requiredFields={[]} | ||
| jurisdictions={[ | ||
| { | ||
| id: "JurisdictionA", | ||
| name: "JurisdictionA", | ||
| } as unknown as Jurisdiction, | ||
| ]} | ||
| /> | ||
| </FormComponent> | ||
| ) | ||
|
|
||
| await screen.findByRole("heading", { level: 2, name: "Listing intro" }) | ||
| expect( | ||
| screen.getByText("Let's get started with some basic information about your listing.") | ||
| ).toBeInTheDocument() | ||
| expect(screen.getByRole("textbox", { name: "Listing name *" })).toBeInTheDocument() | ||
| expect(screen.queryByRole("combobox", { name: "Jurisdiction *" })).not.toBeInTheDocument() | ||
| expect(screen.getByRole("textbox", { name: "Housing developer" })).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("should render the ListingIntro section with multiple jurisdictions and required developer", async () => { | ||
| document.cookie = "access-token-available=True" | ||
| server.use( | ||
| rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => { | ||
| return res(ctx.json(adminUserWithJurisdictions)) | ||
| }) | ||
| ) | ||
|
|
||
| render( | ||
| <FormComponent> | ||
| <ListingIntro | ||
| requiredFields={["developer"]} | ||
| jurisdictions={[ | ||
| { | ||
| id: "JurisdictionA", | ||
| name: "JurisdictionA", | ||
| } as unknown as Jurisdiction, | ||
| { | ||
| id: "JurisdictionB", | ||
| name: "JurisdictionB", | ||
| } as unknown as Jurisdiction, | ||
| ]} | ||
| /> | ||
| </FormComponent> | ||
| ) | ||
|
|
||
| expect(screen.getByRole("textbox", { name: "Listing name *" })).toBeInTheDocument() | ||
| expect(screen.getByRole("combobox", { name: "Jurisdiction *" })).toBeInTheDocument() | ||
| expect(screen.getByRole("textbox", { name: "Housing developer *" })).toBeInTheDocument() | ||
|
|
||
| await userEvent.selectOptions( | ||
| screen.getByRole("combobox", { name: "Jurisdiction *" }), | ||
| screen.getByRole("option", { name: "JurisdictionA" }) | ||
| ) | ||
|
|
||
| expect(screen.getByRole("textbox", { name: "Housing developer *" })).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("should render appropriate text when housing developer owner feature flag is on", async () => { | ||
| document.cookie = "access-token-available=True" | ||
| server.use( | ||
| rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => { | ||
| return res( | ||
| ctx.json({ | ||
| jurisdictions: [ | ||
| { | ||
| id: "JurisdictionA", | ||
| name: "jurisdictionWithJurisdictionAdmin", | ||
| featureFlags: [{ name: FeatureFlagEnum.enableHousingDeveloperOwner, active: true }], | ||
| }, | ||
| ], | ||
| }) | ||
| ) | ||
| }) | ||
| ) | ||
|
|
||
| render( | ||
| <FormComponent> | ||
| <ListingIntro | ||
| requiredFields={[]} | ||
| jurisdictions={[ | ||
| { | ||
| id: "JurisdictionA", | ||
| name: "JurisdictionA", | ||
| featureFlags: [{ name: FeatureFlagEnum.enableHousingDeveloperOwner, active: true }], | ||
| } as unknown as Jurisdiction, | ||
| ]} | ||
| /> | ||
| </FormComponent> | ||
| ) | ||
| await screen.findByRole("textbox", { name: "Housing developer / owner" }) | ||
| expect(screen.getByRole("textbox", { name: "Housing developer / owner" })).toBeInTheDocument() | ||
| expect(screen.queryByRole("textbox", { name: "Housing developer" })).not.toBeInTheDocument() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.