baseLayout.e2e.js 950 Bytes
Newer Older
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
1 2 3 4 5 6 7
import RouterConfig from '../../config/router.config';

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 25 26 27 28
    const haveFooter = await page.evaluate(
      () => document.getElementsByTagName('footer').length > 0
    );
    expect(haveFooter).toBeTruthy();
  };
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
29 30 31 32 33

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