|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { parse } from 'path'; |
| 3 | +import { checkScreenshot, testSelector } from '../../utils'; |
| 4 | +import { RESOLUTIONS } from '../visual-constants'; |
| 5 | +import { WebHelpPage } from './page'; |
| 6 | + |
| 7 | +const DOCS_URLS = [`/docs/home.html`, '/docs/multiplatform/get-started.html']; |
| 8 | + |
| 9 | +for (let index = 0, docsLength = DOCS_URLS.length; index < docsLength; index++) { |
| 10 | + const docsUrl = DOCS_URLS[index]; |
| 11 | + |
| 12 | + for (const [resolutionName, resolution] of Object.entries(RESOLUTIONS)) { |
| 13 | + test.describe(`Docs: ${parse(docsUrl).dir}/ on ${resolutionName}`, () => { |
| 14 | + test.beforeEach(async ({ page }) => { |
| 15 | + await page.setViewportSize(resolution); |
| 16 | + |
| 17 | + const webHelpPage = new WebHelpPage(page, docsUrl); |
| 18 | + await webHelpPage.init(); |
| 19 | + }); |
| 20 | + |
| 21 | + test(`Should render table of contents properly`, async ({ page }) => { |
| 22 | + test.skip(resolutionName !== 'desktop'); |
| 23 | + |
| 24 | + const element = page.locator(testSelector('toc')); |
| 25 | + |
| 26 | + await expect(element).toHaveCount(1); |
| 27 | + await expect(element).toBeVisible(); |
| 28 | + |
| 29 | + await checkScreenshot(element); |
| 30 | + }); |
| 31 | + |
| 32 | + test(`Should open page item properly`, async ({ page }) => { |
| 33 | + test.skip(resolutionName !== 'desktop'); |
| 34 | + |
| 35 | + const element = page.locator(testSelector('toc')).first(); |
| 36 | + |
| 37 | + const tocItem = element.locator(testSelector('internal-link toc-item')).first(); |
| 38 | + const link = new URL(await tocItem.getAttribute('href'), page.url()); |
| 39 | + |
| 40 | + await tocItem.click(); |
| 41 | + expect(page.url()).toBe(link.href); |
| 42 | + }); |
| 43 | + |
| 44 | + test(`Should render table of contents with expanded item properly`, async ({ page }) => { |
| 45 | + test.skip(resolutionName !== 'desktop'); |
| 46 | + |
| 47 | + const toc = page.locator(testSelector('toc')); |
| 48 | + |
| 49 | + await expect(toc).toHaveCount(1); |
| 50 | + await expect(toc).toBeVisible(); |
| 51 | + |
| 52 | + const item = toc.locator(`:scope > li:has(${testSelector('toc-item')})`).first(); |
| 53 | + await expect(item).toBeVisible(); |
| 54 | + |
| 55 | + const itemExpander = item.locator(testSelector('toc-expander')).first(); |
| 56 | + await expect(item).toBeVisible(); |
| 57 | + |
| 58 | + const itemNext = item.locator(`:scope + li`).first(); |
| 59 | + const itemNextText = await itemNext.textContent(); |
| 60 | + |
| 61 | + await itemExpander.click(); |
| 62 | + |
| 63 | + expect(await itemNext.textContent()).not.toBe(itemNextText); |
| 64 | + |
| 65 | + await checkScreenshot(item); |
| 66 | + }); |
| 67 | + |
| 68 | + test(`Should render header properly`, async ({ page }) => { |
| 69 | + const element = page.locator('.kt-header'); |
| 70 | + await expect(element).toBeVisible(); |
| 71 | + await checkScreenshot(element, { mask: [page.locator('.kt-header__product-version')] }); |
| 72 | + }); |
| 73 | + |
| 74 | + test(`Should render footer properly`, async ({ page }) => { |
| 75 | + const element = page.locator(testSelector('footer')); |
| 76 | + await expect(element).toBeVisible(); |
| 77 | + await checkScreenshot(element); |
| 78 | + }); |
| 79 | + |
| 80 | + test(`Should render docs switcher properly`, async ({ page }) => { |
| 81 | + const switcher = page.locator('[data-e2e="toc-subnav"]'); |
| 82 | + |
| 83 | + if (resolutionName !== 'desktop') { |
| 84 | + await expect(switcher).not.toBeVisible(); |
| 85 | + return; |
| 86 | + } |
| 87 | + |
| 88 | + await expect(switcher).toHaveCount(1); |
| 89 | + await expect(switcher).toBeVisible(); |
| 90 | + |
| 91 | + const items = switcher.locator('[data-rs-internal=switcher__option]'); |
| 92 | + await expect(items).toHaveCount(2); |
| 93 | + |
| 94 | + await expect(items.nth(index).locator(':scope[class*=_selected_]')).toBeVisible(); |
| 95 | + |
| 96 | + const inactiveItemIndex = (index + 1) % docsLength; |
| 97 | + |
| 98 | + const inactiveItem = items.nth(inactiveItemIndex); |
| 99 | + await expect(inactiveItem.locator(':scope[class*=_selected_]')).not.toBeVisible(); |
| 100 | + |
| 101 | + await checkScreenshot(switcher); |
| 102 | + |
| 103 | + await inactiveItem.click(); |
| 104 | + await expect(page).toHaveURL(DOCS_URLS[inactiveItemIndex]); |
| 105 | + }); |
| 106 | + |
| 107 | + test(`Should open quick search and show results`, async ({ page }) => { |
| 108 | + await page.locator(testSelector('search-button')).click(); |
| 109 | + await expect(page.locator(testSelector('search-quick'))).toBeVisible(); |
| 110 | + |
| 111 | + const input = page.locator(testSelector('input__inner')); |
| 112 | + await expect(input).toBeVisible(); |
| 113 | + await input.fill('grammar'); |
| 114 | + |
| 115 | + const results = page.locator(testSelector('search-results')); |
| 116 | + await expect(results).toBeVisible(); |
| 117 | + |
| 118 | + const items = page.locator(testSelector('list-item')); |
| 119 | + expect(await items.count()).toBeGreaterThan(1); |
| 120 | + |
| 121 | + await checkScreenshot(page.locator(testSelector('search-quick')), { |
| 122 | + mask: [page.locator(testSelector('result-content')), page.locator(testSelector('search-results'))], |
| 123 | + }); |
| 124 | + }); |
| 125 | + |
| 126 | + test(`Should close quick search on Escape`, async ({ page }) => { |
| 127 | + await page.locator(testSelector('search-button')).click(); |
| 128 | + await expect(page.locator(testSelector('search-quick'))).toBeVisible(); |
| 129 | + |
| 130 | + await page.keyboard.press('Escape'); |
| 131 | + await expect(page.locator(testSelector('search-quick'))).not.toBeVisible(); |
| 132 | + }); |
| 133 | + |
| 134 | + test(`Should open full search from quick search`, async ({ page }) => { |
| 135 | + await page.locator(testSelector('search-button')).click(); |
| 136 | + await expect(page.locator(testSelector('search-quick'))).toBeVisible(); |
| 137 | + |
| 138 | + const input = page.locator(testSelector('input__inner')); |
| 139 | + await input.fill('grammar'); |
| 140 | + await expect(page.locator(testSelector('search-results'))).toBeVisible(); |
| 141 | + |
| 142 | + const fullSearchButton = page.locator(testSelector('full-search-button')); |
| 143 | + |
| 144 | + if (resolutionName === 'mobile') { |
| 145 | + await expect(fullSearchButton).not.toBeVisible(); |
| 146 | + return; |
| 147 | + } |
| 148 | + |
| 149 | + await fullSearchButton.click(); |
| 150 | + await expect(page.locator(testSelector('search-full'))).toBeVisible(); |
| 151 | + |
| 152 | + await expect(page).toHaveURL(/\?q=grammar&s=full/); |
| 153 | + |
| 154 | + const fullResults = page.locator(testSelector('search-full')).locator(testSelector('search-results')); |
| 155 | + await expect(fullResults).toBeVisible(); |
| 156 | + |
| 157 | + await checkScreenshot(page.locator(testSelector('search-full')), { |
| 158 | + mask: [page.locator(testSelector('result-content')), page.locator(testSelector('search-results'))], |
| 159 | + }); |
| 160 | + }); |
| 161 | + |
| 162 | + test(`Should close full search`, async ({ page }) => { |
| 163 | + await page.locator(testSelector('search-button')).click(); |
| 164 | + await expect(page.locator(testSelector('search-quick'))).toBeVisible(); |
| 165 | + |
| 166 | + const input = page.locator(testSelector('input__inner')); |
| 167 | + await input.fill('grammar'); |
| 168 | + await expect(page.locator(testSelector('search-results'))).toBeVisible(); |
| 169 | + |
| 170 | + const fullSearchButton = page.locator(testSelector('full-search-button')); |
| 171 | + |
| 172 | + if (resolutionName === 'mobile') { |
| 173 | + await expect(fullSearchButton).not.toBeVisible(); |
| 174 | + return; |
| 175 | + } |
| 176 | + |
| 177 | + await fullSearchButton.click(); |
| 178 | + await expect(page.locator(testSelector('search-full'))).toBeVisible(); |
| 179 | + |
| 180 | + await page.locator(testSelector('close-search')).click(); |
| 181 | + await expect(page.locator(testSelector('search-full'))).not.toBeVisible(); |
| 182 | + }); |
| 183 | + }); |
| 184 | + } |
| 185 | +} |
0 commit comments