2020-11-22 15:50:07 -05:00
/ *
2021-01-06 15:37:59 -05:00
* SPDX - FileCopyrightText : 2021 The HedgeDoc developers ( see AUTHORS file )
2020-11-22 15:50:07 -05:00
*
* SPDX - License - Identifier : AGPL - 3.0 - only
* /
2021-11-19 12:04:04 -05:00
describe ( 'Autocompletion works for' , ( ) = > {
2020-08-14 07:58:59 -04:00
beforeEach ( ( ) = > {
2021-02-01 16:55:49 -05:00
cy . visitTestEditor ( )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror' ) . click ( ) . get ( 'textarea' ) . as ( 'codeinput' )
2020-08-14 07:58:59 -04:00
} )
2020-09-01 16:28:08 -04:00
describe ( 'code block' , ( ) = > {
2021-11-19 12:04:04 -05:00
it ( 'via enter' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '```' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints' ) . should ( 'exist' )
cy . get ( '@codeinput' ) . type ( '{enter}' )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span' ) . should ( 'have.text' , '```abnf' )
cy . get ( '.CodeMirror-code > div:nth-of-type(3) > .CodeMirror-line > span > span' ) . should ( 'have.text' , '```' )
cy . getMarkdownBody ( ) . findById ( 'highlighted-code-block' ) . should ( 'exist' )
2020-09-01 16:28:08 -04:00
} )
it ( 'via doubleclick' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '```' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints > li' ) . first ( ) . dblclick ( )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span' ) . should ( 'have.text' , '```abnf' )
cy . get ( '.CodeMirror-code > div:nth-of-type(3) > .CodeMirror-line > span > span' ) . should ( 'have.text' , '```' )
cy . getMarkdownBody ( ) . findById ( 'highlighted-code-block' ) . should ( 'exist' )
2020-09-01 16:28:08 -04:00
} )
} )
describe ( 'container' , ( ) = > {
2021-11-19 12:04:04 -05:00
it ( 'via enter' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( ':::' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints' ) . should ( 'exist' )
cy . get ( '@codeinput' ) . type ( '{enter}' )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span' ) . should ( 'have.text' , ':::success' )
cy . get ( '.CodeMirror-code > div:nth-of-type(3) > .CodeMirror-line > span > span' ) . should ( 'have.text' , '::: ' )
cy . getMarkdownBody ( ) . find ( 'div.alert' ) . should ( 'exist' )
2020-09-01 16:28:08 -04:00
} )
it ( 'via doubleclick' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( ':::' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints > li' ) . first ( ) . dblclick ( )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span' ) . should ( 'have.text' , ':::success' )
cy . get ( '.CodeMirror-code > div:nth-of-type(3) > .CodeMirror-line > span > span' ) . should ( 'have.text' , '::: ' )
cy . getMarkdownBody ( ) . find ( 'div.alert' ) . should ( 'exist' )
2020-09-01 16:28:08 -04:00
} )
} )
describe ( 'emoji' , ( ) = > {
describe ( 'normal emoji' , ( ) = > {
2021-11-19 12:04:04 -05:00
it ( 'via enter' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( ':hedg' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints' ) . should ( 'exist' )
cy . get ( '@codeinput' ) . type ( '{enter}' )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , ':hedgehog:' )
2020-09-01 16:28:08 -04:00
} )
it ( 'via doubleclick' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( ':hedg' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints > li' ) . first ( ) . dblclick ( )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , ':hedgehog:' )
2020-09-01 16:28:08 -04:00
} )
} )
describe ( 'fork-awesome-icon' , ( ) = > {
2021-11-19 12:04:04 -05:00
it ( 'via enter' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( ':fa-face' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints' ) . should ( 'exist' )
cy . get ( '@codeinput' ) . type ( '{enter}' )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , ':fa-facebook:' )
2020-09-01 16:28:08 -04:00
} )
it ( 'via doubleclick' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( ':fa-face' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints > li' ) . first ( ) . dblclick ( )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , ':fa-facebook:' )
2020-09-01 16:28:08 -04:00
} )
} )
} )
describe ( 'header' , ( ) = > {
2021-11-19 12:04:04 -05:00
it ( 'via enter' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '#' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints' ) . should ( 'exist' )
cy . get ( '@codeinput' ) . type ( '{enter}' )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , '# ' )
cy . getMarkdownBody ( ) . find ( 'h1' ) . should ( 'have.text' , '\n ' )
2020-09-01 16:28:08 -04:00
} )
it ( 'via doubleclick' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '#' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints > li' ) . first ( ) . dblclick ( )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , '# ' )
cy . getMarkdownBody ( ) . find ( 'h1' ) . should ( 'have.text' , '\n ' )
2020-09-01 16:28:08 -04:00
} )
} )
describe ( 'images' , ( ) = > {
2021-11-19 12:04:04 -05:00
it ( 'via enter' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '!' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints' ) . should ( 'exist' )
cy . get ( '@codeinput' ) . type ( '{enter}' )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , '![image alt](https:// "title")' )
2021-01-24 14:50:51 -05:00
cy . getMarkdownBody ( )
. find ( 'p > img' )
2020-09-01 16:28:08 -04:00
. should ( 'have.attr' , 'alt' , 'image alt' )
. should ( 'have.attr' , 'src' , 'https://' )
. should ( 'have.attr' , 'title' , 'title' )
2020-08-14 07:58:59 -04:00
} )
it ( 'via doubleclick' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '!' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints > li' ) . first ( ) . dblclick ( )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , '![image alt](https:// "title")' )
2021-01-24 14:50:51 -05:00
cy . getMarkdownBody ( )
. find ( 'p > img' )
2020-09-01 16:28:08 -04:00
. should ( 'have.attr' , 'alt' , 'image alt' )
. should ( 'have.attr' , 'src' , 'https://' )
. should ( 'have.attr' , 'title' , 'title' )
2020-08-14 07:58:59 -04:00
} )
} )
2020-09-01 16:28:08 -04:00
describe ( 'links' , ( ) = > {
2021-11-19 12:04:04 -05:00
it ( 'via enter' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '[' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints' ) . should ( 'exist' )
cy . get ( '@codeinput' ) . type ( '{enter}' )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , '[link text](https:// "title") ' )
2021-01-24 14:50:51 -05:00
cy . getMarkdownBody ( )
. find ( 'p > a' )
2020-09-01 16:28:08 -04:00
. should ( 'have.text' , 'link text' )
. should ( 'have.attr' , 'href' , 'https://' )
. should ( 'have.attr' , 'title' , 'title' )
} )
it ( 'via doubleclick' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '[' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints > li' ) . first ( ) . dblclick ( )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , '[link text](https:// "title") ' )
2021-01-24 14:50:51 -05:00
cy . getMarkdownBody ( )
. find ( 'p > a' )
2020-09-01 16:28:08 -04:00
. should ( 'have.text' , 'link text' )
. should ( 'have.attr' , 'href' , 'https://' )
. should ( 'have.attr' , 'title' , 'title' )
} )
} )
describe ( 'pdf' , ( ) = > {
2021-11-19 12:04:04 -05:00
it ( 'via enter' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '{' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints' ) . should ( 'exist' )
cy . get ( '@codeinput' ) . type ( '{enter}' )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , '{%pdf https:// %}' )
cy . getMarkdownBody ( ) . find ( 'p' ) . should ( 'exist' )
2020-08-14 07:58:59 -04:00
} )
it ( 'via doubleclick' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '{' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints > li' ) . first ( ) . dblclick ( )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , '{%pdf https:// %}' )
cy . getMarkdownBody ( ) . find ( 'p' ) . should ( 'exist' )
2020-08-14 07:58:59 -04:00
} )
} )
2020-09-30 17:35:10 -04:00
2021-11-19 12:04:04 -05:00
describe ( 'collapsible blocks' , ( ) = > {
it ( 'via enter' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '<d' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints' ) . should ( 'exist' )
cy . get ( '@codeinput' ) . type ( '{enter}' )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , '</details>' ) // after selecting the hint, the last line of the inserted suggestion is active
cy . getMarkdownBody ( ) . find ( 'details' ) . should ( 'exist' )
2020-09-30 17:35:10 -04:00
} )
it ( 'via doubleclick' , ( ) = > {
2021-10-04 06:50:39 -04:00
cy . setCodemirrorContent ( '<d' )
2021-11-19 12:04:04 -05:00
cy . get ( '.CodeMirror-hints > li' ) . first ( ) . dblclick ( )
cy . get ( '.CodeMirror-hints' ) . should ( 'not.exist' )
cy . get ( '.CodeMirror-activeline > .CodeMirror-line > span' ) . should ( 'have.text' , '</details>' )
cy . getMarkdownBody ( ) . find ( 'details' ) . should ( 'exist' )
2020-09-30 17:35:10 -04:00
} )
} )
2020-08-14 07:58:59 -04:00
} )