Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add same touched behavior as inputs for text editor #3274

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions site/gatsby-site/playwright/e2e-full/submit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,40 @@ test.describe('The Submit form', () => {
await expect(page.locator('text=Please review. Some data is missing.')).toBeVisible();
});

test('Should display an error messages for each missing field on step 1', async ({ page }) => {

await page.goto(url);

const valuesStep1 = {
url: '',
title: '',
authors: '',
date_published: '',
incident_date: '',
};

for (const key in valuesStep1) {
await page.locator(`input[name="${key}"]`).fill(valuesStep1[key]);
}

await setEditorText(
page,
''
);

await expect(page.locator('.form-has-errors')).toBeVisible();

await expect(page.locator('text=*URL required')).toBeVisible();

await expect(page.locator('text=*Title is required')).toBeVisible();

await expect(page.locator('text=*Author is required. Anonymous or the publication can be entered.')).toBeVisible();

await expect(page.locator('text=*Text is required')).toBeVisible();

await expect(page.locator('text=*Date published is required')).toBeVisible();
});

test('Should submit a new report response', async ({ page }) => {
const values = {
url: 'https://incidentdatabase.ai',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ const StepOne = (props) => {
.nullable(),
authors: yup
.string()
.required('*Author is required. Anonymous or the publication can be entered.')
.min(3, '*Authors must have at least 3 characters')
.max(200, "*Authors can't be longer than 200 characters")
.required('*Author is required. Anonymous or the publication can be entered.')
.nullable(),
date_published: yup
.string()
.matches(dateRegExp, '*Date is not valid, must be `YYYY-MM-DD`')
.test(isPastDate)
.required('*Date published is required')
.test(isPastDate)
.nullable(),
date_downloaded: yup
.string()
.matches(dateRegExp, '*Date is not valid, must be `YYYY-MM-DD`')
.test(isPastDate)
.required('*Date downloaded required')
.test(isPastDate)
.nullable(),
url: yup
.string()
Expand Down Expand Up @@ -333,6 +333,7 @@ const FormDetails = ({
position: 'relative',
...styles,
}}
onBlur={() => setFieldTouched('text', true)}
>
{touched['text'] && errors['text'] && (
<div
Expand Down
4 changes: 4 additions & 0 deletions site/gatsby-site/src/components/forms/Tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function Tags({
className,
allowNew = true,
stayOpen = false,
onBlur,
}) {
const [open, setOpen] = useState(false);

Expand Down Expand Up @@ -44,6 +45,9 @@ export default function Tags({
commitTag(e.target.value);
}
setOpen(false);
if (onBlur) {
onBlur();
}
}}
multiple
open={open && stayOpen ? true : undefined}
Expand Down
1 change: 1 addition & 0 deletions site/gatsby-site/src/components/forms/TagsControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const TagsControl = ({
handleChange(value);
}
}}
onBlur={() => setTouched(true)}
{...{
name,
disabled,
Expand Down
Loading