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 = "nuclear"
5+ const email = Cypress . env ( 'COLLABORATOR_USER' )
6+ const crName = `CR_${ Date . now ( ) } `
7+ let documentID = "" , nuclearPowerPlantData = { } , branchID = { }
8+
9+ describe ( `Test document explorer UI (Edit/delete/create)` , ( ) => {
10+ const dashboard = Cypress . config ( ) . baseUrl
11+
12+ /** add this statement to stop cypress form complaining
13+ * about react-leaflet being used in terminusdb-document-ui */
14+ Cypress . on ( 'uncaught:exception' , ( err , runnable ) => {
15+ return false ;
16+ } ) ;
17+
18+ // visit dashboard-dev at the start
19+ before ( function ( ) {
20+ cy . visit ( dashboard )
21+ cy . fixture ( 'nuclearPowerPlant.json' ) . then ( function ( data ) {
22+ nuclearPowerPlantData = data ;
23+ } )
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 Terminusdb_demo team
32+ /*it('Select Team', () => {
33+ cy.selectTeam(teamName)
34+ })
35+
36+ //Clone Nuclear team
37+ it('Clone Nuclear team', () => {
38+ cy.intercept(`/${teamName}/${dataProduct}`).as('cloaning')
39+ cy.get(`button[data-cy=${CONST.CLONE_BUTTON}_${dataProduct}]`).should('exist').click();
40+ cy.wait('@cloaning')
41+ })*/
42+
43+ // Go to Document Explorer
44+ it ( "Go to Document Explorer" , ( ) => {
45+ cy . visit ( `/CYPRESS_TEST_TEAM/nuclear` )
46+ cy . get ( `a[data-cy=${ IconBarConfig . documentExplorer . key } ]` ) . should ( 'exist' ) . click ( ) ;
47+ } )
48+
49+ // Click on add a new NuclearPowerPlant
50+ /*it("Click on add a new NuclearPowerPlant", () => {
51+ cy.get(`button[data-cy=${CONST.NEW_DOCUMENT_BUTTON_ID}_NuclearPowerPlant]`).should('exist').click();
52+ cy.get(2000)
53+ // the CR modal should pop up on click of create document
54+ cy.get('.modal-dialog').should('exist')
55+ })*/
56+
57+ // Create a CR
58+ it ( "Create a CR " , ( ) => {
59+ let url = `/api/changes/${ teamName } /${ dataProduct } `
60+ cy . intercept ( {
61+ method : 'POST' ,
62+ path : url ,
63+ } ) . as ( 'getBranchName' )
64+ cy . createCR ( crName , "NuclearPowerPlant" )
65+ // create CR
66+ cy . get ( `button[data-cy=${ CONST . CREATE_CHANGE_REQUEST_BUTTON } ]` ) . should ( 'exist' ) . click ( ) ;
67+ cy . get ( 2000 )
68+ cy . wait ( '@getBranchName' ) . then ( ( interception ) => {
69+ assert . isNotNull ( interception . response . body , 'Intercepting create CR API ' )
70+ //console.log("interception.response.body", interception.response.body)
71+ branchID = interception . response . body . branchName
72+ } )
73+ } )
74+
75+ // Check if Frame Viewer of NuclearPowerPlant is loaded
76+ it ( "Check if Frame Viewer of NuclearPowerPlant is loaded" , ( ) => {
77+ // check if frame viewer loaded
78+ cy . get ( `div[data-cy=${ CONST . FRAME_VIEWER } ]` ) . should ( 'exist' ) ;
79+ cy . wait ( 1000 )
80+ } )
81+
82+ // Add Name ( test string field )
83+ it ( "Add Name ( test string field )" , ( ) => {
84+ // add name
85+ cy . get ( 'textarea[data-cy="root_name"]' ) . focus ( ) . type ( nuclearPowerPlantData . name )
86+ cy . wait ( 1000 )
87+ } )
88+
89+ // Test Linking of documents
90+ it ( "Add country (test linking a field)" , ( ) => {
91+ // add country and test linking documents
92+ cy . get ( `input[data-cy="Link an existing Document__country"]` ) . should ( 'exist' ) . click ( ) ;
93+ cy . wait ( 1000 )
94+ cy . get ( `span[data-cy="Argentina"]` ) . should ( 'exist' ) . click ( ) ;
95+ } )
96+
97+ // Delete Linked country and test if changing links works
98+ it ( "Delete Linked country and test if changing links works" , ( ) => {
99+ // after linking a document, change link button for the field should appear in dom
100+ cy . get ( `button[data-cy="delete__country"]` ) . should ( 'exist' ) . click ( ) ;
101+ cy . wait ( 1000 )
102+ } )
103+
104+ // Add country
105+ it ( "Add country" , ( ) => {
106+ // add country and test linking documents
107+ cy . get ( `input[data-cy="Link an existing Document__country"]` ) . should ( 'exist' ) . click ( ) ;
108+ cy . wait ( 1000 )
109+ cy . get ( `span[data-cy="Argentina"]` ) . should ( 'exist' ) . click ( ) ;
110+ //cy.get('span').contains(nuclearPowerPlantData.country).click();
111+ } )
112+
113+ // Add capacity
114+ it ( "Add capacity (test numeric field & linking in subdocument)" , ( ) => {
115+ // add country and test linking documents
116+ cy . get ( `input[data-cy="root_capacity_quantity"]` ) . focus ( ) . type ( nuclearPowerPlantData . capacity . quantity )
117+ cy . wait ( 1000 )
118+ // link a new unit
119+ cy . get ( `input[data-cy="Link an existing Document__unit"]` ) . should ( 'exist' ) . click ( ) ;
120+ cy . wait ( 2000 )
121+ cy . get ( `span[data-cy="US Dollar"]` ) . should ( 'exist' ) . click ( ) ;
122+ cy . wait ( 2000 )
123+ cy . get ( `button[data-cy="delete__unit"]` ) . should ( 'exist' )
124+ } )
125+
126+ // Add location
127+ it ( "Add location & test Create New Document Links" , ( ) => {
128+ // add location
129+ cy . get ( `input[data-cy="Create New Document__location"]` ) . should ( 'exist' ) . click ( ) ;
130+ // add latitude
131+ cy . get ( `input[data-cy="latitude__0"]` ) . focus ( ) . type ( nuclearPowerPlantData . location . coordinates [ 0 ] )
132+ // add longitude
133+ cy . get ( `input[data-cy="longitude__1"]` ) . focus ( ) . type ( nuclearPowerPlantData . location . coordinates [ 1 ] )
134+ // select type
135+ cy . get ( `input[id="root_location_type_1"]` ) . should ( 'exist' ) . focus ( ) . type ( `${ nuclearPowerPlantData . location . type } {enter}` )
136+ } )
137+
138+ // Add url
139+ it ( "Add url and test url field" , ( ) => {
140+ cy . get ( `textarea[data-cy="root_url"]` ) . focus ( ) . type ( nuclearPowerPlantData . url )
141+ } )
142+
143+ // Add gppd_idnr
144+ it ( "Add gppd_idnr field" , ( ) => {
145+ cy . get ( `textarea[data-cy="root_gppd_idnr"]` ) . focus ( ) . type ( nuclearPowerPlantData . gppd_idnr )
146+ } )
147+
148+ // Create new Nuclear Power Plant
149+ it ( "Create new Nuclear Power Plant" , ( ) => {
150+ const url = `/${ teamName } /api/document/${ teamName } /${ dataProduct } /local/branch/${ branchID } ?author=${ email } &message=add%20a%20new%20document`
151+ cy . intercept ( {
152+ method : 'POST' ,
153+ path : url ,
154+ } ) . as ( 'addDocument' )
155+
156+ // click on submit button to create document
157+ cy . get ( '.btn' ) . contains ( 'Submit' ) . should ( 'exist' ) . click ( ) ;
158+
159+ cy . wait ( '@addDocument' ) . then ( ( interception ) => {
160+ assert . isNotNull ( interception . response . body , 'intercepting Add Document API' )
161+ console . log ( "interception.response.body" , interception . response . body )
162+ let fullId = interception . response . body [ 0 ]
163+ documentID = btoa ( fullId )
164+ console . log ( "encoded" , documentID )
165+ //`https://dashboard.terminusdb.com/${orgName}/${dbName}/documents/${type}/${fullIdEncode}`
166+ } )
167+ cy . get ( 2000 )
168+
169+ } )
170+
171+ // View newly created nuclear power plant
172+ it ( "View newly created nuclear power plant" , ( ) => {
173+ // Get newly created Planet
174+ cy . visit ( `${ teamName } /${ dataProduct } /documents/NuclearPowerPlant/${ documentID } ` )
175+ cy . get ( 2000 )
176+ } )
177+
178+ } )
0 commit comments