|
| 1 | +const testCases = [ |
| 2 | + { |
| 3 | + selector: '#index', |
| 4 | + expected: { |
| 5 | + path: '/', |
| 6 | + meta: {}, |
| 7 | + notFound: false, |
| 8 | + }, |
| 9 | + }, |
| 10 | + { |
| 11 | + selector: '#non-index', |
| 12 | + expected: { |
| 13 | + path: '/router/resolve-route.html', |
| 14 | + meta: {}, |
| 15 | + notFound: false, |
| 16 | + }, |
| 17 | + }, |
| 18 | + { |
| 19 | + selector: '#non-ascii', |
| 20 | + expected: { |
| 21 | + path: encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html'), |
| 22 | + meta: {}, |
| 23 | + notFound: false, |
| 24 | + }, |
| 25 | + }, |
| 26 | + { |
| 27 | + selector: '#non-ascii-encoded', |
| 28 | + expected: { |
| 29 | + path: encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html'), |
| 30 | + meta: {}, |
| 31 | + notFound: false, |
| 32 | + }, |
| 33 | + }, |
| 34 | + { |
| 35 | + selector: '#non-existent', |
| 36 | + expected: { |
| 37 | + path: '/non-existent.html', |
| 38 | + meta: { foo: 'bar' }, |
| 39 | + notFound: true, |
| 40 | + }, |
| 41 | + }, |
| 42 | + { |
| 43 | + selector: '#route-meta', |
| 44 | + expected: { |
| 45 | + path: '/page-data/route-meta.html', |
| 46 | + meta: { a: 0, b: 2, c: 3 }, |
| 47 | + notFound: false, |
| 48 | + }, |
| 49 | + }, |
| 50 | +] |
| 51 | + |
| 52 | +const parseResolvedRouteFromElement = (el: Cypress.JQueryWithSelector) => |
| 53 | + JSON.parse(/: (\{.*\})\s*$/.exec(el.text())![1]) |
| 54 | + |
| 55 | +it('should resolve routes correctly', () => { |
| 56 | + cy.visit('/router/resolve-route.html') |
| 57 | + |
| 58 | + testCases.forEach(({ selector, expected }) => { |
| 59 | + cy.get(`.e2e-theme-content ${selector} + ul > li`).each((el) => { |
| 60 | + const resolvedRoute = parseResolvedRouteFromElement(el) |
| 61 | + expect(resolvedRoute.path).to.equal(expected.path) |
| 62 | + expect(resolvedRoute.meta).to.deep.equal(expected.meta) |
| 63 | + expect(resolvedRoute.notFound).to.equal(expected.notFound) |
| 64 | + }) |
| 65 | + }) |
| 66 | +}) |
0 commit comments