Skip to content

Commit 8ab2810

Browse files
committed
Tests: Added test for header
1 parent cec8411 commit 8ab2810

File tree

5 files changed

+63
-19
lines changed

5 files changed

+63
-19
lines changed

layouts/partials/header.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</label>
1919
</div>
2020

21-
<div class="header__product-selector">
21+
<div class="header__product-selector" data-testid="header__product-selector">
2222
{{ $nginxProducts := slice
2323
(dict "title" "NGINX One Console" "url" "/nginx-one" "type" "nginx-one")
2424
(dict "title" "NGINX Plus" "url" "/nginx" "type" "nginx-one")
@@ -43,7 +43,7 @@
4343
{{ $productIdentifier := index ((split $relPermalink "/")) 1 }}
4444
{{ $productName := index $productMap $productIdentifier | default "Product Documentation" }}
4545

46-
<button class="product-selector__button" id="product-selector-button">
46+
<button class="product-selector__button" id="product-selector-button" data-testid="product-selector__button">
4747
{{/* product name and selector */}}
4848
<span class="product-name">{{ $productName }}</span>
4949
<span class="product-selector-button-icon">
@@ -52,7 +52,7 @@
5252
</svg>
5353
</span>
5454
</button>
55-
<div class="product-selector" id="product-selector">
55+
<div class="product-selector" id="product-selector" data-testid="product-selector">
5656
{{ $groupedProducts := dict
5757
"nginx-one" (where $nginxProducts "type" "nginx-one")
5858
"nginx-app-protect" (where $nginxProducts "type" "nginx-app-protect")
@@ -63,7 +63,7 @@
6363
{{ range $orderedKeys }}
6464
{{ $type := . }}
6565
{{ $products := index $groupedProducts $type }}
66-
<div class="product-selector-content" id="product-selector-content">
66+
<div class="product-selector-content" id="product-selector-content" data-testid="product-selector-content">
6767
<p>{{ $type | humanize | title | upper }}</p>
6868
<ul>
6969
{{ range $products }}
@@ -78,20 +78,20 @@
7878
</div>
7979

8080
{{ if ( not ( in .Site.Params.buildtype "package" ) ) }}
81-
<div class="header__search">
81+
<div class="header__search" data-testid="header__search">
8282
<!-- Standalone search box. -->
8383
{{ partial "coveo-atomic-search.html" }}
8484
</div>
8585
{{ end }}
8686

87-
<div class="header__f5sites">
87+
<div class="header__f5sites" data-testid="header__f5sites">
8888
{{ $f5Sites := slice
8989
(dict "title" "DevCentral" "url" "https://community.f5.com/" "description" "Connect & learn in our hosted community")
9090
(dict "title" "MyF5" "url" "https://my.f5.com/" "description" "Your key to everything F5, including support, registration keys, and subscriptions")
9191
(dict "title" "NGINX" "url" "https://nginx.org/" "description" "Learn more about NGINX Open Source and read the community blog")
9292
}}
9393

94-
<button id="navbar-sites-button" class="header__f5sites__button">
94+
<button id="navbar-sites-button" class="header__f5sites__button" data-testid="header__f5sites__button">
9595
<div class="header__f5sites__logo">
9696
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000">
9797
<title>f5-logo-black</title>
@@ -115,7 +115,7 @@
115115
</svg>
116116
</div>
117117
</button>
118-
<div class="dropdown-content" id="dropdown-content">
118+
<div class="dropdown-content" id="dropdown-content" data-testid="header__f5sites-content">
119119
<ul>
120120
{{ range $f5Sites }}
121121
<li>

tests/src/header-smoke.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Smoke test for header', () => {
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('/');
6+
});
7+
8+
test('should test header renders', async ({ page }) => {
9+
await expect(
10+
await page.locator('data-testid=header__product-selector').count()
11+
).toBeTruthy();
12+
await expect(
13+
await page.locator('data-testid=header__search').count()
14+
).toBeTruthy();
15+
await expect(
16+
await page.locator('data-testid=header__f5sites').count()
17+
).toBeTruthy();
18+
});
19+
20+
test('should test product selector renders', async ({ page }) => {
21+
// Check it renders
22+
const productSelectorButton = await page.locator(
23+
'data-testid=product-selector__button'
24+
);
25+
await productSelectorButton.click();
26+
const productSelector = await page.locator('data-testid=product-selector');
27+
await expect(productSelector.count()).toBeTruthy();
28+
29+
// Check it has four product groups. Usually this is frowned upon but is fine since it is a static number of groups for a while.
30+
const productSelectorContent = productSelector.locator(
31+
'data-testid=product-selector-content'
32+
);
33+
expect((await productSelectorContent.all()).length).toBe(4);
34+
});
35+
36+
test('should test F5 Sites button works', async ({ page }) => {
37+
const f5SitesButton = await page.locator(
38+
'data-testid=header__f5sites__button'
39+
);
40+
await f5SitesButton.click();
41+
const f5SitesContent = await page.locator(
42+
'data-testid=header__f5sites-content'
43+
);
44+
await expect(f5SitesContent.count()).toBeTruthy();
45+
});
46+
});
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { test } from '@playwright/test';
2-
import { runSmokeTest } from './util';
2+
import { runSmokeTestOnPage } from './util';
33

4-
test.describe('Smoke test', () => {
5-
test('should test each product landing page renders correctly', async ({
6-
page,
7-
}) => {
4+
test.describe('Smoke test for landing page', () => {
5+
test('should test each product landing page renders', async ({ page }) => {
86
const products = ['test-products', 'nginx'];
97

108
for (const product of products) {
119
await page.goto(`/${product}/`);
12-
await runSmokeTest(page);
10+
await runSmokeTestOnPage(page);
1311
}
1412
});
1513
});

tests/src/sidebar-smoke.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { test, expect } from '@playwright/test';
2-
import { runSmokeTest } from './util';
1+
import { test } from '@playwright/test';
2+
import { runSmokeTestOnPage } from './util';
33

44
async function openPage(page, sidebarPage) {
55
// Find all toggles
@@ -41,7 +41,7 @@ async function openPage(page, sidebarPage) {
4141
await content.waitFor();
4242
}
4343

44-
test.describe('Smoke test', () => {
44+
test.describe('Smoke test for sidebar', () => {
4545
test.beforeEach(async ({ page }) => {
4646
await page.goto(`/test-product/`);
4747
});
@@ -51,7 +51,7 @@ test.describe('Smoke test', () => {
5151
const sidebarPages = await page.locator('data-testid=sidebar__page').all();
5252
for (const sidebarPage of sidebarPages) {
5353
await openPage(page, sidebarPage);
54-
await runSmokeTest(page);
54+
await runSmokeTestOnPage(page);
5555
}
5656
});
5757
});

tests/src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@playwright/test';
22

3-
export async function runSmokeTest(page) {
3+
export async function runSmokeTestOnPage(page) {
44
/* Ensure each page follows the following dom structure */
55
await expect(await page.locator('data-testid=content').count()).toBeTruthy();
66
await expect(await page.locator('data-testid=header').count()).toBeTruthy();

0 commit comments

Comments
 (0)