|
| 1 | +const PERMALINK_PREFIX = Cypress.env('E2E_BASE').replace(/\/$/, '') |
| 2 | + |
| 3 | +const CONFIGS = [ |
| 4 | + { |
| 5 | + id: 'ascii-ascii', |
| 6 | + filename: 'ascii-ascii.md', |
| 7 | + permalink: '/permalink-ascii-ascii/', |
| 8 | + }, |
| 9 | + { |
| 10 | + id: 'ascii-non-ascii', |
| 11 | + filename: 'ascii-non-ascii.md', |
| 12 | + permalink: '/永久链接-ascii-中文/', |
| 13 | + }, |
| 14 | + { |
| 15 | + id: '中文-ascii', |
| 16 | + filename: '中文-ascii.md', |
| 17 | + permalink: '/permalink-non-ascii-ascii/', |
| 18 | + }, |
| 19 | + { |
| 20 | + id: '中文-中文', |
| 21 | + filename: '中文-中文.md', |
| 22 | + permalink: '/永久链接-中文-中文/', |
| 23 | + }, |
| 24 | +] |
| 25 | + |
| 26 | +it('should support visiting permalinks directly', () => { |
| 27 | + for (const { permalink } of CONFIGS) { |
| 28 | + cy.visit(encodeURI(permalink)) |
| 29 | + cy.get('.e2e-theme-content p').should('have.text', permalink) |
| 30 | + } |
| 31 | +}) |
| 32 | + |
| 33 | +it('should support rendering link by permalink and navigate to it correctly', () => { |
| 34 | + for (const { id, permalink } of CONFIGS) { |
| 35 | + cy.visit('/routes/permalinks/') |
| 36 | + |
| 37 | + // absolute link that does not end with '.md' will not be prepended with `base` |
| 38 | + cy.get(`.e2e-theme-content #${id} + ul > li a`) |
| 39 | + .should('have.length', 3) |
| 40 | + .eq(1) |
| 41 | + .should('have.attr', 'href', encodeURI(permalink)) |
| 42 | + |
| 43 | + // `withBase` won't encode the url |
| 44 | + cy.get(`.e2e-theme-content #${id} + ul > li a`) |
| 45 | + .should('have.length', 3) |
| 46 | + .eq(0) |
| 47 | + .should('have.attr', 'href', `${PERMALINK_PREFIX}${permalink}`) |
| 48 | + .click() |
| 49 | + |
| 50 | + cy.location('pathname').should( |
| 51 | + 'eq', |
| 52 | + encodeURI(`${PERMALINK_PREFIX}${permalink}`), |
| 53 | + ) |
| 54 | + |
| 55 | + cy.get('.e2e-theme-content p').should('have.text', permalink) |
| 56 | + } |
| 57 | +}) |
| 58 | + |
| 59 | +it('should support rendering link by filename and navigate to it correctly', () => { |
| 60 | + for (const { id, permalink } of CONFIGS) { |
| 61 | + cy.visit('/routes/permalinks/') |
| 62 | + |
| 63 | + cy.get(`.e2e-theme-content #${id} + ul > li a`) |
| 64 | + .should('have.length', 3) |
| 65 | + .eq(2) |
| 66 | + .should('have.attr', 'href', encodeURI(`${PERMALINK_PREFIX}${permalink}`)) |
| 67 | + .click() |
| 68 | + |
| 69 | + cy.location('pathname').should( |
| 70 | + 'eq', |
| 71 | + encodeURI(`${PERMALINK_PREFIX}${permalink}`), |
| 72 | + ) |
| 73 | + |
| 74 | + cy.get('.e2e-theme-content p').should('have.text', permalink) |
| 75 | + } |
| 76 | +}) |
0 commit comments