Skip to content

Commit 38d054f

Browse files
committed
tests
1 parent 3c5ff91 commit 38d054f

File tree

19 files changed

+279
-24
lines changed

19 files changed

+279
-24
lines changed

packages/tdb-dashboard/cypress.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"viewportWidth"; 1440,
33
"viewportHeight"; 900,
44
//"baseUrl";"http://localhost:3030/",
5-
"responseTimeout";120000,
5+
//"responseTimeout";120000,
6+
"responseTimeout";5000,
67
"chromeWebSecurity"; false,
78

89
"env"; {

packages/tdb-dashboard/cypress/e2e/dashboard/branch_management.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe(`Test to check Branch Management workflow`, () => {
7979
method: 'POST',
8080
path: url,
8181
}).as('getBranchName')
82-
cy.createCR(crName)
82+
cy.createCR(crName, "Planet")
8383
// create CR
8484
cy.get(`button[data-cy=${CONST.CREATE_CHANGE_REQUEST_BUTTON}]`).should('exist').click();
8585
cy.get(2000)

packages/tdb-dashboard/cypress/e2e/dashboard/document_history.cy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe(`Test Document History Widget`, () => {
6969
method: 'POST',
7070
path: url,
7171
}).as('getBranchName')
72-
cy.createCR(crName)
72+
cy.createCR(crName, "Planet")
7373
// create CR
7474
cy.get(`button[data-cy=${CONST.CREATE_CHANGE_REQUEST_BUTTON}]`).should('exist').click();
7575
cy.get(2000)
@@ -92,7 +92,7 @@ describe(`Test Document History Widget`, () => {
9292
})
9393

9494
// Edit Planet's orbital_period second time
95-
it("Edit Planet's orbital_period second time", () => {
95+
/*it("Edit Planet's orbital_period second time", () => {
9696
cy.visit(`${teamName}/${dataProduct}/documents/Planet/dGVybWludXNkYjovLy9zdGFyLXdhcnMvUGxhbmV0LzE=`)
9797
cy.get(`button[data-cy=edit__document]`).should('exist').click();
9898
// edit orbital_period, concatinate 1
@@ -113,7 +113,7 @@ describe(`Test Document History Widget`, () => {
113113
// click on submit button to submit changes
114114
cy.get('.btn').contains('Submit').should('exist').click();
115115
cy.wait(1000)
116-
})
116+
})*/
117117

118118

119119
/*it("Intercept History calls", () => {
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
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+
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"@id": "NuclearPowerPlant/ASCO%20GR_test",
3+
"@type": "NuclearPowerPlant",
4+
"name": "ASCO GR_test",
5+
"capacity": {
6+
"@id": "NuclearPowerPlant/ASCO%20GR_test/capacity/Quantity/http%3A%2F%2Flib.terminusdb.com%2Fnuclear%2FUnit%2FMWe+1990.5",
7+
"@type": "Quantity",
8+
"quantity": "1990.5",
9+
"unit": "Unit/$"
10+
},
11+
"commissioning_year": "1983",
12+
"country": "Country/Argentina",
13+
"gppd_idnr": "WRI1006213",
14+
"location": {
15+
"@id": "Point/03d8f091c3aebad2d43effb153fcfea06e1754485421cab90c10fc3f821646c4",
16+
"@type": "Point",
17+
"coordinates": [
18+
0.5679,
19+
41.2008
20+
],
21+
"type": "Point"
22+
},
23+
"output": [
24+
{
25+
"@id": "NuclearPowerPlant/ASCO%20GR_test/output/AnnualOutput/2015",
26+
"@type": "AnnualOutput",
27+
"output": {
28+
"@id": "NuclearPowerPlant/ASCO%20GR_test/output/NuclearPowerPlant/ASCO%20GR_test/output/AnnualOutput/2015/output/Quantity/http%3A%2F%2Flib.terminusdb.com%2Fnuclear%2FUnit%2FGWh+15802.182",
29+
"@type": "Quantity",
30+
"quantity": "15802.182",
31+
"unit": "Unit/GWh"
32+
},
33+
"year": "2015"
34+
},
35+
{
36+
"@id": "NuclearPowerPlant/ASCO%20GR_test/output/AnnualOutput/2016",
37+
"@type": "AnnualOutput",
38+
"output": {
39+
"@id": "NuclearPowerPlant/ASCO%20GR_test/output/NuclearPowerPlant/ASCO%20GR_test/output/AnnualOutput/2016/output/Quantity/http%3A%2F%2Flib.terminusdb.com%2Fnuclear%2FUnit%2FGWh+16029.262",
40+
"@type": "Quantity",
41+
"quantity": "16029.262",
42+
"unit": "Unit/GWh"
43+
},
44+
"year": "2016"
45+
},
46+
{
47+
"@id": "NuclearPowerPlant/ASCO%20GR_test/output/AnnualOutput/2017",
48+
"@type": "AnnualOutput",
49+
"output": {
50+
"@id": "NuclearPowerPlant/ASCO%20GR_test/output/NuclearPowerPlant/ASCO%20GR_test/output/AnnualOutput/2017/output/Quantity/http%3A%2F%2Flib.terminusdb.com%2Fnuclear%2FUnit%2FGWh+15241.801",
51+
"@type": "Quantity",
52+
"quantity": "15241.801",
53+
"unit": "Unit/GWh"
54+
},
55+
"year": "2017"
56+
}
57+
],
58+
"owner": "ENDESA GENERACION S.A.",
59+
"url": "http://www.ree.es/en/statistical-data-of-spanish-electrical-system/annual-report/preliminary-report-spanish-electricity-system-2015"
60+
}

packages/tdb-dashboard/cypress/support/commands.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ Cypress.Commands.add('deleteDataProduct', (dataProduct) => {
8181
})
8282

8383
/** create a CR */
84-
Cypress.Commands.add('createCR', (crName) => {
85-
cy.get(`button[data-cy=${CONST.NEW_DOCUMENT_BUTTON_ID}_Planet]`).should('exist').click();
84+
Cypress.Commands.add('createCR', (crName, type) => {
85+
cy.get(`button[data-cy=${CONST.NEW_DOCUMENT_BUTTON_ID}_${type}]`).should('exist').click();
8686
cy.get(2000)
8787
// the CR modal should not pop up on click of create document
8888
cy.get('.modal-dialog').should('exist')

packages/tdb-dashboard/src/components/DatabaseList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const DataProductItems = (props) => {
3131
const {page,organization} = getLocation()
3232
const currentPage = page ? `/${page}` : ""
3333
navigate(`/${organization}/`+dp.name+currentPage)
34-
setDataProduct(dp.name)
34+
setDataProduct(dp.name)
3535
}
3636

3737
const DataProductMenu = ({handleClick, item}) => {

packages/tdb-dashboard/src/components/JSONModelBuilder.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { BiUndo } from "react-icons/bi"
1313
import { BsSave } from "react-icons/bs"
1414
import {FaRegEdit, FaSave} from 'react-icons/fa'
1515
import {TERMINUS_DANGER,DOCUMENT_PREFIX} from "./constants"
16-
import {GRAPH_TAB} from "../pages/constants"
16+
import {GRAPH_TAB, DOCUMENT_TAB} from "../pages/constants"
1717
import {GraphContextObj} from "@terminusdb-live/tdb-react-components"
1818
import {CopyButton} from "./utils"
1919
import Card from "react-bootstrap/Card"
@@ -37,7 +37,7 @@ export const JSONModelBuilder = ({tab,accessControlEditMode}) => {
3737

3838
let branch = "main"
3939
let ref = ""
40-
40+
4141

4242
const {saveGraphChanges,
4343
reportMessage,
@@ -62,7 +62,8 @@ export const JSONModelBuilder = ({tab,accessControlEditMode}) => {
6262
}
6363

6464
useEffect(() => {
65-
if(tab == GRAPH_TAB) return
65+
if(tab === GRAPH_TAB) return
66+
if(tab === DOCUMENT_TAB) return
6667
loadSchema()
6768
}, [tab,dataProduct,mainGraphObj])
6869

packages/tdb-dashboard/src/pages/ModelBuilder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const ModelBuilderViewControl = () => {
8383

8484
}
8585

86-
export const ModelBuilder = () => {
86+
export const ModelBuilder = () => {
8787

8888
const { woqlClient, branch, ref, accessControlDashboard, currentChangeRequest, collapseSideBar, selectedMode } = WOQLClientObj()
8989
if(!woqlClient) return ""
@@ -149,7 +149,7 @@ export const ModelBuilder = () => {
149149

150150
{!callServerLoading && selectedMode === JSON_TAB && <div className="ml-5 mr-5">
151151
<div className={collapseSideBar ? "ml-5" : ""}>
152-
<JSONModelBuilder accessControlEditMode={isEditMode} tab={tab} />
152+
<JSONModelBuilder accessControlEditMode={isEditMode} tab={selectedMode} />
153153
</div>
154154
</div>}
155155

packages/tdb-dashboard/src/pages/ModelProductPage.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React from "react"
1+
import React, {useEffect} from "react"
22
import { ModelBuilder } from "./ModelBuilder"
33
import { Layout } from "./Layout"
44
import { modelCallServerHook, GraphObjectProvider } from "@terminusdb-live/tdb-react-components"
55
import { WOQLClientObj } from '../init-woql-client'
6+
import { DOCUMENT_TAB } from "../pages/constants"
67
import { ErrorMessageReport } from "../components/ErrorMessageReport"
78

89
export const ModelProductPage = () => {
@@ -17,8 +18,13 @@ export const ModelProductPage = () => {
1718
reportMessage,
1819
setReport,
1920
callServerLoading,
21+
setSelectedMode
2022
} = modelCallServerHook(woqlClient, branch, ref,dataProduct)
2123

24+
useEffect(() => {
25+
if(setSelectedMode) setSelectedMode(DOCUMENT_TAB)
26+
}, [])
27+
2228
if(!dataProduct) return <div>error in loading graph</div>
2329

2430
return <React.Fragment>

0 commit comments

Comments
 (0)