Unverified Commit d393c29d authored by 陈帅's avatar 陈帅 Committed by GitHub

add layout test (#2499)

* add layout test

* change judge to tagName
parent e0882a7c
...@@ -5,7 +5,7 @@ import styles from './index.less'; ...@@ -5,7 +5,7 @@ import styles from './index.less';
const GlobalFooter = ({ className, links, copyright }) => { const GlobalFooter = ({ className, links, copyright }) => {
const clsString = classNames(styles.globalFooter, className); const clsString = classNames(styles.globalFooter, className);
return ( return (
<div className={clsString}> <footer className={clsString}>
{links && ( {links && (
<div className={styles.links}> <div className={styles.links}>
{links.map(link => ( {links.map(link => (
...@@ -21,7 +21,7 @@ const GlobalFooter = ({ className, links, copyright }) => { ...@@ -21,7 +21,7 @@ const GlobalFooter = ({ className, links, copyright }) => {
</div> </div>
)} )}
{copyright && <div className={styles.copyright}>{copyright}</div>} {copyright && <div className={styles.copyright}>{copyright}</div>}
</div> </footer>
); );
}; };
......
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());
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment