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 909b66e
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 81 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
104 changes: 66 additions & 38 deletions e2e/learn.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import words from '../client/i18n/locales/english/motivation.json';

const superBlocks = [
Expand All @@ -22,49 +21,69 @@ const superBlocks = [
'Project Euler',
'Rosetta Code',
'Legacy Responsive Web Design Challenges',
'JavaScript Algorithms and Data Structures',
'Legacy JavaScript Algorithms and Data Structures',
'Legacy Python for Everybody'
];

test('the page should render correctly', async ({ page }) => {
await page.goto('/learn');
await expect(page).toHaveTitle(
'Learn to Code — For Free — Coding Courses for Busy People'
);

const header = page.getByTestId('learn-heading');
await expect(header).toBeVisible();
await expect(header).toContainText(translations.learn.heading);

// Advice for new learners
const learnReadThisSection = page.getByTestId('learn-read-this-section');
await expect(learnReadThisSection).toBeVisible();

const learnReadThisSectionHeading = page.getByTestId(
'learn-read-this-heading'
);
await expect(learnReadThisSectionHeading).toBeVisible();

const learnReadThisSectionParagraphs = page.getByTestId('learn-read-this-p');
await expect(learnReadThisSectionParagraphs).toHaveCount(10);

for (const paragraph of await learnReadThisSectionParagraphs.all()) {
await expect(paragraph).toBeVisible();
}
// certifications
const curriculumBtns = page.getByTestId('curriculum-map-button');
await expect(curriculumBtns).toHaveCount(superBlocks.length);
for (let i = 0; i < superBlocks.length; i++) {
const btn = curriculumBtns.nth(i);
await expect(btn).toContainText(superBlocks[i]);
}
test.describe('Learn page (unauthenticated user)', () => {
test.use({ storageState: { cookies: [], origins: [] } });

test('the page should render correctly', async ({ page }) => {
await page.goto('/learn');
await expect(page).toHaveTitle(
'Learn to Code — For Free — Coding Courses for Busy People'
);

await expect(
page.getByRole('heading', {
level: 1,
name: "Welcome to freeCodeCamp's curriculum."
})
).toBeVisible();

// Advice for new learners
const learnReadThisSection = page.getByTestId('learn-read-this-section');
await expect(learnReadThisSection).toBeVisible();

const learnReadThisSectionHeading = page.getByTestId(
'learn-read-this-heading'
);
await expect(learnReadThisSectionHeading).toBeVisible();

const learnReadThisSectionParagraphs =
page.getByTestId('learn-read-this-p');
await expect(learnReadThisSectionParagraphs).toHaveCount(10);

for (const paragraph of await learnReadThisSectionParagraphs.all()) {
await expect(paragraph).toBeVisible();
}

// certifications
const certifications = page.getByTestId('curriculum-map-button');
await expect(certifications).toHaveCount(superBlocks.length);

for (let i = 0; i < superBlocks.length; i++) {
const btn = certifications.nth(i);
await expect(btn).toContainText(superBlocks[i]);
}
});
});

test.describe('Learn (authenticated user)', () => {
test('the page shows a random quote for an authenticated user', async ({
page
}) => {
test.describe('Learn page (authenticated user)', () => {
test('the page should render correctly', async ({ page }) => {
await page.goto('/learn');
await expect(page).toHaveTitle(
'Learn to Code — For Free — Coding Courses for Busy People'
);

await expect(
page.getByRole('heading', {
level: 1,
name: 'Welcome back, Full Stack User.'
})
).toBeVisible();

// Random quote
const shownQuote = await page.getByTestId('random-quote').textContent();

const shownAuthorText = await page
Expand All @@ -78,5 +97,14 @@ test.describe('Learn (authenticated user)', () => {

expect(allMotivationalQuotes).toContain(shownQuote);
expect(allAuthors).toContain(shownAuthor);

// Certifications
const certifications = page.getByTestId('curriculum-map-button');
await expect(certifications).toHaveCount(superBlocks.length);

for (let i = 0; i < superBlocks.length; i++) {
const btn = certifications.nth(i);
await expect(btn).toContainText(superBlocks[i]);
}
});
});
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 909b66e

Please sign in to comment.