1+ /**
2+ * 1) login to terminusdb
3+ * 2) select Terminusdb_demo team
4+ * 3) Clone Nuclear data product
5+ * 4) Go to Document Explorer
6+ * 5) Create a CR
7+ * 6) Check if Frame Viewer of ExperimentalReactor is loaded
8+ * 7) Add a new ExperimentalReactor
9+ * 8) Create new ExperimentalReactor
10+ * 9) Check if document were created
11+ * 10) Go to CR Page
12+ * 11) Submit the Change Request for review
13+ * 12) Review CR
14+ * 13) Check if diff page is loaded correctly
15+ * 14) Check if diff class names and UI is loaded correctly
16+ * 15) Approve CR
17+ * 16) Get newly created ExperimentalReactor
18+ * 17) Reopen the CR
19+ * 18) Edit ExperimentalReactor
20+ * 19) Unlink moderator
21+ * 20) Submit the Change Request for review
22+ * 21) Check if Update CR is prompted
23+ * 22) Check if Merge Conflict screen is prompted
24+ * 23) Merge Conflicts
25+ */
26+ import * as CONST from "../../../src/cypress.constants"
27+ import { IconBarConfig } from "../../../src/components/constants"
28+ const teamName = Cypress . env ( 'TEAM_NAME' )
29+ const dataProduct = "nuclear"
30+ const branchName = `branch__${ Date . now ( ) } `
31+ const crName = `CR__${ branchName } `
32+ const email = Cypress . env ( 'COLLABORATOR_USER' )
33+ let experimentalReactorData = { } , documentID = "" , branchID = "" , coolantSubstanceID = "" , moderatorSubstanceID = ""
34+
35+ describe ( `Change Request and Diff screens workflow` , ( ) => {
36+ const dashboard = Cypress . config ( ) . baseUrl
37+
38+ /** add this statement to stop cypress form complaining
39+ * about react-leaflet being used in terminusdb-document-ui */
40+ Cypress . on ( 'uncaught:exception' , ( err , runnable ) => {
41+ return false ;
42+ } ) ;
43+
44+ // visit dashboard-dev at the start
45+ before ( function ( ) {
46+ cy . visit ( dashboard )
47+ cy . fixture ( 'experimentalReactor.json' ) . then ( function ( data ) {
48+ experimentalReactorData = data ;
49+ } )
50+ } ) ;
51+
52+ // login to terminusdb
53+ it ( 'Check to see that you can login with an exists user' , ( ) => {
54+ cy . userLogin ( )
55+ } )
56+
57+ // select Terminusdb_demo team
58+ it ( 'Select Team' , ( ) => {
59+ cy . selectTeam ( teamName )
60+ } )
61+
62+ //Clone Nuclear data product
63+ it ( 'Clone Nuclear data product' , ( ) => {
64+ cy . intercept ( `/${ teamName } /${ dataProduct } ` ) . as ( 'cloaning' )
65+ cy . get ( `button[data-cy=${ CONST . CLONE_BUTTON } _${ dataProduct } ]` ) . should ( 'exist' ) . click ( ) ;
66+ cy . wait ( '@cloaning' )
67+ } )
68+
69+ // Go to Document Explorer
70+ it ( "Go to Document Explorer" , ( ) => {
71+ cy . visit ( `/CYPRESS_TEST_TEAM/nuclear` )
72+ cy . get ( `a[data-cy=${ IconBarConfig . documentExplorer . key } ]` ) . should ( 'exist' ) . click ( ) ;
73+ } )
74+
75+ // Create a CR
76+ it ( "Create a CR " , ( ) => {
77+ let url = `/api/changes/${ teamName } /${ dataProduct } `
78+ cy . intercept ( {
79+ method : 'POST' ,
80+ path : url ,
81+ } ) . as ( 'getBranchName' )
82+ cy . createCR ( crName , "ExperimentalReactor" )
83+ // create CR
84+ cy . get ( `button[data-cy=${ CONST . CREATE_CHANGE_REQUEST_BUTTON } ]` ) . should ( 'exist' ) . click ( ) ;
85+ cy . get ( 2000 )
86+ cy . wait ( '@getBranchName' ) . then ( ( interception ) => {
87+ assert . isNotNull ( interception . response . body , 'Intercepting create CR API ' )
88+ //console.log("interception.response.body", interception.response.body)
89+ branchID = interception . response . body . branchName
90+ } )
91+ } )
92+
93+ // Check if Frame Viewer of ExperimentalReactor is loaded
94+ it ( "Check if Frame Viewer of ExperimentalReactor is loaded" , ( ) => {
95+ // check if frame viewer loaded
96+ cy . get ( `div[data-cy=${ CONST . FRAME_VIEWER } ]` ) . should ( 'exist' ) ;
97+ cy . wait ( 1000 )
98+ } )
99+
100+ // Add a new ExperimentalReactor
101+ it ( "Add a new ExperimentalReactor" , ( ) => {
102+ // Add capacity
103+ cy . get ( `input[data-cy="root_capacity_quantity"]` ) . focus ( ) . type ( experimentalReactorData . capacity . quantity )
104+ cy . wait ( 1000 )
105+ // link a new unit
106+ cy . get ( `input[data-cy="Link an existing Document__unit"]` ) . should ( 'exist' ) . click ( ) ;
107+ cy . wait ( 2000 )
108+ cy . get ( `span[data-cy="US Dollar"]` ) . should ( 'exist' ) . click ( ) ;
109+ cy . wait ( 2000 )
110+ cy . get ( `button[data-cy="delete__unit"]` ) . should ( 'exist' )
111+
112+ // Add New coolent
113+ cy . get ( `input[data-cy="Create New Document__coolant"]` ) . should ( 'exist' ) . click ( ) ;
114+ cy . get ( `textarea[data-cy="root_coolant_name_1"]` ) . focus ( ) . type ( experimentalReactorData . coolant . name )
115+
116+ // Add New Moderator
117+ cy . get ( `input[data-cy="Create New Document__moderator"]` ) . should ( 'exist' ) . click ( ) ;
118+ cy . get ( `textarea[data-cy="root_moderator_name_1"]` ) . focus ( ) . type ( experimentalReactorData . moderator . name )
119+
120+ // Add a name
121+ cy . get ( `textarea[data-cy="root_name"]` ) . focus ( ) . type ( experimentalReactorData . name )
122+
123+ } )
124+
125+ // Create new ExperimentalReactor
126+ it ( "Create new ExperimentalReactor" , ( ) => {
127+ const url = `/${ teamName } /api/document/${ teamName } /${ dataProduct } /local/branch/${ branchID } ?author=${ email } &message=add%20a%20new%20document`
128+ cy . intercept ( {
129+ method : 'POST' ,
130+ path : url ,
131+ } ) . as ( 'addDocument' )
132+
133+ // click on submit button to create document
134+ cy . get ( '.btn' ) . contains ( 'Submit' ) . should ( 'exist' ) . click ( ) ;
135+
136+ // catch the Document ID of ExperimentalReactor
137+ cy . wait ( '@addDocument' ) . then ( ( interception ) => {
138+ assert . isNotNull ( interception . response . body , 'intercepting Add Document API' )
139+ let fullId = interception . response . body [ 0 ]
140+ documentID = btoa ( fullId )
141+ } )
142+ cy . get ( 2000 )
143+ } )
144+
145+ // Check if document were created
146+ it ( "Check if document were created " , ( ) => {
147+
148+ const url = `/${ teamName } /api/document/${ teamName } /${ dataProduct } /local/branch/${ branchID } ?id=http://lib.terminusdb.com/nuclear/ExperimentalReactor/ExperimentalReactor_test`
149+ cy . intercept ( {
150+ method : 'GET' ,
151+ path : url ,
152+ } ) . as ( 'getDocument' )
153+
154+ cy . wait ( 1000 )
155+ cy . get ( `span[data-cy="ExperimentalReactor_test"]` ) . should ( 'exist' ) . click ( ) ;
156+ // click on submit button to create document
157+ //cy.get('.btn').contains('Submit').should('exist').click();
158+
159+ // catch the Document ID of ExperimentalReactor
160+ cy . wait ( '@getDocument' ) . then ( ( interception ) => {
161+ assert . isNotNull ( interception . response . body , 'intercepting get Document API' )
162+ coolantSubstanceID = interception . response . body . coolant
163+ moderatorSubstanceID = interception . response . body . moderator
164+ } )
165+ cy . get ( 2000 )
166+
167+ } )
168+
169+ // Go to CR Page
170+ it ( "Go to CR Page" , ( ) => {
171+ cy . get ( `a[data-cy=${ IconBarConfig . changes . key } ]` ) . should ( 'exist' ) . click ( ) ;
172+ cy . get ( `button[data-cy=${ CONST . CR_READY_FOR_REVIEW } ]` ) . should ( 'exist' ) . click ( ) ;
173+ cy . get ( '.modal-dialog' ) . should ( 'exist' )
174+ } )
175+
176+ // Submit the Change Request for review
177+ it ( "Submit the Change Request for review" , ( ) => {
178+ // add CR review message
179+ cy . get ( `textarea[data-cy=${ CONST . CHANGE_REQUEST_MESSAGE_FOR_REVIEW } ]` ) . focus ( ) . type ( `${ crName } __REVIEW__MESSAGE` )
180+ // submit CR
181+ cy . get ( `button[data-cy=${ CONST . CHANGE_REQUEST_SUBMIT_REVIEW } ]` ) . should ( 'exist' ) . click ( ) ;
182+
183+ } )
184+
185+ // Review CR
186+ it ( "Review CR" , ( ) => {
187+ cy . get ( `button[data-cy=${ CONST . CHANGE_REQUEST_SUBMIT_REVIEW_FOR_DIFF } ]` ) . should ( 'exist' ) . click ( ) ;
188+ cy . wait ( 1000 )
189+ } )
190+
191+ // Check if diff page is loaded correctly
192+ it ( "Check if diff page is loaded correctly " , ( ) => {
193+ cy . get ( `button[data-cy=Approve]` ) . should ( 'exist' )
194+ cy . get ( `button[data-cy=Reject]` ) . should ( 'exist' )
195+
196+ cy . get ( `div[id="ExperimentalReactor/ExperimentalReactor_test"]` ) . should ( 'exist' )
197+
198+
199+ cy . get ( `div[id="${ coolantSubstanceID } "]` ) . should ( 'exist' )
200+ cy . get ( `div[id="${ moderatorSubstanceID } "]` ) . should ( 'exist' )
201+
202+ } )
203+
204+ // Check if diff class names and UI is loaded correctly
205+ it ( "Check if diff class names and UI is loaded correctly " , ( ) => {
206+ cy . get ( `div[id="ExperimentalReactor/ExperimentalReactor_test"]` ) . click ( )
207+ cy . get ( `.tdb__diff__inserted` ) . should ( 'exist' )
208+ cy . get ( `div[id="ExperimentalReactor/ExperimentalReactor_test"]` ) . click ( { force : true } )
209+ } )
210+
211+
212+ // Approve CR
213+ it ( "Approve CR" , ( ) => {
214+ cy . get ( `textarea[data-cy=${ CONST . CR_ACTION_MESSAGEBOX } ]` ) . first ( ) . focus ( ) . type ( `APPROVE ${ crName } ` ) ;
215+ cy . get ( `button[data-cy=Approve]` ) . should ( 'exist' ) . click ( ) ;
216+ } )
217+
218+ // Get newly created ExperimentalReactor
219+ it ( "Get newly created ExperimentalReactor" , ( ) => {
220+ cy . visit ( `${ teamName } /${ dataProduct } /documents/ExperimentalReactor/${ documentID } ` )
221+ } )
222+
223+ // Reopen the CR
224+ it ( "Reopen the CR " , ( ) => {
225+
226+ cy . get ( `a[data-cy=${ IconBarConfig . changes . key } ]` ) . should ( 'exist' ) . click ( ) ;
227+ cy . get ( `button[data-cy=${ CONST . MERGED_CR } ]` ) . should ( 'exist' ) . click ( ) ;
228+ cy . wait ( 2000 )
229+ cy . get ( `button` ) . contains ( `Reopen` ) . should ( 'exist' ) . click ( ) ;
230+ cy . get ( '.modal-dialog' ) . should ( 'exist' )
231+ cy . get ( `textarea[data-cy="cr_message_for_review"]` ) . focus ( ) . type ( `Reopening ${ crName } message` )
232+ cy . get ( `button` ) . contains ( `Submit change request` ) . should ( 'exist' ) . click ( ) ;
233+ cy . get ( `button[data-cy=${ CONST . CR_KEEP_EDITING } ]` ) . should ( 'exist' ) . click ( ) ;
234+ } )
235+
236+ // Go to Document Explorer
237+ it ( "Go to Document Explorer" , ( ) => {
238+ cy . get ( `a[data-cy=${ IconBarConfig . documentExplorer . key } ]` ) . should ( 'exist' ) . click ( ) ;
239+ } )
240+
241+ // Edit ExperimentalReactor
242+ it ( "Edit ExperimentalReactor" , ( ) => {
243+ cy . get ( `button[id="ExperimentalReactor"]` ) . should ( 'exist' ) . click ( ) ;
244+ cy . get ( `span[data-cy="ExperimentalReactor_test"]` ) . should ( 'exist' ) . click ( ) ;
245+ cy . get ( `button[data-cy="edit__document"]` ) . should ( 'exist' ) . click ( )
246+ } )
247+
248+ // Unlink moderator
249+ it ( "Unlink moderator " , ( ) => {
250+ cy . get ( `button[data-cy="delete__moderator"]` ) . should ( 'exist' ) . click ( ) ;
251+ // select type
252+ cy . get ( `input[id="root_type"]` ) . should ( 'exist' ) . focus ( ) . type ( `${ experimentalReactorData . type } {enter}` )
253+ cy . get ( '.btn' ) . contains ( 'Submit' ) . should ( 'exist' ) . click ( ) ;
254+ cy . wait ( 2000 )
255+ } )
256+
257+ // Go to CR Page
258+ it ( "Go to CR Page" , ( ) => {
259+ cy . get ( `a[data-cy=${ IconBarConfig . changes . key } ]` ) . should ( 'exist' ) . click ( ) ;
260+ cy . get ( `button[data-cy=${ CONST . CR_READY_FOR_REVIEW } ]` ) . should ( 'exist' ) . click ( ) ;
261+ cy . get ( '.modal-dialog' ) . should ( 'exist' )
262+ } )
263+
264+ // Submit the Change Request for review
265+ it ( "Submit the Change Request for review" , ( ) => {
266+ // add CR review message
267+ cy . get ( `textarea[data-cy=${ CONST . CHANGE_REQUEST_MESSAGE_FOR_REVIEW } ]` ) . focus ( ) . type ( `${ crName } __REVIEW__EDIT__MESSAGE` )
268+ // submit CR
269+ cy . get ( `button[data-cy=${ CONST . CHANGE_REQUEST_SUBMIT_REVIEW } ]` ) . should ( 'exist' ) . click ( ) ;
270+
271+ } )
272+
273+ // Review CR
274+ it ( "Review CR" , ( ) => {
275+ cy . get ( `button[data-cy=${ CONST . CHANGE_REQUEST_SUBMIT_REVIEW_FOR_DIFF } ]` ) . should ( 'exist' ) . click ( ) ;
276+ cy . wait ( 1000 )
277+ } )
278+
279+ // Check if Update CR is prompted
280+ it ( "Check if Update CR is prompted" , ( ) => {
281+ cy . get ( 'h3' ) . contains ( `This Change Request is out of date` ) . should ( 'exist' )
282+ cy . get ( `button` ) . contains ( `Update Change Request` ) . should ( 'exist' ) . click ( ) ;
283+ cy . wait ( 2000 )
284+ cy . get ( `button` ) . contains ( `Resolve Conflict` ) . should ( 'exist' ) . click ( ) ;
285+ cy . wait ( 2000 )
286+ } )
287+
288+ // Check if Merge Conflict screen is prompted
289+ it ( "Check if Merge Conflict screen is prompted" , ( ) => {
290+ cy . get ( `button` ) . contains ( `Merge Conflicts` ) . should ( 'exist' )
291+ cy . get ( `button` ) . contains ( `Reject Conflicts` ) . should ( 'exist' )
292+ cy . get ( `button` ) . contains ( `Reopen CR` ) . should ( 'exist' )
293+ cy . get ( `div[id="ExperimentalReactor/ExperimentalReactor_test"]` ) . click ( )
294+ cy . wait ( 2000 )
295+ cy . get ( `div[data-cy="${ moderatorSubstanceID } "]` ) . should ( 'exist' )
296+ . should ( 'satisfy' , ( $el ) => {
297+ const classList = Array . from ( $el [ 0 ] . classList ) ;
298+ return classList . includes ( 'tdb__diff__original-underline' )
299+ } )
300+
301+ cy . get ( `div[data-cy="deleted__moderator"]` ) . should ( 'exist' )
302+
303+ } )
304+
305+ // Merge Conflicts
306+ it ( "Merge Conflicts" , ( ) => {
307+ cy . get ( `button` ) . contains ( `Merge Conflicts` ) . should ( 'exist' ) . click ( )
308+ } )
309+
310+ // delete dataProduct
311+ it ( 'Delete dataProduct' , ( ) => {
312+ cy . visit ( `/${ teamName } /${ dataProduct } ` )
313+ cy . deleteDataProduct ( dataProduct )
314+ } )
315+
316+ it ( 'Logout' , ( ) => {
317+ cy . logout ( )
318+ } )
319+
320+
321+ } )
0 commit comments