Skip to content

Commit cec8411

Browse files
committed
Tests: Added new UI smoke tests
1 parent 8b8a3ee commit cec8411

File tree

13 files changed

+99
-40
lines changed

13 files changed

+99
-40
lines changed

layouts/404.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{ define "main"}}
22

3-
<div class="content">
4-
<div class="not-found-container">
3+
<div class="content" data-testid="content">
4+
<div class="not-found-container" data-testid="not-found-container">
55
<h1 class="info-header">
66
HTTP 404 - Page not found
77
</h1>

layouts/_default/baseof.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@
4343
{{ end }}
4444
<input type="checkbox" id="sidebar-panel" class="sidebar-panel" hidden/>
4545
<div class="grid-container">
46-
<aside class="sidebar">
46+
<aside class="sidebar" data-testid="sidebar">
4747
{{ partial "sidebar-v2.html" . }}
4848
</aside>
4949

50-
<header class="header">
50+
<header class="header" data-testid="header">
5151
{{ block "header" . }}{{end}}
5252
</header>
5353

5454
{{ block "main" . }}{{ end }}
5555

56-
<footer class="footer">
56+
<footer class="footer" data-testid="footer">
5757
{{ block "footer-v2" . }}
5858
{{ partial "footer-v2.html" . }}
5959
{{ end }}

layouts/_default/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{ define "main" }}
22

3-
<main class="content " role="main">
3+
<main class="content " role="main" data-testid="content">
44
<section class="main-layout">
55
<section id="maincontent" class="content-layout">
66
<div data-cms-edit="content" class="text-content list-page">

layouts/_default/single.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{ define "main" }}
22

3-
<main class="content">
3+
<main class="content" data-testid="content">
44
<!-- Replace icons -->
55
{{ $content := partial "icon-replacement.html" (dict "content" .Content) }}
66

layouts/partials/api.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--Use wide page layout for the API reference pages-->
22
<div class="nginx-docs-api-container">
3-
<div id="api-component" class="content">
3+
<div id="api-component" class="content" data-testid="content">
44
{{ .Content}}
55
</div>
66
</div>

layouts/partials/sidebar-list.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{ $firstSection := .firstSection }}
44
{{ $idPrefix := .idPrefix }}
55
{{ with $firstSection }}
6-
<ul class="sidebar__ul">
6+
<ul class="sidebar__ul" data-testid="sidebar__ul">
77
{{ $pages := .Pages.ByWeight }}
88
{{ range $index, $p := $pages }}
99
{{- $onPage := eq $currentUrl $p.Permalink -}}
@@ -14,10 +14,11 @@
1414
{{- $nextIndex := add $index 1 -}}
1515
{{- $nextLink := index $pages $nextIndex -}}
1616
{{ if eq $p.Kind "section" }}
17-
<li class="sidebar__section">
17+
<li class="sidebar__section" data-testid="sidebar__section">
1818
<button
1919
id="{{ $linkID }}"
2020
class="sidebar__toggle {{ if $isAncestor }}sidebar__toggle--ancestor{{ end }}"
21+
data-testid="sidebar__section__toggle"
2122
aria-expanded="{{ $shouldExpand }}"
2223
aria-controls="{{ $sectionID }}"
2324
>
@@ -33,7 +34,7 @@
3334
>
3435
{{ if and .Content (gt (len .Pages) 0) }}
3536
<ul>
36-
<li class="sidebar__page">
37+
<li class="sidebar__page" data-testid="sidebar__page">
3738
<a
3839
href="{{ $p.Permalink }}"
3940
class="sidebar__link {{ if $onPage }}sidebar__link--current{{ end }}"
@@ -57,7 +58,7 @@
5758
{{- $tocHasItems := (in $p.TableOfContents "<li>") -}}
5859
{{- $pageHasTOC := (and $onPage $tocHasItems $p.Params.toc) -}}
5960
{{- $tocID := printf "%stoc-%s" $idPrefix (urlize $p.Permalink) -}}
60-
<li class="sidebar__page">
61+
<li class="sidebar__page" data-testid="sidebar__page">
6162
{{ if $pageHasTOC }}
6263
<button
6364
class="sidebar__toggle sidebar__link sidebar__link--current"

