Skip to content

Commit 07587c5

Browse files
committed
cypress testing ...
1 parent 9e5cbff commit 07587c5

File tree

12 files changed

+333
-11
lines changed

12 files changed

+333
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { SiGmail } from "react-icons/si"
44

5-
///8MmY%*2q
5+
///8MmY%*2q
66
//tester@terminusdb.com
77

88
//emf7V3RaiDXCsx$#@%yy
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* This test checks the Update of data product details
3+
*/
4+
import * as CONST from "../../../src/cypress.constants"
5+
const teamName = Cypress.env('TEAM_NAME')
6+
7+
const dataProduct = `test__${Date.now()}`
8+
// new time stamp
9+
const update_dataProduct = `test__${Date.now()}`
10+
11+
describe(`Visit dashboard team ${teamName}`, () => {
12+
const dashboard = Cypress.config().baseUrl
13+
14+
/** add this statement to stop cypress form complaining
15+
* about react-leaflet being used in terminusdb-document-ui */
16+
Cypress.on('uncaught:exception', (err, runnable) => {
17+
return false;
18+
});
19+
20+
// visit dashboard-dev at the start
21+
before(function () {
22+
cy.visit(dashboard)
23+
});
24+
25+
// login to terminusdb
26+
it('Check to see that you can login with an exists user', () => {
27+
cy.userLogin()
28+
})
29+
30+
// select a team
31+
it('Select Team', () => {
32+
cy.selectTeam()
33+
})
34+
35+
// Create a new data product
36+
it('Create a new dataProduct', ()=>{
37+
cy.newDataProduct(dataProduct)
38+
})
39+
40+
// Update dataProduct details
41+
it('Update dataProduct details', () => {
42+
cy.get(`button[data-cy=${CONST.UPDATE_DATA_PRODUCT_BUTTON}]`).click()
43+
cy.get('.modal-dialog').should('be.visible')
44+
cy.get(`input[data-cy=${CONST.NEW_DATA_PRODUCT_NAME}]`).clear()
45+
cy.get(`input[data-cy=${CONST.NEW_DATA_PRODUCT_NAME}]`).type(update_dataProduct)
46+
cy.get(`textarea[data-cy=${CONST.NEW_DATA_PRODUCT_DESC}]`).type(update_dataProduct)
47+
cy.get(`button[data-cy=${CONST.CREATE_NEW_DATA_PRODUCT_BUTTON_ID}]`).click()
48+
})
49+
50+
// delete dataProduct
51+
it('Delete dataProduct', ()=>{
52+
cy.deleteDataProduct(dataProduct)
53+
})
54+
55+
it('Logout', () => {
56+
cy.logout()
57+
})
58+
59+
60+
})

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// ***********************************************
1010
//
1111
//
12-
// -- This is a parent command --
12+
// -- This is a parent command --
1313
// Cypress.Commands.add('login', (email, password) => { ... })
1414
//
1515
//
@@ -23,3 +23,61 @@
2323
//
2424
// -- This will overwrite an existing command --
2525
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26+
27+
28+
import * as CONST from "../../src/cypress.constants"
29+
const email = Cypress.env('COLLABORATOR_USER')
30+
const password = Cypress.env('COLLABORATOR_PASSWORD')
31+
const team = Cypress.env('TEAM_NAME')
32+
33+
34+
/** user login function */
35+
Cypress.Commands.add('userLogin', () => {
36+
cy.get('#loginTab').click()
37+
cy.get('#email').type(email).trigger('change');
38+
cy.get('#password').type(password).trigger('change');
39+
cy.get('#btn-login').click()
40+
cy.wait(5000)
41+
});
42+
43+
/** select a team */
44+
Cypress.Commands.add('selectTeam', () => {
45+
cy.get(`#${team}`).click()
46+
cy.location().should((loc) => {
47+
expect(loc.pathname).to.eq(`/${team}`)
48+
})
49+
})
50+
51+
/** check if in correct data product */
52+
Cypress.Commands.add('inCorrectDataProduct', (dataProduct) => {
53+
cy.location().should((loc) => {
54+
expect(loc.pathname).to.eq(`/${team}/${dataProduct}`)
55+
})
56+
})
57+
58+
/** create a data product */
59+
Cypress.Commands.add('newDataProduct', (dataProduct) => {
60+
cy.get(`button[data-cy=${CONST.NEW_DATA_PRODUCT_BUTTON_ID}]`).click()
61+
cy.get(`input[data-cy=${CONST.NEW_DATA_PRODUCT_ID}]`).type(dataProduct)
62+
cy.get(`input[data-cy=${CONST.NEW_DATA_PRODUCT_NAME}]`).type(dataProduct)
63+
cy.get(`textarea[data-cy=${CONST.NEW_DATA_PRODUCT_DESC}]`).type(dataProduct)
64+
cy.get(`button[data-cy=${CONST.CREATE_NEW_DATA_PRODUCT_BUTTON_ID}]`).click()
65+
cy.inCorrectDataProduct(dataProduct)
66+
})
67+
68+
/** delete a data product */
69+
Cypress.Commands.add('deleteDataProduct', (dataProduct) => {
70+
cy.get(`button[data-cy=${CONST.HOME_DELETE_DATAPRODUCT_BUTTON_ID}]`).click()
71+
cy.get('.modal-dialog').should('be.visible')
72+
cy.get(`input[data-cy=${CONST.DELETE_DATA_PRODUCT_ID}]`).type(dataProduct)
73+
cy.get(`button[data-cy=${CONST.DELETE_DATAPRODUCT_BUTTON_ID}]`).click()
74+
cy.get(`#${dataProduct}`).should('not.exist');
75+
})
76+
77+
/** logout */
78+
Cypress.Commands.add('logout', () => {
79+
cy.get('#profile_menu_arrow').click()
80+
cy.get('#logout').click()
81+
cy.get('h1.hero-banner__heading').should('have.text', 'SIGN UP')
82+
})
83+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./commands";

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ManageDatabase } from "../hooks/ManageDatabase"
1313
import { useParams } from "react-router-dom"
1414
import { Loading } from "./Loading"
1515
import {useTDBDocuments} from "@terminusdb/terminusdb-documents-ui-template"
16+
import { UPDATE_DATA_PRODUCT_BUTTON, HOME_DELETE_DATAPRODUCT_BUTTON_ID } from "../cypress.constants"
1617

