1+ /*!
2+ Copyright (C) 2020 Evolved Binary
3+
4+ This program is free software: you can redistribute it and/or modify
5+ it under the terms of the GNU Affero General Public License as
6+ published by the Free Software Foundation, either version 3 of the
7+ License, or (at your option) any later version.
8+
9+ This program is distributed in the hope that it will be useful,
10+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ GNU Affero General Public License for more details.
13+
14+ You should have received a copy of the GNU Affero General Public License
15+ along with this program. If not, see <https://www.gnu.org/licenses/>.
16+ */
17+
18+ import { mockXML } from "./download.cy" ;
19+
20+ describe ( "Open Xdita file" , ( ) => {
21+ it ( "should open the example xdita file" , ( ) => {
22+ // First, verify the fixture file exists
23+ cy . readFile ( 'cypress/fixtures/sample.xml' ) . should ( 'exist' )
24+
25+ cy . visit ( 'http://localhost:1234/' )
26+ . get ( "#editor > div > div.ProseMirror-menubar > span:nth-child(1)" )
27+ . click ( )
28+ . get ( 'input[type="file"]' )
29+ . selectFile ( 'cypress/fixtures/sample.xml' , { force : true } )
30+ . get ( "#editor > div > div.ProseMirror > article > div > section > p" )
31+ . should ( 'contain.text' , 'A test paragraph.' )
32+ } )
33+ } ) ;
34+
35+ describe ( 'Download Xdita file' , ( ) => {
36+ it ( 'should download the current document as Xdita file' , ( ) => {
37+ // set up the entry xdita
38+ window . localStorage . setItem ( 'file' , mockXML ) ;
39+ cy . visit ( 'http://localhost:1234/' )
40+ . get ( '#saveFile' )
41+ . click ( )
42+ . readFile ( 'cypress/downloads/Petal.xml' )
43+ // compare the output to the input
44+ . should ( 'equal' , mockXML ) ;
45+ } ) ;
46+ } ) ;
47+
48+ // Undo/Redo tests
49+ describe ( "Undo/Redo" , ( ) => {
50+ beforeEach ( ( ) => {
51+ window . localStorage . setItem ( 'file' , `<?xml version="1.0" encoding="UTF-8"?>
52+ <!DOCTYPE topic PUBLIC "-//OASIS//DTD LIGHTWEIGHT DITA Topic//EN" "lw-topic.dtd">
53+ <topic id="program">
54+ <title>Test File 2</title>
55+ <body>
56+ <section>
57+ <p>A test paragraph.</p>
58+ </section>
59+ </body>
60+ </topic>` ) ;
61+ } ) ;
62+ it ( "should be able to undo and redo changes" , ( ) => {
63+ cy . visit ( 'http://localhost:1234/' )
64+ . get ( '#editor > div > div.ProseMirror > article > h1' )
65+ . click ( )
66+ cy . focused ( )
67+ . type ( 'YOLO' )
68+ . get ( '#editor > div > div.ProseMirror > article > h1' )
69+ . should ( 'contain.text' , 'Test File 2YOLO' )
70+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(5) > div' )
71+ . click ( )
72+ . get ( '#editor > div > div.ProseMirror > article > h1' )
73+ . should ( 'contain.text' , 'Test File 2' )
74+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(6) > div' )
75+ . click ( )
76+ . get ( '#editor > div > div.ProseMirror > article > h1' )
77+ . should ( 'contain.text' , 'Test File 2YOLO' ) ;
78+ } ) ;
79+
80+ it ( "undo/redo should be disabled at the start and when not possible" , ( ) => {
81+ cy . visit ( 'http://localhost:1234/' )
82+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(5) > div' )
83+ . should ( 'have.css' , 'pointer-events' , 'none' )
84+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(6) > div' )
85+ . should ( 'have.css' , 'pointer-events' , 'none' )
86+ } ) ;
87+ } ) ;
88+
89+ // bold / underline / italic / subscript / superscript tests
90+ describe ( "Text formatting" , ( ) => {
91+ beforeEach ( ( ) => {
92+ window . localStorage . setItem ( 'file' , `<?xml version="1.0" encoding="UTF-8"?>
93+ <!DOCTYPE topic PUBLIC "-//OASIS//DTD LIGHTWEIGHT DITA Topic//EN" "lw-topic.dtd">
94+ <topic id="program">
95+ <title>Test File 2</title>
96+ <body>
97+ <section>
98+ <p>A test paragraph.</p>
99+ </section>
100+ </body>
101+ </topic>` ) ;
102+ } ) ;
103+
104+ it ( "should be able to apply bold formatting" , ( ) => {
105+ cy . visit ( 'http://localhost:1234/' )
106+ //#editor > div > div.ProseMirror > article > div > section > p
107+ . get ( '#editor > div > div.ProseMirror > article > div > section > p' )
108+ . click ( )
109+ cy . focused ( )
110+ . type ( '{selectall}' )
111+ // bold button #editor > div > div.ProseMirror-menubar > span:nth-child(8) > div
112+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(8) > div' )
113+ . click ( )
114+ // the bold button should now be active
115+ // #editor > div > div.ProseMirror-menubar > span:nth-child(8) > div
116+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(8) > div' )
117+ . should ( 'have.class' , 'ProseMirror-menu-active' )
118+ . get ( '#editor > div > div.ProseMirror > article > div > section > p > strong' )
119+ . should ( 'exist' ) ;
120+ } ) ;
121+
122+ it ( "should be able to apply underline formatting" , ( ) => {
123+ cy . visit ( 'http://localhost:1234/' )
124+ //#editor > div > div.ProseMirror > article > div > section > p
125+ . get ( '#editor > div > div.ProseMirror > article > div > section > p' )
126+ . click ( )
127+ cy . focused ( )
128+ . type ( '{selectall}' )
129+ // underline button #editor > div > div.ProseMirror-menubar > span:nth-child(9) > div
130+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(9) > div' )
131+ . click ( )
132+ // the underline button should now be active
133+ // #editor > div > div.ProseMirror-menubar > span:nth-child(9) > div
134+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(9) > div' )
135+ . should ( 'have.class' , 'ProseMirror-menu-active' )
136+ . get ( '#editor > div > div.ProseMirror > article > div > section > p > u' )
137+ . should ( 'exist' ) ;
138+ } ) ;
139+
140+ it ( "should be able to apply italic formatting" , ( ) => {
141+ cy . visit ( 'http://localhost:1234/' )
142+ //#editor > div > div.ProseMirror > article > div > section > p
143+ . get ( '#editor > div > div.ProseMirror > article > div > section > p' )
144+ . click ( )
145+ cy . focused ( )
146+ . type ( '{selectall}' )
147+ // italic button #editor > div > div.ProseMirror-menubar > span:nth-child(10) > div
148+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(10) > div' )
149+ . click ( )
150+ // the italic button should now be active
151+ // #editor > div > div.ProseMirror-menubar > span:nth-child(10) > div
152+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(10) > div' )
153+ . should ( 'have.class' , 'ProseMirror-menu-active' )
154+ . get ( '#editor > div > div.ProseMirror > article > div > section > p > em' )
155+ . should ( 'exist' ) ;
156+ } ) ;
157+
158+ it ( "should be able to apply subscript formatting" , ( ) => {
159+ cy . visit ( 'http://localhost:1234/' )
160+ //#editor > div > div.ProseMirror > article > div > section > p
161+ . get ( '#editor > div > div.ProseMirror > article > div > section > p' )
162+ . click ( )
163+ cy . focused ( )
164+ . type ( '{selectall}' )
165+ // subscript button #editor > div > div.ProseMirror-menubar > span:nth-child(11) > div
166+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(11) > div' )
167+ . click ( )
168+ // the subscript button should now be active
169+ // #editor > div > div.ProseMirror-menubar > span:nth-child(11) > div
170+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(11) > div' )
171+ . should ( 'have.class' , 'ProseMirror-menu-active' )
172+ . get ( '#editor > div > div.ProseMirror > article > div > section > p > sub' )
173+ . should ( 'exist' ) ;
174+ } ) ;
175+
176+ it ( "should be able to apply superscript formatting" , ( ) => {
177+ cy . visit ( 'http://localhost:1234/' )
178+ //#editor > div > div.ProseMirror > article > div > section > p
179+ . get ( '#editor > div > div.ProseMirror > article > div > section > p' )
180+ . click ( )
181+ cy . focused ( )
182+ . type ( '{selectall}' )
183+ // superscript button #editor > div > div.ProseMirror-menubar > span:nth-child(12) > div
184+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(12) > div' )
185+ . click ( )
186+ // the superscript button should now be active
187+ // #editor > div > div.ProseMirror-menubar > span:nth-child(12) > div
188+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(12) > div' )
189+ . should ( 'have.class' , 'ProseMirror-menu-active' )
190+ . get ( '#editor > div > div.ProseMirror > article > div > section > p > sup' )
191+ . should ( 'exist' ) ;
192+ } ) ;
193+ } ) ;
194+
195+ // links to library and the prosemirror-lwdita repo
196+ describe ( "Menu links" , ( ) => {
197+ it ( "should link to the ProseMirror library" , ( ) => {
198+ cy . visit ( 'http://localhost:1234/' )
199+ // #editor > div > div.ProseMirror-menubar > span:nth-child(20)
200+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(20)' )
201+ . click ( )
202+ . url ( ) . should ( 'include' , 'https://github.com/evolvedbinary/lwdita' )
203+ } ) ;
204+
205+ it ( "should link to the prosemirror-lwdita repo" , ( ) => {
206+ cy . visit ( 'http://localhost:1234/' )
207+ // #editor > div > div.ProseMirror-menubar > span:nth-child(21)
208+ . get ( '#editor > div > div.ProseMirror-menubar > span:nth-child(21)' )
209+ . click ( )
210+ . url ( ) . should ( 'include' , 'https://github.com/evolvedbinary/prosemirror-lwdita' )
211+ } ) ;
212+ } ) ;
0 commit comments