|
| 1 | +import { randHash } from '../utils/index.js' |
| 2 | + |
| 3 | +const currentUser = randHash() |
| 4 | + |
| 5 | +const refresh = () => cy.get('.files-controls .crumb:not(.hidden) a') |
| 6 | + .last() |
| 7 | + .click({ force: true }) |
| 8 | + |
| 9 | +const clickOutline = () => { |
| 10 | + cy.getActionEntry('headings') |
| 11 | + .click() |
| 12 | + |
| 13 | + cy.get('.v-popper__wrapper .open').getActionEntry('outline') |
| 14 | + .click() |
| 15 | +} |
| 16 | + |
| 17 | +const createMarkdown = (fileName, content) => { |
| 18 | + return cy.createFile(fileName, content, 'text/markdown') |
| 19 | + .then(refresh) |
| 20 | +} |
| 21 | + |
| 22 | +describe('Table of Contents', () => { |
| 23 | + before(() => { |
| 24 | + // Init user |
| 25 | + cy.nextcloudCreateUser(currentUser, 'password') |
| 26 | + cy.login(currentUser, 'password') |
| 27 | + }) |
| 28 | + |
| 29 | + beforeEach(() => { |
| 30 | + cy.login(currentUser, 'password') |
| 31 | + }) |
| 32 | + |
| 33 | + it('sidebar toc', () => { |
| 34 | + const fileName = 'toc.md' |
| 35 | + |
| 36 | + createMarkdown(fileName, '# T1 \n ## T2 \n ### T3 \n #### T4 \n ##### T5 \n ###### T6') |
| 37 | + .then(refresh) |
| 38 | + .then(() => cy.openFile(fileName, { force: true })) |
| 39 | + .then(clickOutline) |
| 40 | + |
| 41 | + cy.getOutline() |
| 42 | + .find('header') |
| 43 | + .should('exist') |
| 44 | + |
| 45 | + cy.getTOC() |
| 46 | + .find('ul li') |
| 47 | + .should('have.length', 6) |
| 48 | + cy.getTOC() |
| 49 | + .find('ul li') |
| 50 | + .each((el, index) => { |
| 51 | + cy.wrap(el) |
| 52 | + .should('have.attr', 'data-toc-level') |
| 53 | + .and('equal', String(index + 1)) |
| 54 | + |
| 55 | + cy.wrap(el) |
| 56 | + .find('a') |
| 57 | + .should('have.attr', 'href') |
| 58 | + .and('equal', `#t${index + 1}`) |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + it('empty toc', () => { |
| 63 | + const fileName = 'empty.md' |
| 64 | + |
| 65 | + createMarkdown(fileName, '') |
| 66 | + .then(refresh) |
| 67 | + .then(() => cy.openFile(fileName, { force: true })) |
| 68 | + .then(clickOutline) |
| 69 | + |
| 70 | + cy.getOutline() |
| 71 | + .find('ul') |
| 72 | + .should('be.empty') |
| 73 | + }) |
| 74 | +}) |
0 commit comments