1718
import { UTILS } from "@terminusdb/terminusdb-client"
1819

@@ -188,6 +189,7 @@ export const AboutDataProduct = ({dataProductDetails, setShowDeleteModal, setSho
188189
<div className="w-100 d-block align-items-center gx-0">
189190
<Button variant="light"
190191
id="update_database"
192+
data-cy={UPDATE_DATA_PRODUCT_BUTTON}
191193
title={`Update Data Product ${dataProduct} info`}
192194
className=" btn btn-md h4 w-100 mt-4 text-dark"
193195
onClick={showUpdateHandler}>
@@ -251,6 +253,7 @@ export const AboutDataProduct = ({dataProductDetails, setShowDeleteModal, setSho
251253
<span className="mt-2 text-light w-100 mb-0"> Delete this Data Product, there is no going back. Please be certain. </span>
252254
<Button variant="secondary"
253255
id="home_open_delete_product_modal"
256+
data-cy={HOME_DELETE_DATAPRODUCT_BUTTON_ID}
254257
title={`Delete Data Product ${dataProduct}`}
255258
className=" btn btn-lg h2 text-danger fw-bold w-100 mt-4"
256259
onClick={(e) =>setShowDeleteModal(true)}>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {PROGRESS_BAR_COMPONENT} from "./constants"
77
import {WOQLClientObj} from "../init-woql-client"
88
import {TERMINUS_DANGER} from "./constants"
99
import {Alerts} from "./Alerts"
10-
import {useNavigate,useParams} from "react-router-dom"
10+
import {useNavigate,useParams} from "react-router-dom"
11+
import { DELETE_DATA_PRODUCT_ID, DELETE_DATAPRODUCT_BUTTON_ID } from "../cypress.constants"
1112

1213
export const DeleteDatabaseModal = ({showModal,setShowModal, dataProductDetails}) => {
1314
const {
@@ -90,15 +91,17 @@ export const DeleteDatabaseModal = ({showModal,setShowModal, dataProductDetails}
9091
<Form.Control required
9192
id={dataProductDetails.name}
9293
type={deleteDataProductForm.type}
94+
data-cy={DELETE_DATA_PRODUCT_ID}
9395
onChange={handleOnChange}
9496
placeholder={deleteDataProductForm.placeholder} />
9597
</Form.Group>
9698
</Form>
97-
</Modal.Body>
99+
</Modal.Body>
98100
<Modal.Footer>
99101
<Button
100102
id ="delete_data_product_button"
101103
variant="danger"
104+
data-cy={DELETE_DATAPRODUCT_BUTTON_ID}
102105
title={`Delete Data Product ${dataProductDetails.name}`}
103106
disabled={disabled}
104107
onClick={handleClick}>

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import React, {useState} from "react"
22
import {Button} from "react-bootstrap"
33
import {FaPlus} from "react-icons/fa"
44
import {NewDatabaseModal} from "../components/NewDatabaseModal"
5+
import { NEW_DATA_PRODUCT_BUTTON_ID } from "../cypress.constants"
56

6-
export const NewDataProduct = ({css}) => {
7+
export const NewDataProduct = ({css, dataCy}) => {
78
const [showModal, setShowModal] = useState(false)
89

910
function handleNew (evt) {
@@ -13,7 +14,12 @@ export const NewDataProduct = ({css}) => {
1314
}
1415

1516
return <React.Fragment>
16-
<Button id="new_data_product" variant="info" className={`btn-new-data-product btn ${css}`} title="Create New Data Product" onClick={handleNew}>
17+
<Button id={NEW_DATA_PRODUCT_BUTTON_ID}
18+
data-cy={dataCy}
19+
variant="info"
20+
className={`btn-new-data-product btn ${css}`}
21+
title="Create New Data Product"
22+
onClick={handleNew}>
1723
<FaPlus className="me-2"/> <label className="opacity-1 fw-bold">New Data Product</label>
1824
</Button>
1925
{showModal && <NewDatabaseModal setShowModal={setShowModal} showModal={showModal}/>}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {useNavigate,useParams} from "react-router-dom"
1414
import {UTILS} from "@terminusdb/terminusdb-client"
1515
import {Loading} from "../components/Loading"
1616
import { ManageDatabase } from "../hooks/ManageDatabase"
17-
export const NewDatabaseModal = ({showModal, setShowModal, dbDetails = null}) => {
17+
import { NEW_DATA_PRODUCT_ID, NEW_DATA_PRODUCT_DESC, NEW_DATA_PRODUCT_NAME, CREATE_NEW_DATA_PRODUCT_BUTTON_ID } from "../cypress.constants"
18+
19+
export const NewDatabaseModal = ({showModal, setShowModal, dbDetails = null}) => {
1820
const {
1921
reconnectToServer
2022
} = WOQLClientObj()
@@ -94,23 +96,28 @@ export const NewDatabaseModal = ({showModal, setShowModal, dbDetails = null}) =>
9496
<Form.Group className="mb-3" {...defValueId}>
9597
<Form.Control required id={newDataProductForm.id.id}
9698
type={"text"}
99+
data-cy={NEW_DATA_PRODUCT_ID}
97100
defaultValue={id}
98101
onBlur={handleOnBlur}
99102
placeholder={newDataProductForm.id.placeholder} />
100103
</Form.Group>
101104
<Form.Group className="mb-3">
102105
<Form.Control defaultValue={label}
103-
required id={newDataProductForm.label.id} type={"text"} onBlur={handleOnBlur} placeholder={newDataProductForm.label.placeholder} />
106+
data-cy={NEW_DATA_PRODUCT_NAME}
107+
required id={newDataProductForm.label.id} type={"text"} onBlur={handleOnBlur} placeholder={newDataProductForm.label.placeholder} />
104108
</Form.Group>
105109
<Form.Group className="mb-3">
106-
<Form.Control defaultValue={description} id={newDataProductForm.description.id} as="textarea" onBlur={handleOnBlur} rows="5" placeholder={newDataProductForm.description.placeholder} />
110+
<Form.Control defaultValue={description}
111+
data-cy={NEW_DATA_PRODUCT_DESC}
112+
id={newDataProductForm.description.id} as="textarea" onBlur={handleOnBlur} rows="5" placeholder={newDataProductForm.description.placeholder} />
107113
</Form.Group>
108114
</Form>}
109115
</Modal.Body>
110116
<Modal.Footer>
111117
<button title={IconBarConfig.dataProductView.title}
112118
className="btn-new-data-product mr-1 pt-2 pb-2 pr-4 pl-4 btn btn-sm btn btn-info"
113119
to={IconBarConfig.dataProductView.path}
120+
data-cy={CREATE_NEW_DATA_PRODUCT_BUTTON_ID}
114121
{...action}
115122
id="create_data_product_button">
116123
<BiPlus className="mr-1" size="1em"/>{buttonLabel}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { WOQLClient } from "@terminusdb/terminusdb-client"
77
import {localSettings} from "../../localSettings"
88
import { useNavigate } from "react-router-dom"
99
import { Loading } from "./Loading"
10+
import { NEW_DATA_PRODUCT_BUTTON_ID } from "../cypress.constants"
11+
1012
// tean home page
1113
export const NoDataProductSelected = (props) => {
1214
const {woqlClient,accessControlDashboard,clientUser} = WOQLClientObj()
@@ -75,7 +77,7 @@ export const NoDataProductSelected = (props) => {
7577
<Card className="h-100 tdb__create__new__dp bg-info" style={{opacity: "0.8"}}>
7678
<Card.Body>
7779
{accessControlDashboard && accessControlDashboard.createDB() &&
78-
<NewDataProduct css={"mt-5 p-5 opacity-1"}/>}
80+
<NewDataProduct css={"mt-5 p-5 opacity-1"} dataCy={NEW_DATA_PRODUCT_BUTTON_ID}/>}
7981
</Card.Body>
8082
</Card>
8183
</Col>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** NEW DATA PRODUCT CONSTANTS */
2+
export const NEW_DATA_PRODUCT_BUTTON_ID = "new_data_product"
3+
export const NEW_DATA_PRODUCT_ID="new_data_product_id"
4+
export const NEW_DATA_PRODUCT_NAME="new_data_product_name"
5+
export const NEW_DATA_PRODUCT_DESC="new_data_product_desc"
6+
export const CREATE_NEW_DATA_PRODUCT_BUTTON_ID = "create_new_data_product"
7+
8+
/** UPDATE DATA PRODUCT BUTTON */
9+
export const UPDATE_DATA_PRODUCT_BUTTON="update_data_product_button"
10+
11+
/** DELETE DATA PRODUCT BUTTON */
12+
export const HOME_DELETE_DATAPRODUCT_BUTTON_ID="home_delete_data_product_button"
13+
export const DELETE_DATA_PRODUCT_ID="delete_data_product_id"
14+
export const DELETE_DATAPRODUCT_BUTTON_ID="delete_data_product_button"

0 commit comments

Comments
 (0)