Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Template settings fixes/kira pilot#3668

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Kira-Pilot merged 13 commits intomainfromtemplate-settings-fixes/kira-pilot
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
added ttl tests
  • Loading branch information
@Kira-Pilot
Kira-Pilot committedAug 24, 2022
commit45a41d1a2e88fd203e23c400bb0640de1c690b7a
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,7 +161,7 @@ describe("validationSchema", () => {
ttl: 24 * 7 + 1,
}
const validate = () => validationSchema.validateSync(values)
expect(validate).toThrowError("ttl must be less than or equal to 168")
expect(validate).toThrowError(Language.errorTtlMax)
})
})

Expand Down
12 changes: 10 additions & 2 deletionssite/src/pages/TemplateSettingsPage/TemplateSettingsForm.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,11 +54,18 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
initialValues: {
name: template.name,
description: template.description,
max_ttl_ms: template.max_ttl_ms,
// on display, convert from ms => hours
max_ttl_ms: template.max_ttl_ms / 3600000,
icon: template.icon,
},
validationSchema,
onSubmit,
onSubmit: (formData) => {
// on submit, convert from hours => ms
onSubmit({
...formData,
max_ttl_ms: formData.max_ttl_ms ? formData.max_ttl_ms * 3600000 : undefined,
})
},
initialTouched,
})
const getFieldHelpers = getFormHelpersWithError<UpdateTemplateMeta>(form, error)
Expand DownExpand Up@@ -152,6 +159,7 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
inputProps={{ min: 0, step: 1 }}
label={Language.maxTtlLabel}
variant="outlined"
type="number"
/>
</Stack>

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,12 +19,11 @@ const renderTemplateSettingsPage = async () => {
return renderResult
}

const validFormValues: UpdateTemplateMeta = {
name: "A name",
const validFormValues = {
name: "Name",
description: "A description",
icon: "A string",
max_ttl_ms: 24,
min_autostart_interval_ms: 24,
max_ttl_ms: 1,
}

const fillAndSubmitForm = async ({
Expand DownExpand Up@@ -63,46 +62,33 @@ describe("TemplateSettingsPage", () => {
it("succeeds", async () => {
await renderTemplateSettingsPage()

const newTemplateSettings = {
name: "edited-template-name",
description: "Edited description",
max_ttl_ms: 4000,
icon: "/icon/code.svg",
}
jest.spyOn(API, "updateTemplateMeta").mockResolvedValueOnce({
...MockTemplate,
...newTemplateSettings,
...validFormValues,
})
await fillAndSubmitForm(newTemplateSettings)
await fillAndSubmitForm(validFormValues)

await waitFor(() => expect(API.updateTemplateMeta).toBeCalledTimes(1))
})

test("ttl is converted to and from hours", async () => {
await renderTemplateSettingsPage()

const newTemplateSettings = {
name: "edited-template-name",
description: "Edited description",
max_ttl_ms: 1,
icon: "/icon/code.svg",
}

jest.spyOn(API, "updateTemplateMeta").mockResolvedValueOnce({
...MockTemplate,
...newTemplateSettings,
...validFormValues,
})

await fillAndSubmitForm(newTemplateSettings)
expect(screen.getByDisplayValue(1)).toBeInTheDocument()
await fillAndSubmitForm(validFormValues)
expect(screen.getByDisplayValue(1)).toBeInTheDocument() // the max_ttl_ms
await waitFor(() => expect(API.updateTemplateMeta).toBeCalledTimes(1))

await waitFor(() =>
expect(API.updateTemplateMeta).toBeCalledWith(
"test-template",
expect.objectContaining({
...newTemplateSettings,
max_ttl_ms: 3600000,
...validFormValues,
max_ttl_ms: 3600000, // the max_ttl_ms to ms
}),
),
)
Expand All@@ -123,6 +109,6 @@ describe("TemplateSettingsPage", () => {
max_ttl_ms: 24 * 7 + 1,
}
const validate = () => validationSchema.validateSync(values)
expect(validate).toThrowError("ttl must be less than or equal to 168")
expect(validate).toThrowError(FormLanguage.ttlMaxError)
})
})

[8]ページ先頭

©2009-2025 Movatter.jp