Skip to content

Commit

Permalink
refactor: use a different approach to visually hide input elements (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenltnguyen authored Oct 11, 2023
1 parent 3ce08ba commit 2dcbda7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client/src/templates/Challenges/odin/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class ShowOdin extends Component<ShowOdinProps, ShowOdinState> {
<input
aria-label={t('aria.answer')}
checked={this.state.selectedOption === index}
className='video-quiz-input-hidden'
className='sr-only'
name='quiz'
onChange={this.handleOptionChange}
type='radio'
Expand Down
5 changes: 0 additions & 5 deletions client/src/templates/Challenges/video.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@
border-bottom: 4px solid var(--tertiary-background);
}

.video-quiz-input-hidden {
position: absolute;
left: -9999px;
}

.video-quiz-input-visible {
margin-inline-end: 15px;
position: relative;
Expand Down
48 changes: 48 additions & 0 deletions e2e/template-challenges-show.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { test, expect } from '@playwright/test';

import translations from '../client/i18n/locales/english/translations.json';

test.describe('Template Challenges Show', () => {
test.beforeEach(async ({ page }) => {
await page.goto(
'/learn/foundational-c-sharp-with-microsoft/write-your-first-code-using-c-sharp/write-your-first-c-sharp-code'
);
});

test.afterEach(async ({ page }) => {
await page.close();
});

test('should display a success dialog when the user submits the form, and they have completed the quiz and the assignments correctly', async ({
page
}) => {
// Tick the assignment box
await page.getByRole('checkbox').check();

// Find and click the third quiz option, which is the correct answer.
// Set `force: true` to bypass Playwright's check
// as the radio is visually hidden and the click event is intercepted by the `span` element.
const quizOptions = await page.getByRole('radio').all();
await quizOptions[2].check({ force: true });

await page
.getByRole('button', { name: translations.buttons['check-answer'] })
.click();

await expect(
page.getByText(translations.learn['assignment-not-complete'])
).not.toBeVisible();

await expect(
page.getByText(translations.learn['wrong-answer'])
).not.toBeVisible();

// There are two elements with the `dialog` role in the DOM.
// This appears to be semantically incorrect and should be resolved
// once we have migrated the component to use Dialog from the `ui-components` library.
expect(page.getByRole('dialog').all()).toBeTruthy();
await expect(
page.getByRole('button', { name: translations.buttons['go-to-next'] })
).toBeVisible();
});
});

0 comments on commit 2dcbda7

Please sign in to comment.