baseLayout.e2e.js 920 Bytes
Newer Older
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
1
const RouterConfig = [];
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
2 3 4 5 6
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;

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

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

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