1+ import * as CONST from "../../../src/cypress.constants"
2+ import { IconBarConfig } from "../../../src/components/constants"
3+ const teamName = Cypress . env ( 'TEAM_NAME' )
4+ const dataProduct = "star_wars"
5+ const branchName = `branch__${ Date . now ( ) } `
6+ const crName = `CR__${ branchName } `
7+ const email = Cypress . env ( 'COLLABORATOR_USER' )
8+ let planetData = { } , documentID = "" , branchID = ""
9+
10+ describe ( `Test to check Branch Management workflow` , ( ) => {
11+ const dashboard = Cypress . config ( ) . baseUrl
12+
13+ /** add this statement to stop cypress form complaining
14+ * about react-leaflet being used in terminusdb-document-ui */
15+ Cypress . on ( 'uncaught:exception' , ( err , runnable ) => {
16+ return false ;
17+ } ) ;
18+
19+ // visit dashboard-dev at the start
20+ before ( function ( ) {
21+ cy . visit ( dashboard )
22+ cy . fixture ( 'starWarsPlanet.json' ) . then ( function ( data ) {
23+ planetData = data ;
24+ } )
25+ } ) ;
26+
27+ // login to terminusdb
28+ it ( 'Check to see that you can login with an exists user' , ( ) => {
29+ cy . userLogin ( )
30+ } )
31+
32+ // select Terminusdb_demo team
33+ it ( 'Select Team' , ( ) => {
34+ cy . selectTeam ( teamName )
35+ } )
36+
37+ //Clone Starwars team
38+ it ( 'Clone Starwars team' , ( ) => {
39+ cy . intercept ( `/${ teamName } /${ dataProduct } ` ) . as ( 'cloaning' )
40+ cy . get ( `button[data-cy=${ CONST . CLONE_BUTTON } _${ dataProduct } ]` ) . should ( 'exist' ) . click ( ) ;
41+ cy . wait ( '@cloaning' )
42+ } )
43+
44+
45+ // Create New Branch
46+ it ( 'Create New Branch' , ( ) => {
47+
48+ cy . visit ( `/CYPRESS_TEST_TEAM/star_wars` )
49+
50+ // Activate Change Request
51+ cy . get ( `label[data-cy=${ CONST . CHANGE_REQUEST_MODE_ACTIVE } ]` ) . should ( 'exist' ) . click ( ) ;
52+ cy . get ( `button[data-cy=${ CONST . BRANCH_MANAGEMENT_BUTTON_ID } ]` ) . should ( 'exist' ) . click ( ) ;
53+ // create
54+ cy . get ( `button[data-cy=${ CONST . NEW_BRANCH_BUTTON_ID } ]` ) . should ( 'exist' ) . click ( ) ;
55+ // the Branch modal should pop up
56+ cy . get ( '.modal-dialog' ) . should ( 'exist' )
57+ // Input branch ID
58+ cy . get ( `input[data-cy=${ CONST . BRANCH_ID_INPUT } ]` ) . should ( 'exist' ) . type ( branchName ) ;
59+ // force click here on modal since branch id input change is an onBlur()
60+ cy . get ( `.modal-body` ) . should ( 'exist' ) . click ( ) ;
61+ // create new branch
62+ cy . get ( `button[data-cy=${ CONST . CREATE_BRANCH_BUTTON_ID } ]` ) . should ( 'exist' ) . click ( ) ;
63+ } )
64+
65+ it ( 'Check if Branch created' , ( ) => {
66+ // check if data product is set to new branch id
67+ cy . get ( `span[data-cy=${ CONST . CURRENT_BRANCH_BADGE } ]` ) . should ( 'have.text' , branchName )
68+ } )
69+
70+ // Go to Document Explorer
71+ it ( "Go to Document Explorer" , ( ) => {
72+ cy . get ( `a[data-cy=${ IconBarConfig . documentExplorer . key } ]` ) . should ( 'exist' ) . click ( ) ;
73+ } )
74+
75+ // Create a new CR
76+ it ( "Create a new CR" , ( ) => {
77+ const url = `/api/changes/${ teamName } /${ dataProduct } `
78+ cy . intercept ( {
79+ method : 'POST' ,
80+ path : url ,
81+ } ) . as ( 'getBranchName' )
82+ cy . createCR ( crName , "Planet" )
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+ // Click on add a new Planet
94+ it ( "Add new Planet" , ( ) => {
95+ const url = `/${ teamName } /api/document/${ teamName } /${ dataProduct } /local/branch/${ branchID } ?author=${ email } &message=add%20a%20new%20document`
96+ cy . intercept ( {
97+ method : 'POST' ,
98+ path : url ,
99+ } ) . as ( 'addDocument' )
100+
101+ // check if frame viewer loaded
102+ cy . get ( `div[data-cy=${ CONST . FRAME_VIEWER } ]` ) . should ( 'exist' ) ;
103+
104+ // add label as markdown
105+ cy . get ( 'textarea[data-cy="root_label"]' ) . focus ( ) . type ( planetData . label )
106+ // add orbital_period
107+ cy . get ( 'input[data-cy="root_orbital_period"]' ) . focus ( ) . type ( planetData . orbital_period )
108+ // add diameter
109+ cy . get ( 'input[data-cy="root_diameter"]' ) . focus ( ) . type ( planetData . diameter )
110+ // add gravity
111+ cy . get ( 'textarea[data-cy="root_gravity"]' ) . focus ( ) . type ( planetData . gravity )
112+ // add climate
113+ cy . get ( 'textarea[data-cy="root_climate"]' ) . focus ( ) . type ( planetData . climate )
114+
115+ // click on submit button to create document
116+ cy . get ( '.btn' ) . contains ( 'Submit' ) . should ( 'exist' ) . click ( ) ;
117+ cy . wait ( 1000 )
118+
119+ cy . wait ( '@addDocument' ) . then ( ( interception ) => {
120+ assert . isNotNull ( interception . response . body , 'intercepting Add Document API' )
121+ //console.log("interception.response.body", interception.response.body)
122+ documentID = interception . response . body . branchName
123+ } )
124+
125+ } )
126+
127+ // Submit CR for Review
128+ it ( "Submit CR for Review" , ( ) => {
129+ cy . visit ( `${ teamName } /${ dataProduct } /change_requests` )
130+ cy . get ( `button[data-cy=${ CONST . CR_READY_FOR_REVIEW } ]` ) . should ( 'exist' ) . click ( ) ;
131+ // CR Modal for review should pop up
132+ cy . get ( `.modal-body` ) . should ( 'exist' ) . click ( ) ;
133+ // add CR review message
134+ cy . get ( `textarea[data-cy=${ CONST . CHANGE_REQUEST_MESSAGE_FOR_REVIEW } ]` ) . focus ( ) . type ( `${ crName } __REVIEW__MESSAGE` )
135+ // submit CR
136+ cy . get ( `button[data-cy=${ CONST . CHANGE_REQUEST_SUBMIT_REVIEW } ]` ) . should ( 'exist' ) . click ( ) ;
137+ } )
138+
139+ // Review CR
140+ it ( "Review CR" , ( ) => {
141+ //cy.isCorrectURL(`${teamName}/${dataProduct}/change_requests`)
142+ cy . get ( `button[data-cy=${ CONST . CHANGE_REQUEST_SUBMIT_REVIEW_FOR_DIFF } ]` ) . should ( 'exist' ) . click ( ) ;
143+ cy . wait ( 1000 )
144+ // Aprove CR
145+ cy . get ( `button[data-cy=Approve]` ) . should ( 'exist' ) . click ( ) ;
146+ //cy.isCorrectURL(`${teamName}/${dataProduct}/change_requests?status=Merged`)
147+ } )
148+
149+ // Get newly created Planet
150+ it ( "Get newly created Planet" , ( ) => {
151+ cy . visit ( `${ teamName } /${ dataProduct } /documents/Planet/${ documentID } ` )
152+ } )
153+
154+ // Switch to main branch
155+ it ( "Switch to main branch" , ( ) => {
156+ cy . visit ( `/${ teamName } /${ dataProduct } ` )
157+ // click on branches
158+ cy . get ( `button[data-cy=${ CONST . BRANCH_MANAGEMENT_BUTTON_ID } ]` ) . should ( 'exist' ) . click ( ) ;
159+ // switch to main
160+ cy . get ( `span[data-cy=${ CONST . SWITCH_BRANCH_ID } __main]` ) . should ( 'exist' ) . click ( ) ;
161+ cy . get ( `span[data-cy=${ CONST . CURRENT_BRANCH_BADGE } ]` ) . should ( 'have.text' , "main" )
162+ } )
163+
164+ // Check if newly created Planet exists in main branch - api call should result in 404
165+ it ( "Check if newly created Planet exists in main branch" , ( ) => {
166+ cy . visit ( `${ teamName } /${ dataProduct } /documents/Planet/${ documentID } ` )
167+ const url = `/${ teamName } /api/document/${ teamName } /${ dataProduct } /local/branch/main?id=${ documentID } `
168+ cy . intercept ( {
169+ method : 'GET' ,
170+ path : url ,
171+ } ) . as ( 'getDocument' )
172+
173+ cy . wait ( '@getDocument' ) . its ( 'response.statusCode' ) . should ( 'eq' , 404 )
174+ } )
175+
176+
177+ // delete dataProduct
178+ it ( 'Delete dataProduct' , ( ) => {
179+ cy . visit ( `/${ teamName } /${ dataProduct } ` )
180+ cy . deleteDataProduct ( dataProduct )
181+ } )
182+
183+ it ( 'Logout' , ( ) => {
184+ cy . logout ( )
185+ } )
186+
187+
188+
189+ } )
0 commit comments