baseLayout.e2e.js 954 Bytes
Newer Older
何乐's avatar
何乐 committed
1 2
const RouterConfig = require('../../config/config').default.routes;

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

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

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

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