baseLayout.e2e.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const { uniq } = require('lodash');
  2. const RouterConfig = require('../../config/config').default.routes;
  3. const BASE_URL = `http://localhost:${process.env.PORT || 8001}`;
  4. function formatter(routes, parentPath = '') {
  5. const fixedParentPath = parentPath.replace(/\/{1,}/g, '/');
  6. let result = [];
  7. routes.forEach((item) => {
  8. if (item.path && !item.path.startsWith('/')) {
  9. result.push(`${fixedParentPath}/${item.path}`.replace(/\/{1,}/g, '/'));
  10. }
  11. if (item.path && item.path.startsWith('/')) {
  12. result.push(`${item.path}`.replace(/\/{1,}/g, '/'));
  13. }
  14. if (item.routes) {
  15. result = result.concat(
  16. formatter(item.routes, item.path ? `${fixedParentPath}/${item.path}` : parentPath),
  17. );
  18. }
  19. });
  20. return uniq(result.filter((item) => !!item));
  21. }
  22. beforeEach(async () => {
  23. await page.goto(`${BASE_URL}`);
  24. await page.evaluate(() => {
  25. localStorage.setItem('antd-pro-authority', '["admin"]');
  26. localStorage.setItem('X-Access-Token', 'a688358d5d1b48b6b7249ca01dd0cefe');
  27. });
  28. });
  29. describe('Ant Design Pro E2E test', () => {
  30. const testPage = (path) => async () => {
  31. await page.goto(`${BASE_URL}${path}`);
  32. // await page.waitForSelector('footer', {
  33. // timeout: 2000,
  34. // });
  35. // const haveFooter = await page.evaluate(
  36. // () => document.getElementsByTagName('footer').length > 0,
  37. // );
  38. // expect(haveFooter).toBeTruthy();
  39. };
  40. const routers = formatter(RouterConfig);
  41. routers.forEach((route) => {
  42. it(`test pages ${route}`, testPage(route));
  43. });
  44. it('topmenu should have footer', async () => {
  45. const params = '?navTheme=light&layout=topmenu';
  46. await page.goto(`${BASE_URL}${params}`);
  47. await page.waitForSelector('footer', {
  48. timeout: 2000,
  49. });
  50. const haveFooter = await page.evaluate(
  51. () => document.getElementsByTagName('footer').length > 0,
  52. );
  53. expect(haveFooter).toBeTruthy();
  54. });
  55. });