-
Notifications
You must be signed in to change notification settings - Fork 17
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 #1019 from syucream/fix/test-with-initial-values
Improve some FE tests
- Loading branch information
Showing
11 changed files
with
372 additions
and
80 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
80 changes: 80 additions & 0 deletions
80
frontend/src/components/entry/entryForm/DateAttributeValueField.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,80 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import { EntryAttributeTypeTypeEnum } from "@dmm-com/airone-apiclient-typescript-fetch"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { act, screen, render, renderHook } from "@testing-library/react"; | ||
import React from "react"; | ||
import { useForm } from "react-hook-form"; | ||
|
||
import { DateAttributeValueField } from "./DateAttributeValueField"; | ||
import { schema, Schema } from "./EntryFormSchema"; | ||
|
||
import { TestWrapper } from "TestWrapper"; | ||
|
||
import "@testing-library/jest-dom"; | ||
|
||
describe("DateAttributeValueField", () => { | ||
const defaultValues: Schema = { | ||
name: "entry", | ||
schema: { | ||
id: 1, | ||
name: "entity", | ||
}, | ||
attrs: { | ||
"0": { | ||
type: EntryAttributeTypeTypeEnum.DATE, | ||
index: 0, | ||
isMandatory: false, | ||
schema: { | ||
id: 1, | ||
name: "date", | ||
}, | ||
value: { | ||
asString: "2020-01-01", | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
test("should provide date value editor", () => { | ||
const { | ||
result: { | ||
current: { control, getValues, setValue }, | ||
}, | ||
} = renderHook(() => | ||
useForm<Schema>({ | ||
resolver: zodResolver(schema), | ||
mode: "onBlur", | ||
defaultValues, | ||
}) | ||
); | ||
|
||
render( | ||
<DateAttributeValueField | ||
attrId={0} | ||
control={control} | ||
setValue={setValue} | ||
/>, | ||
{ | ||
wrapper: TestWrapper, | ||
} | ||
); | ||
|
||
expect(screen.getByRole("textbox")).toHaveValue("2020/01/01"); | ||
expect(getValues("attrs.0.value.asString")).toEqual("2020-01-01"); | ||
|
||
// Open the date picker | ||
act(() => { | ||
screen.getByRole("button").click(); | ||
}); | ||
// Select 2020-01-02 | ||
act(() => { | ||
screen.getByRole("gridcell", { name: "2" }).click(); | ||
}); | ||
|
||
expect(screen.getByRole("textbox")).toHaveValue("2020/01/02"); | ||
expect(getValues("attrs.0.value.asString")).toEqual("2020-1-2"); | ||
}); | ||
}); |
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.