Skip to content

Commit 3bab482

Browse files
committed
added description validation and tests
1 parent 45a41d1 commit 3bab482

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

site/src/pages/TemplateSettingsPage/TemplateSettingsForm.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ export const Language = {
2323
formAriaLabel: "Template settings form",
2424
selectEmoji: "Select emoji",
2525
ttlMaxError: "Please enter a limit that is less than or equal to 168 hours (7 days).",
26+
descriptionMaxError: "Please enter a description that is less than or equal to 128 characters.",
2627
}
2728

29+
const MAX_DESCRIPTION_CHAR_LIMIT = 128
30+
const MAX_TTL_DAYS = 7
31+
2832
export const validationSchema = Yup.object({
2933
name: nameValidator(Language.nameLabel),
30-
description: Yup.string(),
31-
max_ttl_ms: Yup.number().integer().min(0).max(168, Language.ttlMaxError),
34+
description: Yup.string().max(MAX_DESCRIPTION_CHAR_LIMIT, Language.descriptionMaxError),
35+
max_ttl_ms: Yup.number()
36+
.integer()
37+
.min(0)
38+
.max(24 * MAX_TTL_DAYS /* 7 days in hours */, Language.ttlMaxError),
3239
})
3340

3441
export interface TemplateSettingsForm {

site/src/pages/TemplateSettingsPage/TemplateSettingsPage.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,24 @@ describe("TemplateSettingsPage", () => {
111111
const validate = () => validationSchema.validateSync(values)
112112
expect(validate).toThrowError(FormLanguage.ttlMaxError)
113113
})
114+
115+
it("allows a description of 128 chars", () => {
116+
const values: UpdateTemplateMeta = {
117+
...validFormValues,
118+
description:
119+
"Nam quis nulla. Integer malesuada. In in enim a arcu imperdiet malesuada. Sed vel lectus. Donec odio urna, tempus molestie, port",
120+
}
121+
const validate = () => validationSchema.validateSync(values)
122+
expect(validate).not.toThrowError()
123+
})
124+
125+
it("disallows a description of 128 + 1 chars", () => {
126+
const values: UpdateTemplateMeta = {
127+
...validFormValues,
128+
description:
129+
"Nam quis nulla. Integer malesuada. In in enim a arcu imperdiet malesuada. Sed vel lectus. Donec odio urna, tempus molestie, port a",
130+
}
131+
const validate = () => validationSchema.validateSync(values)
132+
expect(validate).toThrowError(FormLanguage.descriptionMaxError)
133+
})
114134
})

0 commit comments

Comments
 (0)