-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
3 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...arsky/clientapp/src/components/organisms/modal-geo/internal/update-button-active.spec.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,63 @@ | ||
import { fireEvent, render, waitFor } from "@testing-library/react"; | ||
import localization from "../../../../localization/localization.json"; | ||
import { Language, SupportedLanguages } from "../../../../shared/language"; | ||
import { ILatLong } from "../modal-geo"; | ||
import { UpdateButtonActive } from "./update-button-active"; | ||
import { UpdateButtonWrapper } from "./update-button-wrapper"; | ||
import { UpdateGeoLocation } from "./update-geo-location"; | ||
|
||
jest.mock("./update-geo-location"); | ||
|
||
describe("UpdateButtonActive", () => { | ||
const parentDirectory = "parentDirectory"; | ||
const selectedSubPath = "selectedSubPath"; | ||
const location: ILatLong = { latitude: 0, longitude: 0 }; | ||
const setError = jest.fn(); | ||
const setIsLoading = jest.fn(); | ||
const propsCollections = true; | ||
const handleExit = jest.fn(); | ||
const language = new Language(SupportedLanguages.en); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("[UpdateButtonActive] calls UpdateGeoLocation when clicked and updates location", async () => { | ||
(UpdateGeoLocation as jest.Mock).mockResolvedValueOnce({} as any); | ||
|
||
const { getByTestId } = render( | ||
<UpdateButtonActive | ||
handleExit={handleExit} | ||
parentDirectory={parentDirectory} | ||
location={location} | ||
language={language} | ||
selectedSubPath={selectedSubPath} | ||
setError={setError} | ||
setIsLoading={setIsLoading} | ||
propsCollections={propsCollections} | ||
/> | ||
); | ||
const button = getByTestId("update-geo-location"); | ||
fireEvent.click(button); | ||
await waitFor(() => expect(UpdateGeoLocation).toHaveBeenCalledTimes(1)); | ||
expect(handleExit).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("[UpdateButtonActive] enables button when location is updated", () => { | ||
const { getByText } = render( | ||
<UpdateButtonWrapper | ||
handleExit={handleExit} | ||
isLocationUpdated={true} | ||
parentDirectory={parentDirectory} | ||
location={location} | ||
selectedSubPath={selectedSubPath} | ||
setError={setError} | ||
setIsLoading={setIsLoading} | ||
propsCollections={propsCollections} | ||
/> | ||
); | ||
const button = getByText(language.key(localization.MessageAddLocation)) as HTMLButtonElement; | ||
|
||
expect(button.disabled).toBe(false); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
...sky/clientapp/src/components/organisms/modal-geo/internal/update-button-disabled.spec.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,22 @@ | ||
import { render } from "@testing-library/react"; | ||
import localization from "../../../../localization/localization.json"; | ||
import { Language, SupportedLanguages } from "../../../../shared/language"; | ||
import { ILatLong } from "../modal-geo"; | ||
import { UpdateButtonDisabled } from "./update-button-disabled"; | ||
|
||
describe("UpdateButtonActive", () => { | ||
const location: ILatLong = { latitude: 0, longitude: 0 }; | ||
const language = new Language(SupportedLanguages.en); | ||
|
||
it("[disabledBtn] disables button when location is not updated", () => { | ||
const { getByText } = render( | ||
<UpdateButtonDisabled | ||
language={language} | ||
latitude={location.latitude} | ||
longitude={location.longitude} | ||
/> | ||
); | ||
const button = getByText(language.key(localization.MessageAddLocation)) as HTMLButtonElement; | ||
expect(button.disabled).toBe(true); | ||
}); | ||
}); |
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