baseLayout.e2e.js 1.6 KB

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