-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a86739
commit b240fce
Showing
6 changed files
with
126 additions
and
27 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/components/FlightTimeSelector/FlightTimeSelector.definitions.ts
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,11 @@ | ||
export type Value = Date | null | [Date, Date]; | ||
|
||
export interface FormTypes { | ||
departDate: Value; | ||
arrivalDate: Value; | ||
oneWay: boolean; | ||
departureAirportPrimary: string; | ||
departureAirportAlternate: string; | ||
arrivalAirportPrimary: string; | ||
arrivalAirportAlternate: string; | ||
} |
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
103 changes: 103 additions & 0 deletions
103
src/components/FlightTimeSelector/__tests__/FlightTimeSelector.test.tsx
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,103 @@ | ||
import FlightTimeSelector from "../FlightTimeSelector"; | ||
import { render, fireEvent, waitFor } from "@testing-library/react"; | ||
|
||
describe("FlightTimeSelector Tests", () => { | ||
it("renders FlightTimeSelector component correctly", () => { | ||
const { getByText, getByPlaceholderText } = render(<FlightTimeSelector />); | ||
|
||
expect(getByText("Flight Selector")).toBeTruthy(); | ||
expect(getByText("Select your flight")).toBeTruthy(); | ||
expect(getByPlaceholderText("Primary Selection")).toBeTruthy(); | ||
expect(getByPlaceholderText("Alternate Selection")).toBeTruthy(); | ||
}); | ||
|
||
it("updates departure airports on input change", () => { | ||
const { getByPlaceholderText } = render(<FlightTimeSelector />); | ||
const primaryInput = getByPlaceholderText( | ||
"Primary Selection", | ||
) as HTMLInputElement; | ||
const alternateInput = getByPlaceholderText( | ||
"Alternate Selection", | ||
) as HTMLInputElement; | ||
|
||
fireEvent.change(primaryInput, { target: { value: "JFK" } }); | ||
fireEvent.change(alternateInput, { target: { value: "LGA" } }); | ||
|
||
expect(primaryInput.value).toBe("JFK"); | ||
expect(alternateInput.value).toBe("LGA"); | ||
}); | ||
|
||
it("toggles oneWay checkbox", () => { | ||
const { getByLabelText } = render(<FlightTimeSelector />); | ||
const oneWayCheckbox = getByLabelText("One way:") as HTMLInputElement; | ||
|
||
fireEvent.click(oneWayCheckbox); | ||
|
||
expect(oneWayCheckbox.checked).toBe(true); | ||
}); | ||
|
||
it("disables submit button when required fields are empty", () => { | ||
const { getByText, getByPlaceholderText } = render(<FlightTimeSelector />); | ||
const submitButton = getByText("Submit") as HTMLButtonElement; | ||
|
||
fireEvent.click(submitButton); | ||
|
||
// Ensure that the submit button is initially disabled | ||
expect(submitButton.disabled).toBe(true); | ||
|
||
// Fill in some fields | ||
fireEvent.change( | ||
getByPlaceholderText("Primary Selection") as HTMLInputElement, | ||
{ target: { value: "JFK" } }, | ||
); | ||
fireEvent.change( | ||
getByPlaceholderText("Alternate Selection") as HTMLInputElement, | ||
{ target: { value: "LGA" } }, | ||
); | ||
fireEvent.change( | ||
getByPlaceholderText("Primary Selection") as HTMLInputElement, | ||
{ target: { value: "ORD" } }, | ||
); | ||
fireEvent.change( | ||
getByPlaceholderText("Alternate Selection") as HTMLInputElement, | ||
{ target: { value: "DFW" } }, | ||
); | ||
// fireEvent.click(getByLabelText('One way:')); | ||
|
||
// Ensure that the submit button is enabled after filling in required fields | ||
expect(submitButton.disabled).toBe(false); | ||
}); | ||
|
||
it("submits the form when submit button is clicked", async () => { | ||
const { getByText, getByPlaceholderText } = render(<FlightTimeSelector />); | ||
const submitButton = getByText("Submit") as HTMLButtonElement; | ||
|
||
fireEvent.change( | ||
getByPlaceholderText("Primary Selection") as HTMLInputElement, | ||
{ target: { value: "JFK" } }, | ||
); | ||
fireEvent.change( | ||
getByPlaceholderText("Alternate Selection") as HTMLInputElement, | ||
{ target: { value: "LGA" } }, | ||
); | ||
fireEvent.change( | ||
getByPlaceholderText("Primary Selection") as HTMLInputElement, | ||
{ target: { value: "ORD" } }, | ||
); | ||
fireEvent.change( | ||
getByPlaceholderText("Alternate Selection") as HTMLInputElement, | ||
{ target: { value: "DFW" } }, | ||
); | ||
// fireEvent.click(getByLabelText('One way:'), { target: { checked: true } }); | ||
|
||
fireEvent.click(submitButton); | ||
|
||
await waitFor(() => { | ||
expect(getByText("JFK")).toBeTruthy(); | ||
expect(getByText("LGA")).toBeTruthy(); | ||
expect(getByText("ORD")).toBeTruthy(); | ||
expect(getByText("DFW")).toBeTruthy(); | ||
// expect(getByText('One way:')).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
import FlightTimeSelector from "../../components/FlightTimeSelector/FlightTimeSelector"; | ||
|
||
const Dashboard = () => { | ||
return ( | ||
<div> | ||
<FlightTimeSelector /> | ||
</div> | ||
); | ||
return <div>hello</div>; | ||
}; | ||
|
||
export default Dashboard; |
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 |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import FlightTimeSelector from "../../components/FlightTimeSelector/FlightTimeSelector"; | ||
|
||
const RequestFlight = () => { | ||
// Request flight tab | ||
console.log("RequestFlight"); | ||
|
||
return <div>RequestFlight</div>; | ||
return ( | ||
<div> | ||
<FlightTimeSelector /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RequestFlight; |
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