layouts/partials/sidebar-v2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</label>
3535
</div>
3636
</div>
37-
<div class="sidebar__content">
37+
<div class="sidebar__content" data-testid="sidebar__content">
3838
<a class="skip-link" href="#maincontent">Skip Navigation</a>
3939
{{ partial "sidebar-list.html" (dict
4040
"firstSection" .FirstSection

layouts/redoc/single.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{ define "main" }}
22

3-
<main class="content content__redocly">
3+
<main class="content content__redocly" data-testid="content">
44
<div id="api-component">{{ .Content}}</div>
55
</main>
66

tests/playwright.config.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ export default defineConfig({
2121
name: 'firefox',
2222
use: { ...devices['Desktop Firefox'] },
2323
},
24-
{
25-
name: 'webkit',
26-
use: { ...devices['Desktop Safari'] },
27-
},
28-
{
29-
name: 'Mobile Chrome',
30-
use: { ...devices['Pixel 5'] },
31-
},
3224
],
3325
webServer: {
3426
command: `cd ../exampleSite && hugo mod get && hugo --gc --config hugo.toml,hugo.test.toml && hugo serve --port ${PORT} --config hugo.toml,hugo.test.toml`,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { test } from '@playwright/test';
2+
import { runSmokeTest } from './util';
3+
4+
test.describe('Smoke test', () => {
5+
test('should test each product landing page renders correctly', async ({
6+
page,
7+
}) => {
8+
const products = ['test-products', 'nginx'];
9+
10+
for (const product of products) {
11+
await page.goto(`/${product}/`);
12+
await runSmokeTest(page);
13+
}
14+
});
15+
});

tests/src/sidebar-smoke.spec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { test, expect } from '@playwright/test';
2+
import { runSmokeTest } from './util';
3+
4+
async function openPage(page, sidebarPage) {
5+
// Find all toggles
6+
let currentElement = sidebarPage;
7+
const toggles = [];
8+
9+
while (currentElement) {
10+
const parentElement = await currentElement.locator('..');
11+
const isSuperParent = await parentElement.evaluate(
12+
(el) => el.getAttribute('data-testid') === 'sidebar__content'
13+
);
14+
if (isSuperParent) break;
15+
16+
const parentElementClass = await parentElement.getAttribute('class');
17+
if (parentElementClass === 'sidebar__section') {
18+
const toggle = parentElement.locator(
19+
'data-testid=sidebar__section__toggle'
20+
);
21+
if ((await toggle.count()) > 0) {
22+
toggles.unshift(toggle.first());
23+
}
24+
}
25+
26+
currentElement = parentElement;
27+
}
28+
29+
// Click all toggles found top-down
30+
for (const toggle of toggles) {
31+
const isCollapsed =
32+
(await toggle.first().getAttribute('aria-expanded')) === 'false';
33+
if (isCollapsed) {
34+
await toggle.first().click();
35+
}
36+
}
37+
38+
// Click on the page
39+
await sidebarPage.click();
40+
const content = await page.locator('data-testid=content');
41+
await content.waitFor();
42+
}
43+
44+
test.describe('Smoke test', () => {
45+
test.beforeEach(async ({ page }) => {
46+
await page.goto(`/test-product/`);
47+
});
48+
49+
test('should test each section page on sidebar renders', async ({ page }) => {
50+
/* Click on each link */
51+
const sidebarPages = await page.locator('data-testid=sidebar__page').all();
52+
for (const sidebarPage of sidebarPages) {
53+
await openPage(page, sidebarPage);
54+
await runSmokeTest(page);
55+
}
56+
});
57+
});

tests/src/util.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect } from '@playwright/test';
2+
3+
export async function runSmokeTest(page) {
4+
/* Ensure each page follows the following dom structure */
5+
await expect(await page.locator('data-testid=content').count()).toBeTruthy();
6+
await expect(await page.locator('data-testid=header').count()).toBeTruthy();
7+
await expect(await page.locator('data-testid=sidebar').count()).toBeTruthy();
8+
await expect(await page.locator('data-testid=footer').count()).toBeTruthy();
9+
await expect(
10+
await page.locator('data-testid=not-found-container').count()
11+
).toBe(0);
12+
}

tests/src/visual-regression.spec.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)