diff --git a/client/src/components/formHelpers/form-fields.tsx b/client/src/components/formHelpers/form-fields.tsx index 7a08171cdc0..c867043b5f2 100644 --- a/client/src/components/formHelpers/form-fields.tsx +++ b/client/src/components/formHelpers/form-fields.tsx @@ -92,7 +92,12 @@ function FormFields({ formFields, options }: FormFieldsProps): JSX.Element { const isURL = types[name] === 'url'; return ( - {label} + + {label} + {nullOrWarning( value as string, diff --git a/client/src/components/formHelpers/form.tsx b/client/src/components/formHelpers/form.tsx index 182b0ba800f..9d52b4592e6 100644 --- a/client/src/components/formHelpers/form.tsx +++ b/client/src/components/formHelpers/form.tsx @@ -107,6 +107,7 @@ export const StrictSolutionForm = ({ id={`dynamic-${id}`} onSubmit={handleSubmit as (e: FormEvent) => void} style={{ width: '100%' }} + data-playwright-test-label='form-helper-form' > { + test.beforeEach(async ({ page }) => { + await page.goto( + 'learn/front-end-development-libraries/front-end-development-libraries-projects/build-a-random-quote-machine' + ); + }); + + test('The form is visible and has only solution link input', async ({ + page + }) => { + // The solution form should be present and visible + const solutionForm = page.getByTestId('form-helper-form'); + await expect(solutionForm).toBeVisible(); + + // The form submit button should be disabled as the form is not filled + const solutionFormButton = solutionForm.getByRole('button', { + name: `${translations.learn['i-completed']}` + }); + await expect(solutionFormButton).toBeVisible(); + await expect(solutionFormButton).toBeDisabled(); + + const solutionLinkInputLabel = solutionForm.getByTestId( + 'solution-control-label' + ); + await expect(solutionLinkInputLabel).toBeVisible(); + await expect(solutionLinkInputLabel).toHaveText( + translations.learn['solution-link'] + ); + + const solutionLinkInput = solutionForm.getByTestId('solution-form-control'); + await expect(solutionLinkInput).toBeVisible(); + + const githubLinkInputLabel = solutionForm.getByTestId( + 'githubLink-control-label' + ); + await expect(githubLinkInputLabel).not.toBeVisible(); + + // The form submit button should be enabled as the form is now filled + await solutionLinkInput.fill('test-input'); + await expect(solutionFormButton).toBeEnabled(); + }); +}); + +test.describe('Test form with solution link and github link', () => { + test.beforeEach(async ({ page }) => { + await page.goto( + 'learn/quality-assurance/quality-assurance-projects/personal-library' + ); + }); + + test('The form is visible and has solution link and github link input', async ({ + page + }) => { + // The solution form should be present and visible + const solutionForm = page.getByTestId('form-helper-form'); + await expect(solutionForm).toBeVisible(); + + // The form submit button should be disabled as the form is not filled + const solutionFormButton = solutionForm.getByRole('button', { + name: `${translations.learn['i-completed']}` + }); + await expect(solutionFormButton).toBeVisible(); + await expect(solutionFormButton).toBeDisabled(); + + const solutionLinkInputLabel = solutionForm.getByTestId( + 'solution-control-label' + ); + await expect(solutionLinkInputLabel).toBeVisible(); + await expect(solutionLinkInputLabel).toHaveText( + translations.learn['solution-link'] + ); + + const solutionLinkInput = solutionForm.getByTestId('solution-form-control'); + await expect(solutionLinkInput).toBeVisible(); + + const githubLinkInputLabel = solutionForm.getByTestId( + 'githubLink-control-label' + ); + await expect(githubLinkInputLabel).toBeVisible(); + await expect(githubLinkInputLabel).toHaveText( + translations.learn['github-link'] + ); + + const githubLinkInput = solutionForm.getByTestId('githubLink-form-control'); + await expect(githubLinkInput).toBeVisible(); + + // The form submit button should be enabled as the form is now filled + await solutionLinkInput.fill('test-input'); + await expect(solutionFormButton).toBeEnabled(); + }); +});