baseLayout.e2e.js 999 Bytes
Newer Older
何乐's avatar
何乐 committed
1 2 3 4
jest.mock('antd-pro-merge-less');

const RouterConfig = require('../../config/config').default.routes;

ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
5 6 7 8 9
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;

function formatter(data) {
  return data
    .reduce((pre, item) => {
10 11 12 13 14
      if (item.routes) {
        pre.push(item.routes[0].path);
      } else {
        pre.push(item.path);
      }
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
15 16 17 18 19
      return pre;
    }, [])
    .filter(item => item);
}

20
describe('Homepage', () => {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
21 22 23 24
  const testPage = path => async () => {
    await page.goto(`${BASE_URL}${path}`);
    await page.waitForSelector('footer', {
      timeout: 2000,
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
25
    });
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
26
    const haveFooter = await page.evaluate(
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
27
      () => document.getElementsByTagName('footer').length > 0,
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
28 29 30
    );
    expect(haveFooter).toBeTruthy();
  };
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
31 32 33 34 35

  beforeAll(async () => {
    jest.setTimeout(1000000);
    await page.setCacheEnabled(false);
  });
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
36 37
  const routers = formatter(RouterConfig[1].routes);
  routers.forEach(route => {
38
    it(`test pages ${route}`, testPage(route));
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
39 40
  });
});