-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a65adb
commit df7910a
Showing
8 changed files
with
700 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const fetch = require('node-fetch'); | ||
|
||
/** | ||
* @param {object} event | ||
* @param {string} event.body - https://jsoneditoronline.org/#left=cloud.fb1a4fa30a4f475fa6887071c682e2c1 | ||
*/ | ||
exports.handler = async (event) => { | ||
const { payload } = JSON.parse(event.body); | ||
const repo = payload.review_url.match(/github\.com\/(.*)\/pull\/(.*)/); | ||
if (!repo) { | ||
throw new Error(`No repo found at review_url: ${payload.review_url}`); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.info(`repo:`, repo[1]); | ||
// eslint-disable-next-line no-console | ||
console.info(`PR:`, repo[2]); | ||
// eslint-disable-next-line no-console | ||
console.info(`url:`, payload.deploy_ssl_url); | ||
|
||
// for more details > https://circleci.com/docs/2.0/api-developers-guide/# | ||
await fetch(`https://circleci.com/api/v2/project/gh/${repo[1]}/pipeline`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/json', | ||
// token from https://app.netlify.com/sites/material-ui/settings/deploys#environment-variables | ||
'Circle-Token': process.env.CIRCLE_CI_TOKEN, | ||
}, | ||
body: JSON.stringify({ | ||
// For PR, /head is needed. https://support.circleci.com/hc/en-us/articles/360049841151 | ||
branch: `pull/${repo[2]}/head`, | ||
parameters: { | ||
// the parameters defined in .circleci/config.yml | ||
workflow: 'e2e-website', // name of the workflow | ||
'e2e-base-url': payload.deploy_ssl_url, // deploy preview url | ||
}, | ||
}), | ||
}); | ||
return { | ||
statusCode: 200, | ||
body: {}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Docs end-to-end testing | ||
|
||
## Running locally | ||
|
||
1. Run `yarn docs:dev` to start docs in development server. | ||
2. Run `yarn test:e2e-website` in a separate terminal to run the test suites (`*.spec.ts`) inside `test/e2e-website` folder. | ||
|
||
> use --headed to run tests in headed browsers, check out [Playwright CLI](https://playwright.dev/docs/intro#command-line) for more options | ||
## CI | ||
|
||
After netlify deploy the preview site, the `netlify/functions/deploy-succeeded.js` hook calls CircleCI API to run the `e2e-website` workflow against the deployed url. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { test as base, expect, Page } from '@playwright/test'; | ||
import kebabCase from 'lodash/kebabCase'; | ||
import { TestFixture } from './playwright.config'; | ||
|
||
const test = base.extend<TestFixture>({}); | ||
|
||
test.describe.parallel('Material docs', () => { | ||
test('should have correct link with hash in the TOC', async ({ page }) => { | ||
await page.goto(`/components/data-grid/getting-started/`); | ||
|
||
const anchors = page.locator('[aria-label="Page table of contents"] ul a'); | ||
|
||
const anchorTexts = await anchors.allTextContents(); | ||
|
||
await Promise.all( | ||
anchorTexts.map((text, index) => { | ||
return expect(anchors.nth(index)).toHaveAttribute( | ||
'href', | ||
// This is fine for now even though the hash implementation (in textToHash.js) is not the same as kebabCase | ||
`/components/data-grid/getting-started/#${kebabCase(text.toLowerCase())}`, | ||
); | ||
}), | ||
); | ||
}); | ||
|
||
test.describe.parallel('Demo page', () => { | ||
test('should have correct link for API section', async ({ page }) => { | ||
await page.goto(`/components/data-grid/`); | ||
|
||
const anchors = await page.locator('div > h2#heading-api ~ ul a'); | ||
|
||
const anchorTexts = await anchors.allTextContents(); | ||
|
||
await Promise.all( | ||
anchorTexts.map((text, index) => { | ||
return expect(anchors.nth(index)).toHaveAttribute( | ||
'href', | ||
`/api/data-grid/${kebabCase(text)}/`, | ||
); | ||
}), | ||
); | ||
}); | ||
|
||
test('should have correct link for sidebar anchor', async ({ page }) => { | ||
await page.goto(`/components/data-grid/`); | ||
|
||
const anchor = await page.locator('nav[aria-label="documentation"] ul a:text-is("Overview")'); | ||
|
||
await expect(anchor).toHaveAttribute('href', `/components/data-grid/`); | ||
}); | ||
}); | ||
|
||
test.describe.parallel('API page', () => { | ||
test('should have correct link for sidebar anchor', async ({ page }) => { | ||
await page.goto(`/api/data-grid/data-grid/`); | ||
|
||
const anchor = await page.locator('nav[aria-label="documentation"] ul a:text-is("DataGrid")'); | ||
|
||
await expect(anchor).toHaveAttribute('app-drawer-active', ''); | ||
await expect(anchor).toHaveAttribute('href', `/api/data-grid/data-grid/`); | ||
}); | ||
|
||
test('all the links in the main content should have correct prefix', async ({ page }) => { | ||
await page.goto(`/api/data-grid/data-grid/`); | ||
|
||
const anchors = await page.locator('div#main-content a'); | ||
|
||
const handles = await anchors.elementHandles(); | ||
|
||
const links = await Promise.all(handles.map((elm) => elm.getAttribute('href'))); | ||
|
||
links.forEach((link) => { | ||
expect(link?.startsWith('/x/data-grid')).toBeFalsy(); | ||
}); | ||
}); | ||
}); | ||
|
||
test.describe.parallel('Search', () => { | ||
const retryToggleSearch = async (page: Page, count = 3) => { | ||
try { | ||
await page.keyboard.press('Meta+k'); | ||
await page.waitForSelector('input#docsearch-input', { timeout: 2000 }); | ||
} catch (error) { | ||
if (count === 0) { | ||
throw error; | ||
} | ||
await retryToggleSearch(page, count - 1); | ||
} | ||
}; | ||
test('should have correct link when searching component', async ({ page }) => { | ||
await page.goto(`/components/data-grid/getting-started/`, { waitUntil: 'networkidle' }); | ||
|
||
await retryToggleSearch(page); | ||
|
||
await page.type('input#docsearch-input', 'datagrid', { delay: 50 }); | ||
|
||
const anchor = await page.locator('.DocSearch-Hits a:has-text("Data Grid - Components")'); | ||
|
||
await expect(anchor.first()).toHaveAttribute( | ||
'href', | ||
`/components/data-grid/components/#main-content`, | ||
); | ||
}); | ||
|
||
test('should have correct link when searching API', async ({ page }) => { | ||
await page.goto(`/components/data-grid/getting-started/`, { waitUntil: 'networkidle' }); | ||
|
||
await retryToggleSearch(page); | ||
|
||
await page.type('input#docsearch-input', 'datagrid api', { delay: 50 }); | ||
|
||
const anchor = await page.locator('.DocSearch-Hits a:has-text("DataGrid API")'); | ||
|
||
await expect(anchor.first()).toHaveAttribute( | ||
'href', | ||
`/api/data-grid/data-grid/#main-content`, | ||
); | ||
}); | ||
|
||
test('should have correct link when searching pro API', async ({ page }) => { | ||
await page.goto(`/components/data-grid/getting-started/`); | ||
|
||
await page.waitForLoadState('networkidle'); // wait for docsearch | ||
|
||
await retryToggleSearch(page); | ||
|
||
await page.type('input#docsearch-input', 'datagridpro api', { delay: 50 }); | ||
|
||
const anchor = await page.locator('.DocSearch-Hits a:has-text("DataGridPro API")'); | ||
|
||
await expect(anchor.first()).toHaveAttribute( | ||
'href', | ||
`/api/data-grid/data-grid-pro/#main-content`, | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.