2021-05-04 14:34:16 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
const TEST_STRING_UNCHECKED = '- [ ] abc\n\n* [ ] abc\n\n+ [ ] abc\n\n1. [ ] abc\n\n10. [ ] abc\n\n5) [ ] abc'
|
|
|
|
const TEST_STRING_CHECKED_LOWER = '- [x] abc\n\n* [x] abc\n\n+ [x] abc\n\n1. [x] abc\n\n10. [x] abc\n\n5) [x] abc'
|
|
|
|
const TEST_STRING_CHECKED_UPPER = '- [X] abc\n\n* [X] abc\n\n+ [X] abc\n\n1. [X] abc\n\n10. [X] abc\n\n5) [X] abc'
|
|
|
|
const TEST_STRING_INVALID = '- [Y] abc\n\n* [ ] abc\n\n+ [-] abc\n\n1. [.] abc\n\n10. [] abc\n\n5) [-] abc'
|
|
|
|
|
|
|
|
describe('Task lists ', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.visitTestEditor()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('render with checkboxes ', () => {
|
|
|
|
it('when unchecked', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent(TEST_STRING_UNCHECKED)
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getMarkdownBody().find('input[type=checkbox]').should('have.length', 6)
|
2021-05-04 14:34:16 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('when checked lowercase', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent(TEST_STRING_CHECKED_LOWER)
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getMarkdownBody().find('input[type=checkbox]').should('have.length', 6)
|
2021-05-04 14:34:16 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('when checked uppercase', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent(TEST_STRING_CHECKED_UPPER)
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getMarkdownBody().find('input[type=checkbox]').should('have.length', 6)
|
2021-05-04 14:34:16 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('do not render as checkboxes when invalid', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent(TEST_STRING_INVALID)
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getMarkdownBody().find('input[type=checkbox]').should('have.length', 0)
|
2021-05-04 14:34:16 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('are clickable and change the markdown source ', () => {
|
|
|
|
it('from unchecked to checked', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent(TEST_STRING_UNCHECKED)
|
2021-05-04 14:34:16 -04:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('input[type=checkbox]')
|
2021-11-19 12:04:04 -05:00
|
|
|
.each((box) => {
|
2021-05-04 14:34:16 -04:00
|
|
|
box.trigger('click')
|
|
|
|
})
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.CodeMirror-line > span').should('exist').should('contain.text', '[x]').should('not.contain.text', '[ ]')
|
2021-05-04 14:34:16 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('from checked (lowercase) to unchecked', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent(TEST_STRING_CHECKED_LOWER)
|
2021-05-04 14:34:16 -04:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('input[type=checkbox]')
|
2021-11-19 12:04:04 -05:00
|
|
|
.each((box) => {
|
2021-05-04 14:34:16 -04:00
|
|
|
box.trigger('click')
|
|
|
|
})
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.CodeMirror-line > span').should('exist').should('contain.text', '[ ]').should('not.contain.text', '[x]')
|
2021-05-04 14:34:16 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('from checked (uppercase) to unchecked', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent(TEST_STRING_CHECKED_UPPER)
|
2021-05-04 14:34:16 -04:00
|
|
|
cy.getMarkdownBody()
|
|
|
|
.find('input[type=checkbox]')
|
2021-11-19 12:04:04 -05:00
|
|
|
.each((box) => {
|
2021-05-04 14:34:16 -04:00
|
|
|
box.trigger('click')
|
|
|
|
})
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.CodeMirror-line > span').should('exist').should('contain.text', '[ ]').should('not.contain.text', '[X]')
|
2021-05-04 14:34:16 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|