test(e2e): exam results (#51812)
parent
417e5580de
commit
27874a4d53
|
@ -58,29 +58,37 @@ ${t('learn.exam.time', { t: formatSecondsToTime(examTimeInSeconds) })}
|
|||
// TODO: Add share button
|
||||
return (
|
||||
<div className='exam-results-wrapper'>
|
||||
<div className='exam-results-header'>
|
||||
<div
|
||||
className='exam-results-header'
|
||||
data-playwright-test-label='exam-results-header'
|
||||
>
|
||||
{t('learn.exam.results-header', { title })}
|
||||
</div>
|
||||
<hr />
|
||||
<Spacer size='medium' />
|
||||
|
||||
<div className='exam-results-message'>{examResultsMessage}</div>
|
||||
<div
|
||||
className='exam-results-message'
|
||||
data-playwright-test-label='exam-results-message'
|
||||
>
|
||||
{examResultsMessage}
|
||||
</div>
|
||||
<Spacer size='medium' />
|
||||
<div className='exam-results'>
|
||||
<div>
|
||||
<div data-playwright-test-label='exam-results-question-results'>
|
||||
{t('learn.exam.question-results', {
|
||||
n: numberOfCorrectAnswers,
|
||||
q: numberOfQuestionsInExam
|
||||
})}
|
||||
</div>
|
||||
<div>|</div>
|
||||
<div>
|
||||
<div data-playwright-test-label='exam-results-percent-results'>
|
||||
{t('learn.exam.percent-results', {
|
||||
p: percentCorrect
|
||||
})}
|
||||
</div>
|
||||
<div>|</div>
|
||||
<div>
|
||||
<div data-playwright-test-label='exam-time'>
|
||||
{t('learn.exam.time', { t: formatSecondsToTime(examTimeInSeconds) })}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -91,6 +99,7 @@ ${t('learn.exam.time', { t: formatSecondsToTime(examTimeInSeconds) })}
|
|||
block={true}
|
||||
bsStyle='primary'
|
||||
className='btn-invert'
|
||||
data-playwright-test-label='download-exam-results'
|
||||
download={`${dashedName}.txt`}
|
||||
href={downloadURL}
|
||||
>
|
||||
|
@ -100,6 +109,7 @@ ${t('learn.exam.time', { t: formatSecondsToTime(examTimeInSeconds) })}
|
|||
block={true}
|
||||
bsStyle='primary'
|
||||
data-cy='exit-exam'
|
||||
data-playwright-test-label='exit-exam'
|
||||
onClick={exitExam}
|
||||
>
|
||||
{t('buttons.exit')}
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
import * as fs from 'fs';
|
||||
import { test, expect } from '@playwright/test';
|
||||
import translations from '../client/i18n/locales/english/translations.json';
|
||||
import intro from '../client/i18n/locales/english/intro.json';
|
||||
|
||||
test.use({ storageState: 'playwright/.auth/certified-user.json' });
|
||||
|
||||
const examUrl =
|
||||
'/learn/foundational-c-sharp-with-microsoft/foundational-c-sharp-with-microsoft-certification-exam/foundational-c-sharp-with-microsoft-certification-exam';
|
||||
|
||||
test.describe('Exam Results E2E Test Suite', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto(examUrl);
|
||||
await page
|
||||
.getByRole('button', {
|
||||
name: translations.buttons['click-start-exam']
|
||||
})
|
||||
.click();
|
||||
const QUESTION_COUNT = 5;
|
||||
for (let i = 0; i < QUESTION_COUNT; i++) {
|
||||
await page.getByRole('radio').first().check({ force: true });
|
||||
|
||||
if (i < QUESTION_COUNT - 1) {
|
||||
await page
|
||||
.getByRole('button', {
|
||||
name: translations.buttons['next-question']
|
||||
})
|
||||
.click();
|
||||
} else {
|
||||
await page
|
||||
.getByRole('button', {
|
||||
name: translations.buttons['finish-exam']
|
||||
})
|
||||
.click();
|
||||
await page
|
||||
.getByRole('button', { name: translations.learn.exam['finish-yes'] })
|
||||
.click();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('Verifies the Correct Rendering of the Exam results', async ({
|
||||
page,
|
||||
browserName
|
||||
}) => {
|
||||
test.skip(browserName === 'webkit', 'It is failing on webkit');
|
||||
await expect(
|
||||
page
|
||||
.locator('div.exam-results-wrapper')
|
||||
.getByText(
|
||||
intro['foundational-c-sharp-with-microsoft'].blocks[
|
||||
'foundational-c-sharp-with-microsoft-certification-exam'
|
||||
].title
|
||||
)
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page
|
||||
.locator('div.exam-results-wrapper')
|
||||
.getByText(translations.learn.exam['not-passed-message'])
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page
|
||||
.locator('div.exam-results-wrapper')
|
||||
.getByTestId('exam-results-question-results')
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.locator('div.exam-results-wrapper').getByText(/\d% correct/)
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.locator('div.exam-results-wrapper').getByText(/Time: \d:\d/)
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page
|
||||
.locator('div.exam-results-wrapper')
|
||||
.getByTestId('download-exam-results')
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page
|
||||
.locator('div.exam-results-wrapper')
|
||||
.getByRole('button', { name: translations.buttons.exit })
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
test('Exam Results when the User clicks on Exit button', async ({
|
||||
page,
|
||||
browserName
|
||||
}) => {
|
||||
test.skip(browserName === 'webkit', 'It is failing on webkit');
|
||||
await page
|
||||
.locator('div.exam-results-wrapper')
|
||||
.getByRole('button', { name: translations.buttons.exit })
|
||||
.click();
|
||||
await expect(
|
||||
page
|
||||
.locator('div.exam-results-wrapper')
|
||||
.getByText(
|
||||
intro['foundational-c-sharp-with-microsoft'].blocks[
|
||||
'foundational-c-sharp-with-microsoft-certification-exam'
|
||||
].title
|
||||
)
|
||||
).not.toBeVisible();
|
||||
await expect(page).not.toHaveURL(examUrl);
|
||||
});
|
||||
|
||||
test.describe('Exam Results E2E Test Suite', () => {
|
||||
test('Exam Results When the User clicks on Download button', async ({
|
||||
page,
|
||||
browserName
|
||||
}) => {
|
||||
test.skip(browserName === 'webkit', 'It is failing on webkit');
|
||||
const [download] = await Promise.all([
|
||||
page.waitForEvent('download'),
|
||||
page
|
||||
.locator('div.exam-results-wrapper')
|
||||
.getByTestId('download-exam-results')
|
||||
.click()
|
||||
]);
|
||||
const suggestedFileName = download.suggestedFilename();
|
||||
await download.saveAs(suggestedFileName);
|
||||
expect(fs.existsSync(suggestedFileName)).toBeTruthy();
|
||||
await download.delete();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue