baseLayout.e2e.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. });
  27. });
  28. describe('Ant Design Pro E2E test', () => {
  29. const testPage = (path) => async () => {
  30. await page.goto(`${BASE_URL}${path}`);
  31. await page.waitForSelector('footer', {
  32. timeout: 2000,
  33. });
  34. const haveFooter = await page.evaluate(
  35. () => document.getElementsByTagName('footer').length > 0,
  36. );
  37. expect(haveFooter).toBeTruthy();
  38. };
  39. const routers = formatter(RouterConfig);
  40. routers.forEach((route) => {
  41. it(`test pages ${route}`, testPage(route));
  42. });
  43. it('topmenu should have footer', async () => {
  44. const params = '?navTheme=light&layout=topmenu';
  45. await page.goto(`${BASE_URL}${params}`);
  46. await page.waitForSelector('footer', {
  47. timeout: 2000,
  48. });
  49. const haveFooter = await page.evaluate(
  50. () => document.getElementsByTagName('footer').length > 0,
  51. );
  52. expect(haveFooter).toBeTruthy();
  53. });
  54. });