Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenltnguyen committed May 3, 2024
1 parent 418ed3d commit 39435f8
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 43 deletions.
2 changes: 2 additions & 0 deletions e2e/completion-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ test.beforeEach(async ({ page }) => {
});

test.describe('Challenge Completion Modal Tests (Signed Out)', () => {
test.use({ storageState: { cookies: [], origins: [] } });

test('should render the modal correctly', async ({ page }) => {
await expect(page.getByRole('heading')).toBeVisible();
await expect(page.getByRole('button', { name: 'close' })).toBeVisible();
Expand Down
4 changes: 3 additions & 1 deletion e2e/exam-show-non-qualified.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ test.beforeEach(async ({ page }) => {
await page.goto(examUrl);
});

test.describe('Exam Show E2E Test Suite for non-qualified user', () => {
test.describe('Exam Show E2E Test Suite for unauthenticated user', () => {
test.use({ storageState: { cookies: [], origins: [] } });

test('The page renders with correct title', async ({ page }) => {
await expect(page).toHaveTitle(
'Foundational C# with Microsoft Certification Exam: Foundational C# with Microsoft Certification Exam | freeCodeCamp.org'
Expand Down
2 changes: 2 additions & 0 deletions e2e/intro.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ test.describe('Intro Component E2E Test Suite with Signed In User', () => {
});

test.describe('Intro Component E2E Test Suite with Signed Out User', () => {
test.use({ storageState: { cookies: [], origins: [] } });

test('Verifies the Correct Intro component heading', async ({ page }) => {
await expect(page.getByText(translations.learn.heading)).toBeVisible();
});
Expand Down
2 changes: 2 additions & 0 deletions e2e/link-ms-user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ test.beforeEach(async ({ page }) => {
});

test.describe('Link MS user component (signed-out user)', () => {
test.use({ storageState: { cookies: [], origins: [] } });

test('should display the page content with a signin CTA', async ({
page
}) => {
Expand Down
89 changes: 54 additions & 35 deletions e2e/ms-trophy-show.spec.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,69 @@
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

const verifyTrophyButtonText = translations.buttons['verify-trophy'];
const askForHelpButtonText = translations.buttons['ask-for-help'];

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

test('the page should render with correct title and description', async ({
page
}) => {
await expect(page).toHaveTitle(
'Write Your First Code Using C# - Trophy - Write Your First Code Using C# | Learn | freeCodeCamp.org'
);
const title = page.getByTestId('challenge-title');
await expect(title).toBeVisible();
await expect(title).toContainText('Trophy - Write Your First Code Using C#');
test.describe('MS Trophy page if the user is signed in', () => {
test('should render the content correctly', async ({ page }) => {
await expect(page).toHaveTitle(
'Write Your First Code Using C# - Trophy - Write Your First Code Using C# | Learn | freeCodeCamp.org'
);
await expect(
page.getByRole('heading', {
level: 1,
name: 'Trophy - Write Your First Code Using C#'
})
).toBeVisible();

const description = page.getByTestId('challenge-description');
await expect(description).toBeVisible();
});
await expect(
page.getByText(
'Now that you\'ve completed all of the "Write Your First Code Using C#" challenges, you should have earned the trophy for it on the Microsoft Learn platform.'
)
).toBeVisible();

test('Correct Verify Trophy button', async ({ page }) => {
const askHelpButton = page.getByRole('button', {
name: verifyTrophyButtonText
await expect(page.getByRole('button', { name: 'Unlink' })).toBeVisible();
await expect(
page.getByRole('button', { name: 'Verify Trophy' })
).toBeVisible();
await expect(
page.getByRole('button', { name: 'Ask for Help' })
).toBeVisible();
});
await expect(askHelpButton).toBeVisible();
await expect(askHelpButton).toHaveText(verifyTrophyButtonText);
await expect(askHelpButton).toBeDisabled();
});

test('Correct Ask for help button', async ({ page }) => {
const checkAnswerButton = page.getByRole('button', {
name: askForHelpButtonText
test.describe('MS Trophy page if the user is not signed in', () => {
test.use({ storageState: { cookies: [], origins: [] } });

test('should render the content correctly', async ({ page }) => {
await expect(page).toHaveTitle(
'Write Your First Code Using C# - Trophy - Write Your First Code Using C# | Learn | freeCodeCamp.org'
);
await expect(
page.getByRole('heading', {
level: 1,
name: 'Trophy - Write Your First Code Using C#'
})
).toBeVisible();

await expect(
page.getByText(
'Now that you\'ve completed all of the "Write Your First Code Using C#" challenges, you should have earned the trophy for it on the Microsoft Learn platform.'
)
).toBeVisible();

// There are two "Sign in" buttons on the page: one in the nav, and one in the page body
await expect(page.getByRole('link', { name: 'Sign in' })).toHaveCount(2);
await expect(
page.getByRole('button', { name: 'Verify Trophy' })
).toBeVisible();
await expect(
page.getByRole('button', { name: 'Verify Trophy' })
).toBeDisabled();
await expect(
page.getByRole('button', { name: 'Ask for Help' })
).toBeVisible();
});
await expect(checkAnswerButton).toBeVisible();
await expect(checkAnswerButton).toContainText(askForHelpButtonText);

await checkAnswerButton.click();
await expect(
page.getByRole('heading', {
name: translations.buttons['ask-for-help'],
exact: true
})
).toBeVisible();
});
2 changes: 1 addition & 1 deletion e2e/reset-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ test('User can reset classic challenge', async ({ page, isMobile }) => {
).not.toBeVisible();
await expect(
page.getByLabel(translations.icons.passed).locator('circle')
).not.toBeVisible();
).toBeVisible();
await expect(
page.getByText(translations.learn['tests-completed'])
).not.toBeVisible();
Expand Down
15 changes: 9 additions & 6 deletions e2e/show-certificate-else.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { test, expect, type Page } from '@playwright/test';
import { test, expect } from '@playwright/test';

test.describe('Show certification else', () => {
let page: Page;
test.use({ storageState: { cookies: [], origins: [] } });

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
test.beforeEach(async ({ page }) => {
await page.goto('/certification/certifieduser/responsive-web-design');
});

test('while viewing someone else, should display the certificate information', async () => {
test('while viewing someone else, should display the certificate information', async ({
page
}) => {
await expect(page.getByTestId('successful-completion')).toBeVisible();
await expect(page.getByTestId('certification-title')).toBeVisible();
await expect(page.getByTestId('issue-date')).toContainText(
'Developer Certification on August 3, 2018'
);
});

test('while viewing someone else, should not render a LinkedIn button and Twitter button', async () => {
test('while viewing someone else, should not render a LinkedIn button and Twitter button', async ({
page
}) => {
await expect(page.getByTestId('linkedin-share-btn')).toBeHidden();
await expect(page.getByTestId('twitter-share-btn')).toBeHidden();
});
Expand Down

0 comments on commit 39435f8

Please sign in to comment.