-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from sfbrigade/wip-search-form-test
Wip search form test
- Loading branch information
Showing
7 changed files
with
192 additions
and
88 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,90 @@ | ||
import React from "react"; | ||
import {fireEvent, render, screen} from "@testing-library/react"; | ||
import {SearchForm} from "./SearchForm"; | ||
import {idleForIO} from "../../testUtils"; | ||
import {createMemoryHistory} from "history"; | ||
import {Route, Router} from "react-router-dom"; | ||
|
||
const history = createMemoryHistory(); | ||
jest.spyOn(history, "push"); | ||
|
||
describe('SearchForm selections', () => { | ||
beforeEach(() => { | ||
render( | ||
<Router history={history}> | ||
<Route component={SearchForm} /> | ||
</Router> | ||
); | ||
}); | ||
|
||
it('renders a SearchForm with two default Anys', () => { | ||
const anyObject = screen.getAllByRole('option', {name: 'Any'}); | ||
expect(anyObject).toHaveLength(2); | ||
}); | ||
|
||
it('can search with no user selections', async () => { | ||
const searchButton = screen.getByText("Search"); | ||
fireEvent.click(searchButton); | ||
|
||
expect(history.push).toHaveBeenLastCalledWith("/results"); | ||
|
||
const anyObject = screen.getAllByRole('option', {name: 'Any'}); | ||
expect((anyObject[0] as HTMLOptionElement).selected).toBeTruthy(); | ||
expect((anyObject[1] as HTMLOptionElement).selected).toBeTruthy(); | ||
}); | ||
|
||
it('can search by orgType', async () => { | ||
fireEvent.change(screen.getByLabelText('I am a...'), | ||
{ target: { value: 'smallBusiness' } }); | ||
|
||
const searchButton = screen.getByText("Search"); | ||
fireEvent.click(searchButton); | ||
|
||
await idleForIO(); | ||
|
||
expect(history.push).toHaveBeenLastCalledWith("/results?orgType=smallBusiness"); | ||
|
||
const smallBusinessOption = screen.getAllByRole('option', {name: 'Small business'}); | ||
expect((smallBusinessOption[0] as HTMLOptionElement).selected).toBeTruthy(); | ||
const anyObject = screen.getAllByRole('option', {name: 'Any'}); | ||
expect((anyObject[0] as HTMLOptionElement).selected).toBeFalsy(); | ||
expect((anyObject[1] as HTMLOptionElement).selected).toBeTruthy(); | ||
}); | ||
|
||
it('can search by county only', async () => { | ||
fireEvent.change(screen.getByLabelText("County"), | ||
{ target: { value: 'alamedaCounty' } }); | ||
|
||
const searchButton = screen.getByText("Search"); | ||
fireEvent.click(searchButton); | ||
|
||
await idleForIO(); | ||
|
||
expect(history.push).toHaveBeenLastCalledWith("/results?county=alamedaCounty"); | ||
|
||
const countyOption = screen.getAllByRole('option', {name: 'Alameda'}); | ||
expect((countyOption[0] as HTMLOptionElement).selected).toBeTruthy(); | ||
const anyObject = screen.getAllByRole('option', {name: 'Any'}); | ||
expect((anyObject[0] as HTMLOptionElement).selected).toBeTruthy(); | ||
expect((anyObject[1] as HTMLOptionElement).selected).toBeFalsy(); | ||
}); | ||
|
||
it('can search by county and org type', async () => { | ||
fireEvent.change(screen.getByLabelText('I am a...'), | ||
{ target: { value: 'smallBusiness' } }); | ||
fireEvent.change(screen.getByLabelText("County"), | ||
{ target: { value: 'alamedaCounty' } }); | ||
|
||
const searchButton = screen.getByText("Search"); | ||
fireEvent.click(searchButton); | ||
|
||
await idleForIO(); | ||
|
||
expect(history.push).toHaveBeenLastCalledWith("/results?orgType=smallBusiness&county=alamedaCounty"); | ||
|
||
const countyOption = screen.getAllByRole('option', {name: 'Alameda'}); | ||
expect((countyOption[0] as HTMLOptionElement).selected).toBeTruthy(); | ||
const smallBusinessOption = screen.getAllByRole('option', {name: 'Small business'}); | ||
expect((smallBusinessOption[0] as HTMLOptionElement).selected).toBeTruthy(); | ||
}); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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.