Skip to content

Commit 6bb84ce

Browse files
committed
fixup! test(teach): add desktop tests for all /education/ pages
1 parent 0347ed1 commit 6bb84ce

File tree

4 files changed

+70
-34
lines changed

4 files changed

+70
-34
lines changed

test/e2e/teach/courses.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
22
import { CoursesPage } from '../../page/teach/courses-page';
33
import { closeExternalBanners } from '../utils';
44
import { testSelector } from '../../utils';
5-
import { checkTeachCta, checkTeachMap, checkTeachSubnav } from './utils';
5+
import { checkTeachCta, checkTeachMap, checkTeachNav } from './utils';
66

77
test.describe('Courses page appearance and functionality', async () => {
88
test.beforeEach(async ({ page, context, baseURL }) => {
@@ -27,19 +27,19 @@ test.describe('Courses page appearance and functionality', async () => {
2727
});
2828

2929
test('Should have working navigation buttons', async ({ page }) => {
30-
await checkTeachSubnav(page, 'List of Courses');
30+
await checkTeachNav(page, 'List of Courses');
3131
});
3232

3333
test('Should have working tab navigation', async ({ page }) => {
3434
// Check if the tab list is visible
35-
const tabList = page.locator('.ktl-courses__tabs');
35+
const tabList = page.locator(testSelector('tab-list'));
3636
await expect(tabList).toBeVisible();
3737

3838
// Check if both tabs are present
39-
const tableViewTab = tabList.locator('button').filter({ hasText: 'Table view' });
39+
const tableViewTab = tabList.getByRole('tab', { name: 'Table view', exact: true });
4040
await expect(tableViewTab).toBeVisible();
4141

42-
const mapViewTab = tabList.locator('button').filter({ hasText: 'Map view' });
42+
const mapViewTab = tabList.getByRole('tab', { name: 'Map view', exact: true });
4343
await expect(mapViewTab).toBeVisible();
4444

4545
await expect(tableViewTab).toHaveAttribute('data-test', 'tab tab-selected');
@@ -71,7 +71,7 @@ test.describe('Courses page appearance and functionality', async () => {
7171

7272
test('Should display university list in table view', async ({ page }) => {
7373
// Make sure we're in a table view
74-
const tableViewTab = page.locator('button').filter({ hasText: 'Table view' });
74+
const tableViewTab = page.getByRole('button', { name: 'Table view' });
7575
await tableViewTab.click();
7676

7777
// Check if the course list is visible
@@ -94,7 +94,7 @@ test.describe('Courses page appearance and functionality', async () => {
9494

9595
test('Should display map with markers in map view', async ({ page }) => {
9696
// Switch to the map view
97-
const mapViewTab = page.locator('button').filter({ hasText: 'Map view' });
97+
const mapViewTab = page.getByRole('tab', { name: 'Map view' });
9898
await mapViewTab.click();
9999

100100
// Check if the map is visible

test/e2e/teach/education.spec.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
22
import { TeachPage } from '../../page/teach/education';
33
import { closeExternalBanners } from '../utils';
44
import { testSelector } from '../../utils';
5-
import { checkTeachCta, checkTeachMap, checkTeachSubnav, MAILTO_LINK, MATERIALS_LINK, SIGNUP_LINK } from './utils';
5+
import { checkTeachCta, checkTeachMap, checkTeachNav, MAILTO_LINK, MATERIALS_LINK, SIGNUP_LINK } from './utils';
66

77
test.describe('Education landing page content and interactions', async () => {
88
test.beforeEach(async ({ context, page, baseURL }) => {
@@ -27,14 +27,16 @@ test.describe('Education landing page content and interactions', async () => {
2727
});
2828

2929
test('Should have working navigation buttons', async ({ page }) => {
30-
await checkTeachSubnav(page, 'Overview');
30+
await checkTeachNav(page, 'Overview');
3131
});
3232

3333
test('Should display course materials download button', async ({ page }) => {
3434
const block = page.locator('.teach-launch-course__text');
3535

36-
const button = block.locator(`a[href="${MATERIALS_LINK}"]`);
36+
// Locate and verify the download button with the exact name match
37+
const button = block.getByRole('link', { name: 'Download all materials →', exact: true });
3738
await expect(button).toBeVisible();
39+
await expect(button).toHaveAttribute('href', MATERIALS_LINK);
3840

3941
expect(await block.screenshot()).toMatchSnapshot('launch-course-text.png');
4042
});
@@ -60,10 +62,18 @@ test.describe('Education landing page content and interactions', async () => {
6062
});
6163

6264
test('Should display buttons in top section', async ({ page }) => {
65+
// Get the top buttons block container
6366
const block = page.locator('.teach-top-buttons');
6467

65-
await expect(block.locator(`a[href="${SIGNUP_LINK}"]`)).toBeVisible();
66-
await expect(block.locator(`a[href="why-teach-kotlin.html"]`)).toBeVisible();
68+
// Check the "Join Educators Community" button visibility and link
69+
const join = block.getByRole('link', { name: 'Join Educators Сommunity', exact: true });
70+
await expect(join).toBeVisible();
71+
await expect(join).toHaveAttribute('href', SIGNUP_LINK);
72+
73+
// Check the "Why Teach Kotlin" button visibility and link
74+
const why = block.getByRole('link', { name: 'Why Teach Kotlin →', exact: true });
75+
await expect(why).toBeVisible();
76+
await expect(why).toHaveAttribute('href', 'why-teach-kotlin.html');
6777

6878
expect(await block.screenshot()).toMatchSnapshot('teach-top-mobile-buttons.png');
6979
});
@@ -110,12 +120,14 @@ test.describe('Education landing page content and interactions', async () => {
110120
await expect(bottom).toBeVisible();
111121

112122
// Check if the mailto button is visible and working
113-
const mailtoButton = bottom.locator(`a[href="${MAILTO_LINK}"]`);
123+
const mailtoButton = bottom.getByRole('link', { name: '[email protected].', exact: true });
114124
await expect(mailtoButton).toBeVisible();
125+
await expect(mailtoButton).toHaveAttribute('href', MAILTO_LINK);
115126

116127
// Check if the "All Universities" button is visible
117-
const allUniversitiesButton = bottom.locator('a[href="courses.html"]');
128+
const allUniversitiesButton = bottom.getByRole('link', { name: 'All universities', exact: true });
118129
await expect(allUniversitiesButton).toBeVisible();
130+
await expect(allUniversitiesButton).toHaveAttribute('href', 'courses.html');
119131
});
120132

121133
test('Should have comprehensive resource links section', async ({ page }) => {

test/e2e/teach/utils.ts

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect, Locator, Page } from '@playwright/test';
22

3-
export const SIGNUP_LINK = 'https://surveys.jetbrains.com/s3/kotlin-slack-signup-educators' as const;
43
export const MAILTO_LINK = 'mailto:[email protected]' as const;
4+
export const SIGNUP_LINK = 'https://surveys.jetbrains.com/s3/kotlin-slack-signup-educators' as const;
55
export const MATERIALS_LINK = 'https://drive.google.com/drive/folders/1nN3LuyEfmBaSDZpnb4VA9kDuLakmVXH1?usp=drive_link' as const;
66

77
const NAV_LINKS = [
@@ -10,18 +10,34 @@ const NAV_LINKS = [
1010
['List of Courses', '/education/courses.html']
1111
] as const;
1212

13-
export async function checkTeachSubnav(page: Page, selected: typeof NAV_LINKS[number][0]) {
14-
await expect(page.locator('.teach-sticky-menu > div > a[href="/education/"]')).toBeVisible();
15-
await expect(page.locator('.teach-sticky-menu > div > nav span').getByText(selected)).toBeVisible();
13+
export async function checkTeachNav(page: Page, selected: typeof NAV_LINKS[number][0]) {
14+
const navBar = page.locator('.teach-sticky-menu');
15+
16+
// Check section title to root of nav
17+
const sectionLink = navBar.getByRole('link', { name: 'Teach', exact: true });
18+
await expect(sectionLink).toBeVisible();
19+
await expect(sectionLink).toHaveAttribute('href', '/education/');
20+
21+
// Check the Join button
22+
const joinLink = navBar.getByRole('link', { name: 'Join Educators', exact: true });
23+
await expect(joinLink).toBeVisible();
24+
await expect(joinLink).toHaveAttribute('href', SIGNUP_LINK);
25+
26+
const subNav = navBar.getByRole('navigation');
1627

28+
// Check sub-nav link
1729
for (let [title, link] of NAV_LINKS) {
18-
if (title == selected) continue;
19-
await expect(page.locator(`.teach-sticky-menu > div > nav a[href="${link}"]`)).toBeVisible();
30+
if (title == selected) {
31+
await expect(subNav.getByRole('link', { name: title })).toHaveCount(0);
32+
await expect(subNav.getByText(title)).toBeVisible();
33+
continue;
34+
}
35+
36+
const subLink = subNav.getByRole('link', { name: title }).filter({ visible: true });
37+
await expect(subLink).toHaveAttribute('href', link);
2038
}
2139

22-
await expect(page.locator(`.teach-sticky-menu > div > a[href="${SIGNUP_LINK}"]`)).toBeVisible();
23-
24-
expect(await page.locator('.teach-sticky-menu').screenshot()).toMatchSnapshot('sticky-menu.png');
40+
expect(await navBar.screenshot()).toMatchSnapshot('sticky-menu.png');
2541
}
2642

2743
export async function checkTeachMap(page: Page, map: Locator) {
@@ -45,7 +61,7 @@ export async function checkTeachMap(page: Page, map: Locator) {
4561
});
4662

4763
// Check if at least one marker is visible
48-
let marker = markers.nth(36);
64+
let marker = markers.last();
4965
await expect(marker).toBeVisible();
5066
await expect(marker).not.toHaveClass('teach-map-marker teach-map-marker_active');
5167

@@ -59,19 +75,28 @@ export async function checkTeachMap(page: Page, map: Locator) {
5975
await page.mouse.up();
6076

6177
await expect(marker).toHaveClass('teach-map-marker teach-map-marker_active');
78+
6279
const tooltip = marker.locator('.teach-map-tooltip');
6380
await expect(tooltip).toBeVisible();
6481
}
6582

6683
export async function checkTeachCta({ page }) {
67-
// Look for the "Connect with us" section which contains the CTA buttons
84+
// Get the CTA wrapper element from the page
6885
const connectUs = page.locator('section [class*=ktl-cta-block-module_wrapper_]');
6986

70-
const title = connectUs.getByText('Connect with us');
87+
// Check if the "Connect with us" heading is visible
88+
const title = connectUs.getByRole('heading', { name: 'Connect with us', exact: true });
7189
await expect(title).toBeVisible();
7290

73-
await expect(connectUs.locator(`a[href="${SIGNUP_LINK}"]`)).toBeVisible();
74-
await expect(connectUs.locator(`a[href="${MAILTO_LINK}"]`)).toBeVisible();
91+
// Check if the Slack link is visible and has the correct href
92+
const slackLink = connectUs.getByRole('link', { name: 'Slack-channel →', exact: true });
93+
await expect(slackLink).toBeVisible();
94+
await expect(slackLink).toHaveAttribute('href', SIGNUP_LINK);
95+
96+
// Check if the email link is visible and has the correct mailto href
97+
const eduLink = connectUs.getByRole('link', { name: '[email protected]', exact: true });
98+
await expect(eduLink).toBeVisible();
99+
await expect(eduLink).toHaveAttribute('href', MAILTO_LINK);
75100

76101
expect(await connectUs.screenshot()).toMatchSnapshot('connect-us.png');
77-
}
102+
}

test/e2e/teach/why.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect, test } from '@playwright/test';
22
import { WhyTeachPage } from '../../page/teach/why-page';
33
import { closeExternalBanners } from '../utils';
4-
import { checkTeachCta, checkTeachSubnav } from './utils';
4+
import { checkTeachCta, checkTeachNav } from './utils';
55
import { testSelector } from '../../utils';
66

77
const LIST_OF_SECTION = [
@@ -36,13 +36,12 @@ test.describe('Why Teach Kotlin page appearance and functionality', async () =>
3636
await expect(mainContent).toBeVisible();
3737

3838
// Check if the page heading is correct
39-
const heading = page.locator('h1');
39+
const heading = page.getByRole('heading', { name: 'Why Teach Kotlin', exact: true });
4040
await expect(heading).toBeVisible();
41-
expect(await heading.textContent()).toBe('Why Teach Kotlin');
4241
});
4342

4443
test('Should have working navigation buttons', async ({ page }) => {
45-
await checkTeachSubnav(page, 'Why Teach Kotlin');
44+
await checkTeachNav(page, 'Why Teach Kotlin');
4645
});
4746

4847
test('Should display all sections with quotes correctly', async ({ page }) => {
@@ -242,4 +241,4 @@ test.describe('Why Teach Kotlin page appearance and functionality', async () =>
242241
});
243242

244243
test('Should have action buttons for educators', checkTeachCta);
245-
});
244+
});

0 commit comments

Comments
 (0)