From d393c29d922098e7ae47caa7c99ad911f4970d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Tue, 9 Oct 2018 19:18:06 +0800 Subject: [PATCH] add layout test (#2499) * add layout test * change judge to tagName --- src/components/GlobalFooter/index.js | 4 +- src/e2e/layout.e2e.js | 61 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/e2e/layout.e2e.js diff --git a/src/components/GlobalFooter/index.js b/src/components/GlobalFooter/index.js index 01e526e8..1c2fb74e 100644 --- a/src/components/GlobalFooter/index.js +++ b/src/components/GlobalFooter/index.js @@ -5,7 +5,7 @@ import styles from './index.less'; const GlobalFooter = ({ className, links, copyright }) => { const clsString = classNames(styles.globalFooter, className); return ( -
+
+ ); }; diff --git a/src/e2e/layout.e2e.js b/src/e2e/layout.e2e.js new file mode 100644 index 00000000..af1d2b33 --- /dev/null +++ b/src/e2e/layout.e2e.js @@ -0,0 +1,61 @@ +import puppeteer from 'puppeteer'; +import RouterConfig from '../../config/router.config'; + +function formatter(data) { + return data + .reduce((pre, item) => { + if (item.routes) { + return pre.concat(formatter(item.routes)); + } + pre.push(item.path); + return pre; + }, []) + .filter(item => item); +} + +describe('Homepage', () => { + let browser; + let page; + + const testAllPage = async layout => + new Promise(async (resolve, reject) => { + const loadPage = async index => { + const path = layout[index]; + try { + await page.goto(`http://localhost:8000${path}`, { waitUntil: 'networkidle2' }); + const haveFooter = await page.evaluate( + () => document.getElementsByTagName('footer').length > 0 + ); + + expect(haveFooter).toBeTruthy(); + + if (index < layout.length - 1) { + loadPage(index + 1); + } else { + resolve('ok'); + } + } catch (error) { + reject(error); + } + }; + loadPage(0); + }); + + beforeAll(async () => { + browser = await puppeteer.launch({ args: ['--no-sandbox'] }); + page = await browser.newPage(); + jest.setTimeout(1000000); + }); + + it('test user layout', async () => { + const userLayout = formatter(RouterConfig[0].routes); + await testAllPage(userLayout); + }); + + it('test base layout', async () => { + const baseLayout = formatter(RouterConfig[1].routes); + await testAllPage(baseLayout); + }); + + afterAll(() => browser.close()); +}); -- GitLab