1+ import * as CONST from "../../../src/cypress.constants"
2+ const dataProduct = `test__${ Date . now ( ) } `
3+ import { IconBarConfig } from "../../../src/components/constants"
4+ const teamName = Cypress . env ( 'TEAM_NAME' )
5+ const branchName = `branch__${ Date . now ( ) } `
6+ const crName = `CR__${ branchName } `
7+ const email = Cypress . env ( 'COLLABORATOR_USER' )
8+ const documentName = `test__document` , propertyName = `test__document__name`
9+ const schemaSaveCommitMessage = `Update from model builder`
10+ let branchID = ""
11+
12+ describe ( `Test time travel widget` , ( ) => {
13+ const dashboard = Cypress . config ( ) . baseUrl
14+
15+ /** add this statement to stop cypress form complaining
16+ * about react-leaflet being used in terminusdb-document-ui */
17+ Cypress . on ( 'uncaught:exception' , ( err , runnable ) => {
18+ return false ;
19+ } ) ;
20+
21+ // visit dashboard-dev at the start
22+ before ( function ( ) {
23+ cy . visit ( dashboard )
24+ } ) ;
25+
26+ // login to terminusdb
27+ it ( 'Check to see that you can login with an exists user' , ( ) => {
28+ cy . userLogin ( )
29+ } )
30+
31+ // select a team
32+ it ( 'Select Team' , ( ) => {
33+ cy . selectTeam ( teamName )
34+ } )
35+
36+ // Create a new data product
37+ it ( 'Create a new dataProduct' , ( ) => {
38+ cy . newDataProduct ( teamName , dataProduct )
39+ } )
40+
41+ // Go to Product Model Page
42+ it ( "Go to Product Model Page" , ( ) => {
43+ cy . get ( `a[data-cy=${ IconBarConfig . dataProductModal . key } ]` ) . should ( 'exist' ) . click ( ) ;
44+ cy . wait ( 2000 )
45+ } )
46+
47+ // Add a new document
48+ it ( "Add a new document" , ( ) => {
49+ cy . get ( `button[id="add_new_to_schema_button"]` ) . should ( 'exist' ) . click ( ) ;
50+ cy . get ( `a[data-cy="add_new_document"]` ) . should ( 'exist' ) . click ( ) ;
51+ cy . get ( `.RRT__container` ) . should ( 'exist' )
52+
53+ cy . get ( `input[id="id"]` ) . focus ( ) . type ( documentName )
54+ } )
55+
56+ // Add a string property to document
57+ it ( "Add a string property to document" , ( ) => {
58+ cy . get ( `div[id="tab-2"]` ) . should ( 'exist' ) . click ( ) ;
59+ cy . get ( `button[id="add_property"]` ) . should ( 'exist' ) . click ( ) ;
60+ cy . get ( `a[id="StringProperty"]` ) . should ( 'exist' ) . click ( ) ;
61+ cy . get ( `.tdb__panel__box--edit` ) . should ( 'exist' )
62+ cy . get ( `input[id="id"]` ) . focus ( ) . type ( propertyName )
63+ } )
64+
65+ //Add a commit message and save document
66+ it ( "Add a commit message and save document" , ( ) => {
67+ cy . get ( `input[data-cy="schema_save_description"]` ) . should ( 'exist' )
68+
69+
70+ const url = `/${ teamName } /api/document/${ teamName } /${ dataProduct } /local/branch/main?graph_type=schema&full_replace=true&author=${ email } &message=Update%20from%20model%20builder`
71+ cy . intercept ( {
72+ method : 'POST' ,
73+ path : url ,
74+ } ) . as ( 'saveSchema' )
75+
76+ cy . get ( `button[data-cy="schema_save_button"]` ) . should ( 'exist' ) . click ( ) ;
77+
78+ cy . wait ( '@saveSchema' )
79+ } )
80+
81+ // Click on time travel widget to see the first commit
82+ it ( "Click on time travel widget to see the first commit" , ( ) => {
83+ const url = `/${ teamName } /api/woql/${ teamName } /${ dataProduct } /local/branch/main`
84+ cy . intercept ( {
85+ method : 'POST' ,
86+ path : url ,
87+ } ) . as ( 'getCommit' )
88+
89+
90+ cy . get ( `button[data-cy="time_travel_widget_id"]` ) . should ( 'exist' ) . click ( ) ;
91+ cy . wait ( '@getCommit' )
92+ //cy.get('h6').contains(schemaSaveCommitMessage)
93+ } )
94+
95+ // Go to Document Explorer
96+ it ( "Go to Document Explorer" , ( ) => {
97+ cy . get ( `a[data-cy=${ IconBarConfig . documentExplorer . key } ]` ) . should ( 'exist' ) . click ( ) ;
98+ } )
99+
100+ // Create a CR
101+ it ( "Create a CR " , ( ) => {
102+ let url = `/api/changes/${ teamName } /${ dataProduct } `
103+ cy . intercept ( {
104+ method : 'POST' ,
105+ path : url ,
106+ } ) . as ( 'getBranchName' )
107+ cy . createCR ( crName , documentName )
108+ // create CR
109+ cy . get ( `button[data-cy=${ CONST . CREATE_CHANGE_REQUEST_BUTTON } ]` ) . should ( 'exist' ) . click ( ) ;
110+ cy . get ( 2000 )
111+ cy . wait ( '@getBranchName' ) . then ( ( interception ) => {
112+ assert . isNotNull ( interception . response . body , 'Intercepting create CR API ' )
113+ //console.log("interception.response.body", interception.response.body)
114+ branchID = interception . response . body . branchName
115+ } )
116+ } )
117+
118+ // Check if Frame Viewer is loaded and add 3 new documents
119+ it ( "Check if Frame Viewer is loaded and add 3 new documents" , ( ) => {
120+ // check if frame viewer loaded
121+ cy . get ( `div[data-cy=${ CONST . FRAME_VIEWER } ]` ) . should ( 'exist' ) ;
122+ cy . wait ( 1000 )
123+
124+ // first entry
125+ cy . get ( `textarea[data-cy="root_${ propertyName } "]` ) . focus ( ) . type ( `${ propertyName } __1` )
126+ cy . get ( '.btn' ) . contains ( 'Submit' ) . should ( 'exist' ) . click ( ) ;
127+ cy . wait ( 1000 )
128+
129+ // second entry
130+ cy . get ( `button[data-cy="new_document_${ documentName } "]` ) . should ( 'exist' ) . click ( ) ;
131+ cy . get ( `textarea[data-cy="root_${ propertyName } "]` ) . focus ( ) . type ( `${ propertyName } __2` )
132+ cy . get ( '.btn' ) . contains ( 'Submit' ) . should ( 'exist' ) . click ( ) ;
133+ cy . wait ( 1000 )
134+
135+ // third entry
136+ cy . get ( `button[data-cy="new_document_${ documentName } "]` ) . should ( 'exist' ) . click ( ) ;
137+ cy . get ( `textarea[data-cy="root_${ propertyName } "]` ) . focus ( ) . type ( `${ propertyName } __3` )
138+ cy . get ( '.btn' ) . contains ( 'Submit' ) . should ( 'exist' ) . click ( ) ;
139+ cy . wait ( 1000 )
140+
141+ } )
142+
143+ // Click on time travel widget to see 3 commits where new documents were added
144+ it ( "Click on time travel widget to see 3 commits where new documents were added" , ( ) => {
145+ cy . get ( `button[data-cy="time_travel_widget_id"]` ) . should ( 'exist' ) . click ( ) ;
146+ cy . wait ( 2000 )
147+ cy . get ( '.time-travel-card' ) . find ( 'h6' ) . contains ( `add a new document` ) . should ( 'exist' )
148+ cy . get ( `button[data-cy="close__time__travel__widget"]` ) . should ( 'exist' ) . click ( { force : true } ) ;
149+ } )
150+
151+ // Check if Document Table has three entries as well
152+ it ( "Check if Document Table has three entries as well" , ( ) => {
153+ cy . get ( "table tbody" ) . find ( "tr" ) . then ( ( row ) => {
154+ expect ( row . length ) . eq ( 3 )
155+ } ) ;
156+ } )
157+
158+ // Click on time travel widget and jump to a commit where no instances of document were created
159+ it ( "Click on time travel widget and jump to a commit where no instances of document were created" , ( ) => {
160+ cy . get ( `button[data-cy="time_travel_widget_id"]` ) . should ( 'exist' ) . click ( ) ;
161+ cy . wait ( 5000 )
162+ cy . get ( `button[id="time_travel_to_${ schemaSaveCommitMessage } "]` ) . should ( 'exist' ) . click ( ) ;
163+ cy . wait ( 5000 )
164+ cy . get ( `button[id="time_travel_to_${ schemaSaveCommitMessage } "]` ) . should ( 'not.exist' )
165+ cy . get ( 'h6' ) . contains ( `You are at this point in time` ) . should ( 'exist' )
166+ // Check if Document Table has 0 entry
167+ cy . get ( "table tbody" ) . find ( "tr" ) . should ( "not.exist" )
168+ } )
169+
170+ // Select reset button of time travel widget
171+ it ( "Select reset button of time travel widget" , ( ) => {
172+ cy . get ( `button[data-cy="roll_back_to_head"]` ) . should ( 'exist' ) . click ( { force : true } ) ;
173+ cy . wait ( 4000 )
174+ } )
175+
176+ // Check if Document Table has three entries and has been reset to the head of the branch
177+ it ( "Check if Document Table has three entries and has been reset to the head of the branch" , ( ) => {
178+ cy . get ( "table tbody" ) . find ( "tr" ) . then ( ( row ) => {
179+ expect ( row . length ) . eq ( 3 )
180+ } ) ;
181+ } )
182+
183+ // delete dataProduct
184+ it ( 'Delete dataProduct' , ( ) => {
185+ cy . visit ( `/${ teamName } /${ dataProduct } ` )
186+ cy . deleteDataProduct ( dataProduct )
187+ } )
188+
189+ it ( 'Logout' , ( ) => {
190+ cy . logout ( )
191+ } )
192+
193+ } )
0 commit comments