1
0
Fork 0
mirror of synced 2024-08-19 20:11:42 +12:00

Try to fix cypress tests

This commit is contained in:
Andrew Kingston 2022-02-23 13:14:28 +00:00
parent 63e2adbbbe
commit 572cf77644
5 changed files with 851 additions and 698 deletions

View file

@ -1,6 +1,6 @@
import filterTests from "../support/filterTests" import filterTests from "../support/filterTests"
filterTests(['smoke', 'all'], () => { filterTests(["smoke", "all"], () => {
context("Create a Table", () => { context("Create a Table", () => {
before(() => { before(() => {
cy.login() cy.login()
@ -33,7 +33,7 @@ filterTests(['smoke', 'all'], () => {
cy.contains("Save Column").click() cy.contains("Save Column").click()
cy.contains("nameupdated ").should("contain", "nameupdated") cy.contains("nameupdated ").should("contain", "nameupdated")
}) })
it("edits a row", () => { it("edits a row", () => {
cy.contains("button", "Edit").click({ force: true }) cy.contains("button", "Edit").click({ force: true })
cy.wait(1000) cy.wait(1000)
@ -42,20 +42,20 @@ filterTests(['smoke', 'all'], () => {
cy.contains("Save").click() cy.contains("Save").click()
cy.contains("Updated").should("have.text", "Updated") cy.contains("Updated").should("have.text", "Updated")
}) })
it("deletes a row", () => { it("deletes a row", () => {
cy.get(".spectrum-Checkbox-input").check({ force: true }) cy.get(".spectrum-Checkbox-input").check({ force: true })
cy.contains("Delete 1 row(s)").click() cy.contains("Delete 1 row(s)").click()
cy.get(".spectrum-Modal").contains("Delete").click() cy.get(".spectrum-Modal").contains("Delete").click()
cy.contains("RoverUpdated").should("not.exist") cy.contains("RoverUpdated").should("not.exist")
}) })
if (Cypress.env("TEST_ENV")) { if (Cypress.env("TEST_ENV")) {
// No Pagination in CI - Test env only for the next two tests // No Pagination in CI - Test env only for the next two tests
it("Adds 15 rows and checks pagination", () => { it("Adds 15 rows and checks pagination", () => {
// 10 rows per page, 15 rows should create 2 pages within table // 10 rows per page, 15 rows should create 2 pages within table
const totalRows = 16 const totalRows = 16
for (let i = 1; i < totalRows; i++){ for (let i = 1; i < totalRows; i++) {
cy.addRow([i]) cy.addRow([i])
} }
cy.wait(1000) cy.wait(1000)
@ -66,19 +66,19 @@ filterTests(['smoke', 'all'], () => {
cy.get(".spectrum-Body--secondary").contains("Page 2") cy.get(".spectrum-Body--secondary").contains("Page 2")
}) })
}) })
it("Deletes rows and checks pagination", () => { it("Deletes rows and checks pagination", () => {
// Delete rows, removing second page of rows from table // Delete rows, removing second page of rows from table
const deleteRows = 5 const deleteRows = 5
cy.get(".spectrum-Checkbox-input").check({ force: true }) cy.get(".spectrum-Checkbox-input").check({ force: true })
cy.get(".spectrum-Table-body") cy.get(".spectrum-Table")
cy.contains("Delete 5 row(s)").click() cy.contains("Delete 5 row(s)").click()
cy.get(".spectrum-Modal").contains("Delete").click() cy.get(".spectrum-Modal").contains("Delete").click()
cy.wait(1000) cy.wait(1000)
// Confirm table only has one page // Confirm table only has one page
cy.get(".spectrum-Pagination").within(() => { cy.get(".spectrum-Pagination").within(() => {
cy.get(".spectrum-ActionButton").eq(1).should('not.be.enabled') cy.get(".spectrum-ActionButton").eq(1).should("not.be.enabled")
}) })
}) })
} }

View file

@ -1,7 +1,6 @@
import filterTests from "../support/filterTests" import filterTests from "../support/filterTests"
filterTests(["smoke", "all"], () => {
filterTests(['smoke', 'all'], () => {
context("Create a User and Assign Roles", () => { context("Create a User and Assign Roles", () => {
before(() => { before(() => {
cy.login() cy.login()
@ -9,32 +8,32 @@ filterTests(['smoke', 'all'], () => {
it("should create a user", () => { it("should create a user", () => {
cy.createUser("bbuser@test.com") cy.createUser("bbuser@test.com")
cy.get(".spectrum-Table-body").should('contain', 'bbuser') cy.get(".spectrum-Table").should("contain", "bbuser")
}) })
it("should confirm there is No Access for a New User", () => { it("should confirm there is No Access for a New User", () => {
// Click into the user // Click into the user
cy.contains("bbuser").click() cy.contains("bbuser").click()
cy.wait(500) cy.wait(500)
// Get No Access table - Confirm it has apps in it // Get No Access table - Confirm it has apps in it
cy.get(".spectrum-Table").eq(1).should('not.contain', 'No rows found') cy.get(".spectrum-Table").eq(1).should("not.contain", "No rows found")
// Get Configure Roles table - Confirm it has no apps // Get Configure Roles table - Confirm it has no apps
cy.get(".spectrum-Table").eq(0).contains('No rows found') cy.get(".spectrum-Table").eq(0).contains("No rows found")
}) })
it("should assign role types", () => { it("should assign role types", () => {
// 3 apps minimum required - to assign an app to each role type // 3 apps minimum required - to assign an app to each role type
cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`) cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`)
.its("body") .its("body")
.then(val => { .then(val => {
if (val.length < 3) { if (val.length < 3) {
for (let i = 1; i < 3; i++) { for (let i = 1; i < 3; i++) {
const uuid = () => Cypress._.random(0, 1e6) const uuid = () => Cypress._.random(0, 1e6)
const name = uuid() const name = uuid()
cy.createApp(name) cy.createApp(name)
}
} }
} })
})
// Navigate back to the user // Navigate back to the user
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500) cy.wait(500)
@ -43,90 +42,135 @@ filterTests(['smoke', 'all'], () => {
cy.get(".spectrum-Table").contains("bbuser").click() cy.get(".spectrum-Table").contains("bbuser").click()
cy.wait(1000) cy.wait(1000)
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
cy.get(".spectrum-Table-body").eq(1).find('tr').eq(0).click() cy.get(".spectrum-Table")
.eq(1)
.find(".spectrum-Table-row")
.eq(0)
.click()
cy.wait(500) cy.wait(500)
cy.get(".spectrum-Dialog-grid").contains("Choose an option").click().then(() => { cy.get(".spectrum-Dialog-grid")
cy.wait(500) .contains("Choose an option")
if (i == 0) { .click()
cy.get(".spectrum-Popover").contains("Admin").click() .then(() => {
} cy.wait(500)
if (i == 1) { if (i == 0) {
cy.get(".spectrum-Popover").contains("Power").click() cy.get(".spectrum-Popover").contains("Admin").click()
} }
if (i == 2) { if (i == 1) {
cy.get(".spectrum-Popover").contains("Basic").click() cy.get(".spectrum-Popover").contains("Power").click()
} }
cy.wait(500) if (i == 2) {
cy.get(".spectrum-Button").contains("Update role").click({ force: true }) cy.get(".spectrum-Popover").contains("Basic").click()
}
cy.wait(500)
cy.get(".spectrum-Button")
.contains("Update role")
.click({ force: true })
}) })
} }
// Confirm roles exist within Configure roles table // Confirm roles exist within Configure roles table
cy.wait(500) cy.wait(500)
cy.get(".spectrum-Table-body").eq(0).within((assginedRoles) => { cy.get(".spectrum-Table")
.eq(0)
.within(assginedRoles => {
expect(assginedRoles).to.contain("Admin") expect(assginedRoles).to.contain("Admin")
expect(assginedRoles).to.contain("Power") expect(assginedRoles).to.contain("Power")
expect(assginedRoles).to.contain("Basic") expect(assginedRoles).to.contain("Basic")
}) })
}) })
it("should unassign role types", () => { it("should unassign role types", () => {
// Set each app within Configure roles table to 'No Access' // Set each app within Configure roles table to 'No Access'
cy.get(".spectrum-Table-body").eq(0).find('tr').its('length').then((len) => { cy.get(".spectrum-Table")
for (let i = 0; i < len; i ++){ .eq(0)
cy.get(".spectrum-Table-body").eq(0).find('tr').eq(0).click().then(() => { .find(".spectrum-Table-row")
cy.get(".spectrum-Picker").eq(1).click({ force: true }) .its("length")
cy.wait(500) .then(len => {
cy.get(".spectrum-Popover").contains("No Access").click() for (let i = 0; i < len; i++) {
}) cy.get(".spectrum-Table")
cy.get(".spectrum-Button").contains("Update role").click({ force: true }) .eq(0)
.find(".spectrum-Table-row")
.eq(0)
.click()
.then(() => {
cy.get(".spectrum-Picker").eq(1).click({ force: true })
cy.wait(500)
cy.get(".spectrum-Popover").contains("No Access").click()
})
cy.get(".spectrum-Button")
.contains("Update role")
.click({ force: true })
cy.wait(1000) cy.wait(1000)
} }
}) })
// Confirm Configure roles table no longer has any apps in it // Confirm Configure roles table no longer has any apps in it
cy.get(".spectrum-Table-body").eq(0).contains('No rows found') cy.get(".spectrum-Table").eq(0).contains("No rows found")
}) })
it("should enable Developer access", () => { it("should enable Developer access", () => {
// Enable Developer access // Enable Developer access
cy.get(".field").eq(4).within(() => { cy.get(".field")
cy.get(".spectrum-Switch-input").click({ force: true }) .eq(4)
}) .within(() => {
cy.get(".spectrum-Switch-input").click({ force: true })
})
// No Access table should now be empty // No Access table should now be empty
cy.get(".container").contains("No Access").parent().within(() => { cy.get(".container")
cy.get(".spectrum-Table").contains("No rows found") .contains("No Access")
}) .parent()
.within(() => {
cy.get(".spectrum-Table").contains("No rows found")
})
// Each app within Configure roles should have Admin access // Each app within Configure roles should have Admin access
cy.get(".spectrum-Table-body").eq(0).find('tr').its('length').then((len) => { cy.get(".spectrum-Table")
for (let i = 0; i < len; i++) { .eq(0)
cy.get(".spectrum-Table-body").eq(0).find('tr').eq(i).contains("Admin") .find(".spectrum-Table-row")
cy.wait(500) .its("length")
} .then(len => {
}) for (let i = 0; i < len; i++) {
cy.get(".spectrum-Table")
.eq(0)
.find(".spectrum-Table-row")
.eq(i)
.contains("Admin")
cy.wait(500)
}
})
}) })
it("should disable Developer access", () => { it("should disable Developer access", () => {
// Disable Developer access // Disable Developer access
cy.get(".field").eq(4).within(() => { cy.get(".field")
cy.get(".spectrum-Switch-input").click({ force: true }) .eq(4)
}) .within(() => {
cy.get(".spectrum-Switch-input").click({ force: true })
})
// Configure roles table should now be empty // Configure roles table should now be empty
cy.get(".container").contains("Configure roles").parent().within(() => { cy.get(".container")
cy.get(".spectrum-Table").contains("No rows found") .contains("Configure roles")
}) .parent()
.within(() => {
cy.get(".spectrum-Table").contains("No rows found")
})
}) })
it("should delete a user", () => { it("should delete a user", () => {
// Click Delete user button // Click Delete user button
cy.get(".spectrum-Button").contains("Delete user").click({force: true}).then(() => { cy.get(".spectrum-Button")
// Confirm deletion within modal .contains("Delete user")
cy.wait(500) .click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => { .then(() => {
cy.get(".spectrum-Button").contains("Delete user").click({force: true}) // Confirm deletion within modal
cy.wait(4000) cy.wait(500)
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Button")
.contains("Delete user")
.click({ force: true })
cy.wait(4000)
})
}) })
}) cy.get(".spectrum-Table").should("not.have.text", "bbuser")
cy.get(".spectrum-Table-body").should("not.have.text", "bbuser")
}) })
}) })
}) })

View file

@ -1,191 +1,222 @@
import filterTests from "../../support/filterTests" import filterTests from "../../support/filterTests"
filterTests(['all'], () => { filterTests(["all"], () => {
context("MySQL Datasource Testing", () => { context("MySQL Datasource Testing", () => {
if (Cypress.env("TEST_ENV")) { if (Cypress.env("TEST_ENV")) {
before(() => {
before(() => { cy.login()
cy.login() cy.createTestApp()
cy.createTestApp() })
}) const datasource = "MySQL"
const datasource = "MySQL" const queryName = "Cypress Test Query"
const queryName = "Cypress Test Query" const queryRename = "CT Query Rename"
const queryRename = "CT Query Rename"
it("Should add MySQL data source without configuration", () => {
it("Should add MySQL data source without configuration", () => { // Select MySQL data source
// Select MySQL data source cy.selectExternalDatasource(datasource)
cy.selectExternalDatasource(datasource) // Attempt to fetch tables without applying configuration
// Attempt to fetch tables without applying configuration cy.intercept("**/datasources").as("datasource")
cy.intercept('**/datasources').as('datasource') cy.get(".spectrum-Button")
.contains("Save and fetch tables")
.click({ force: true })
// Intercept Request after button click & apply assertions
cy.wait("@datasource")
cy.get("@datasource")
.its("response.body")
.should(
"have.property",
"message",
"connect ECONNREFUSED 127.0.0.1:3306"
)
cy.get("@datasource")
.its("response.body")
.should("have.property", "status", 500)
})
it("should add MySQL data source and fetch tables", () => {
// Add & configure MySQL data source
cy.selectExternalDatasource(datasource)
cy.intercept("**/datasources").as("datasource")
cy.addDatasourceConfig(datasource)
// Check response from datasource after adding configuration
cy.wait("@datasource")
cy.get("@datasource").its("response.statusCode").should("eq", 200)
// Confirm fetch tables was successful
cy.get(".spectrum-Table")
.eq(0)
.find(".spectrum-Table-row")
.its("length")
.should("be.gt", 0)
})
it("should check table fetching error", () => {
// MySQL test data source contains tables without primary keys
cy.get(".spectrum-InLineAlert")
.should("contain", "Error fetching tables")
.and("contain", "No primary key constraint found")
})
it("should define a One relationship type", () => {
// Select relationship type & configure
cy.get(".spectrum-Button")
.contains("Define relationship")
.click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Picker").eq(0).click()
cy.get(".spectrum-Popover").contains("One").click()
cy.get(".spectrum-Picker").eq(1).click()
cy.get(".spectrum-Popover").contains("REGIONS").click()
cy.get(".spectrum-Picker").eq(2).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
cy.get(".spectrum-Picker").eq(3).click()
cy.get(".spectrum-Popover").contains("COUNTRIES").click()
cy.get(".spectrum-Picker").eq(4).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
// Save relationship & reload page
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.reload()
})
// Confirm table length & column name
cy.get(".spectrum-Table")
.eq(1)
.find(".spectrum-Table-row")
.its("length")
.should("eq", 1)
cy.get(".spectrum-Table-cell").should("contain", "COUNTRIES to REGIONS")
})
it("should define a Many relationship type", () => {
// Select relationship type & configure
cy.get(".spectrum-Button")
.contains("Define relationship")
.click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Picker").eq(0).click()
cy.get(".spectrum-Popover").contains("Many").click()
cy.get(".spectrum-Picker").eq(1).click()
cy.get(".spectrum-Popover").contains("LOCATIONS").click()
cy.get(".spectrum-Picker").eq(2).click()
cy.get(".spectrum-Popover").contains("REGIONS").click()
cy.get(".spectrum-Picker").eq(3).click()
cy.get(".spectrum-Popover").contains("COUNTRIES").click()
cy.get(".spectrum-Picker").eq(4).click()
cy.get(".spectrum-Popover").contains("COUNTRY_ID").click()
cy.get(".spectrum-Picker").eq(5).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
// Save relationship & reload page
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.reload()
cy.wait(1000)
})
// Confirm table length & relationship name
cy.get(".spectrum-Table")
.eq(1)
.find(".spectrum-Table-row")
.its("length")
.should("eq", 2)
cy.get(".spectrum-Table-cell").should(
"contain",
"LOCATIONS through COUNTRIES → REGIONS"
)
})
it("should delete relationships", () => {
// Delete both relationships
cy.get(".spectrum-Table")
.eq(1)
.find(".spectrum-Table-row")
.its("length")
.then(len => {
for (let i = 0; i < len; i++) {
cy.get(".spectrum-Table")
.eq(1)
.within(() => {
cy.get(".spectrum-Table-row").eq(0).click()
cy.wait(500)
})
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Button") cy.get(".spectrum-Button")
.contains("Save and fetch tables") .contains("Delete")
.click({ force: true }) .click({ force: true })
// Intercept Request after button click & apply assertions })
cy.wait("@datasource") cy.reload()
cy.get("@datasource").its('response.body') }
.should('have.property', 'message', 'connect ECONNREFUSED 127.0.0.1:3306') // Confirm relationships no longer exist
cy.get("@datasource").its('response.body') cy.get(".spectrum-Body").should(
.should('have.property', 'status', 500) "contain",
}) "No relationships configured"
)
it("should add MySQL data source and fetch tables", () => { })
// Add & configure MySQL data source })
cy.selectExternalDatasource(datasource)
cy.intercept('**/datasources').as('datasource') it("should add a query", () => {
cy.addDatasourceConfig(datasource) // Add query
// Check response from datasource after adding configuration cy.get(".spectrum-Button").contains("Add query").click({ force: true })
cy.wait("@datasource") cy.get(".spectrum-Form-item")
cy.get("@datasource").its('response.statusCode') .eq(0)
.should('eq', 200) .within(() => {
// Confirm fetch tables was successful cy.get("input").type(queryName)
cy.get(".spectrum-Table-body").eq(0) })
.find('tr') // Insert Query within Fields section
.its('length') cy.get(".CodeMirror textarea")
.should('be.gt', 0) .eq(0)
}) .type("SELECT * FROM books", { force: true })
// Intercept query execution
it("should check table fetching error", () => { cy.intercept("**/queries/preview").as("query")
// MySQL test data source contains tables without primary keys cy.get(".spectrum-Button").contains("Run Query").click({ force: true })
cy.get(".spectrum-InLineAlert") cy.wait(500)
.should('contain', 'Error fetching tables') cy.wait("@query")
.and('contain', 'No primary key constraint found') // Assert against Status Code & Body
}) cy.get("@query").its("response.statusCode").should("eq", 200)
cy.get("@query").its("response.body").should("not.be.empty")
it("should define a One relationship type", () => { // Save query
// Select relationship type & configure cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".spectrum-Button").contains("Define relationship").click({ force: true }) cy.get(".nav-item").should("contain", queryName)
cy.get(".spectrum-Dialog-grid").within(() => { })
cy.get(".spectrum-Picker").eq(0).click()
cy.get(".spectrum-Popover").contains("One").click() it("should duplicate a query", () => {
cy.get(".spectrum-Picker").eq(1).click() // Get last nav item - The query
cy.get(".spectrum-Popover").contains("REGIONS").click() cy.get(".nav-item")
cy.get(".spectrum-Picker").eq(2).click() .last()
cy.get(".spectrum-Popover").contains("REGION_ID").click() .within(() => {
cy.get(".spectrum-Picker").eq(3).click() cy.get(".icon").eq(1).click({ force: true })
cy.get(".spectrum-Popover").contains("COUNTRIES").click() })
cy.get(".spectrum-Picker").eq(4).click() // Select and confirm duplication
cy.get(".spectrum-Popover").contains("REGION_ID").click() cy.get(".spectrum-Menu").contains("Duplicate").click()
// Save relationship & reload page cy.get(".nav-item").should("contain", queryName + " (1)")
cy.get(".spectrum-Button").contains("Save").click({ force: true }) })
cy.reload()
}) it("should edit a query name", () => {
// Confirm table length & column name // Rename query
cy.get(".spectrum-Table-body").eq(1) cy.get(".spectrum-Form-item")
.find('tr') .eq(0)
.its('length') .within(() => {
.should('eq', 1) cy.get("input").clear().type(queryRename)
cy.get(".spectrum-Table-cell").should('contain', "COUNTRIES to REGIONS") })
}) // Save query
cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
it("should define a Many relationship type", () => { cy.get(".nav-item").should("contain", queryRename)
// Select relationship type & configure })
cy.get(".spectrum-Button").contains("Define relationship").click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => { it("should delete a query", () => {
cy.get(".spectrum-Picker").eq(0).click() // Get last nav item - The query
cy.get(".spectrum-Popover").contains("Many").click() for (let i = 0; i < 2; i++) {
cy.get(".spectrum-Picker").eq(1).click() cy.get(".nav-item")
cy.get(".spectrum-Popover").contains("LOCATIONS").click() .last()
cy.get(".spectrum-Picker").eq(2).click() .within(() => {
cy.get(".spectrum-Popover").contains("REGIONS").click() cy.get(".icon").eq(1).click({ force: true })
cy.get(".spectrum-Picker").eq(3).click()
cy.get(".spectrum-Popover").contains("COUNTRIES").click()
cy.get(".spectrum-Picker").eq(4).click()
cy.get(".spectrum-Popover").contains("COUNTRY_ID").click()
cy.get(".spectrum-Picker").eq(5).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
// Save relationship & reload page
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.reload()
cy.wait(1000)
})
// Confirm table length & relationship name
cy.get(".spectrum-Table-body").eq(1)
.find('tr')
.its('length')
.should('eq', 2)
cy.get(".spectrum-Table-cell")
.should('contain', "LOCATIONS through COUNTRIES → REGIONS")
})
it("should delete relationships", () => {
// Delete both relationships
cy.get(".spectrum-Table-body")
.eq(1).find('tr').its('length')
.then((len) => {
for (let i = 0; i < len; i++) {
cy.get(".spectrum-Table-body").eq(1).within(() => {
cy.get(".spectrum-Table-row").eq(0).click()
cy.wait(500)
})
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Button").contains("Delete").click({ force: true })
})
cy.reload()
}
// Confirm relationships no longer exist
cy.get(".spectrum-Body").should('contain', 'No relationships configured')
})
})
it("should add a query", () => {
// Add query
cy.get(".spectrum-Button").contains("Add query").click({ force: true })
cy.get(".spectrum-Form-item").eq(0).within(() => {
cy.get("input").type(queryName)
})
// Insert Query within Fields section
cy.get(".CodeMirror textarea").eq(0)
.type("SELECT * FROM books", { force: true })
// Intercept query execution
cy.intercept('**/queries/preview').as('query')
cy.get(".spectrum-Button").contains("Run Query").click({ force: true })
cy.wait(500)
cy.wait("@query")
// Assert against Status Code & Body
cy.get("@query").its('response.statusCode')
.should('eq', 200)
cy.get("@query").its('response.body')
.should('not.be.empty')
// Save query
cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".nav-item").should('contain', queryName)
})
it("should duplicate a query", () => {
// Get last nav item - The query
cy.get(".nav-item").last().within(() => {
cy.get(".icon").eq(1).click({ force: true })
})
// Select and confirm duplication
cy.get(".spectrum-Menu").contains("Duplicate").click()
cy.get(".nav-item").should('contain', queryName + ' (1)')
})
it("should edit a query name", () => {
// Rename query
cy.get(".spectrum-Form-item").eq(0).within(() => {
cy.get("input").clear().type(queryRename)
})
// Save query
cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".nav-item").should('contain', queryRename)
})
it("should delete a query", () => {
// Get last nav item - The query
for (let i = 0; i < 2; i++) {
cy.get(".nav-item").last().within(() => {
cy.get(".icon").eq(1).click({ force: true })
})
// Select Delete
cy.get(".spectrum-Menu").contains("Delete").click()
cy.get(".spectrum-Button").contains("Delete Query").click({ force: true })
cy.wait(1000)
}
// Confirm deletion
cy.get(".nav-item").should('not.contain', queryName)
cy.get(".nav-item").should('not.contain', queryRename)
}) })
// Select Delete
cy.get(".spectrum-Menu").contains("Delete").click()
cy.get(".spectrum-Button")
.contains("Delete Query")
.click({ force: true })
cy.wait(1000)
} }
}) // Confirm deletion
cy.get(".nav-item").should("not.contain", queryName)
cy.get(".nav-item").should("not.contain", queryRename)
})
}
})
}) })

View file

@ -1,196 +1,230 @@
import filterTests from "../../support/filterTests" import filterTests from "../../support/filterTests"
filterTests(['all'], () => { filterTests(["all"], () => {
context("Oracle Datasource Testing", () => { context("Oracle Datasource Testing", () => {
if (Cypress.env("TEST_ENV")) { if (Cypress.env("TEST_ENV")) {
before(() => {
cy.login()
cy.createTestApp()
})
const datasource = "Oracle"
const queryName = "Cypress Test Query"
const queryRename = "CT Query Rename"
before(() => { it("Should add Oracle data source and skip table fetch", () => {
cy.login() // Select Oracle data source
cy.createTestApp() cy.selectExternalDatasource(datasource)
}) // Skip table fetch - no config added
const datasource = "Oracle" cy.get(".spectrum-Button")
const queryName = "Cypress Test Query" .contains("Skip table fetch")
const queryRename = "CT Query Rename" .click({ force: true })
cy.wait(500)
it("Should add Oracle data source and skip table fetch", () => { // Confirm config contains localhost
// Select Oracle data source cy.get(".spectrum-Textfield-input")
cy.selectExternalDatasource(datasource) .eq(1)
// Skip table fetch - no config added .should("have.value", "localhost")
cy.get(".spectrum-Button").contains("Skip table fetch").click({ force: true }) // Add another Oracle data source, configure & skip table fetch
cy.wait(500) cy.selectExternalDatasource(datasource)
// Confirm config contains localhost cy.addDatasourceConfig(datasource, true)
cy.get(".spectrum-Textfield-input").eq(1).should('have.value', 'localhost') // Confirm config and no tables
// Add another Oracle data source, configure & skip table fetch cy.get(".spectrum-Textfield-input")
cy.selectExternalDatasource(datasource) .eq(1)
cy.addDatasourceConfig(datasource, true) .should("have.value", Cypress.env("oracle").HOST)
// Confirm config and no tables cy.get(".spectrum-Body").eq(2).should("contain", "No tables found.")
cy.get(".spectrum-Textfield-input").eq(1).should('have.value', Cypress.env("oracle").HOST) })
cy.get(".spectrum-Body").eq(2).should('contain', 'No tables found.')
}) it("Should add Oracle data source and fetch tables without configuration", () => {
// Select Oracle data source
it("Should add Oracle data source and fetch tables without configuration", () => { cy.selectExternalDatasource(datasource)
// Select Oracle data source // Attempt to fetch tables without applying configuration
cy.selectExternalDatasource(datasource) cy.intercept("**/datasources").as("datasource")
// Attempt to fetch tables without applying configuration cy.get(".spectrum-Button")
cy.intercept('**/datasources').as('datasource') .contains("Save and fetch tables")
.click({ force: true })
// Intercept Request after button click & apply assertions
cy.wait("@datasource")
cy.get("@datasource")
.its("response.body")
.should("have.property", "status", 500)
})
it("should add Oracle data source and fetch tables", () => {
// Add & configure Oracle data source
cy.selectExternalDatasource(datasource)
cy.intercept("**/datasources").as("datasource")
cy.addDatasourceConfig(datasource)
// Check response from datasource after adding configuration
cy.wait("@datasource")
cy.get("@datasource").its("response.statusCode").should("eq", 200)
// Confirm fetch tables was successful
cy.get(".spectrum-Table")
.eq(0)
.find(".spectrum-Table-row")
.its("length")
.should("be.gt", 0)
})
it("should define a One relationship type", () => {
// Select relationship type & configure
cy.get(".spectrum-Button")
.contains("Define relationship")
.click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Picker").eq(0).click()
cy.get(".spectrum-Popover").contains("One").click()
cy.get(".spectrum-Picker").eq(1).click()
cy.get(".spectrum-Popover").contains("REGIONS").click()
cy.get(".spectrum-Picker").eq(2).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
cy.get(".spectrum-Picker").eq(3).click()
cy.get(".spectrum-Popover").contains("COUNTRIES").click()
cy.get(".spectrum-Picker").eq(4).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
// Save relationship & reload page
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.reload()
})
// Confirm table length & column name
cy.get(".spectrum-Table")
.eq(1)
.find(".spectrum-Table-row")
.its("length")
.should("eq", 1)
cy.get(".spectrum-Table-cell").should("contain", "COUNTRIES to REGIONS")
})
it("should define a Many relationship type", () => {
// Select relationship type & configure
cy.get(".spectrum-Button")
.contains("Define relationship")
.click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Picker").eq(0).click()
cy.get(".spectrum-Popover").contains("Many").click()
cy.get(".spectrum-Picker").eq(1).click()
cy.get(".spectrum-Popover").contains("LOCATIONS").click()
cy.get(".spectrum-Picker").eq(2).click()
cy.get(".spectrum-Popover").contains("REGIONS").click()
cy.get(".spectrum-Picker").eq(3).click()
cy.get(".spectrum-Popover").contains("COUNTRIES").click()
cy.get(".spectrum-Picker").eq(4).click()
cy.get(".spectrum-Popover").contains("COUNTRY_ID").click()
cy.get(".spectrum-Picker").eq(5).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
// Save relationship & reload page
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.reload()
})
// Confirm table length & relationship name
cy.get(".spectrum-Table")
.eq(1)
.find(".spectrum-Table-row")
.its("length")
.should("eq", 2)
cy.get(".spectrum-Table-cell").should(
"contain",
"LOCATIONS through COUNTRIES → REGIONS"
)
})
it("should delete relationships", () => {
// Delete both relationships
cy.get(".spectrum-Table")
.eq(1)
.find(".spectrum-Table-row")
.its("length")
.then(len => {
for (let i = 0; i < len; i++) {
cy.get(".spectrum-Table")
.eq(1)
.within(() => {
cy.get(".spectrum-Table-row").eq(0).click()
cy.wait(500)
})
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Button") cy.get(".spectrum-Button")
.contains("Save and fetch tables") .contains("Delete")
.click({ force: true }) .click({ force: true })
// Intercept Request after button click & apply assertions })
cy.wait("@datasource") cy.reload()
cy.get("@datasource").its('response.body') }
.should('have.property', 'status', 500) // Confirm relationships no longer exist
}) cy.get(".spectrum-Body").should(
"contain",
it("should add Oracle data source and fetch tables", () => { "No relationships configured"
// Add & configure Oracle data source )
cy.selectExternalDatasource(datasource) })
cy.intercept('**/datasources').as('datasource') })
cy.addDatasourceConfig(datasource)
// Check response from datasource after adding configuration it("should add a query", () => {
cy.wait("@datasource") // Add query
cy.get("@datasource").its('response.statusCode') cy.get(".spectrum-Button").contains("Add query").click({ force: true })
.should('eq', 200) cy.get(".spectrum-Form-item")
// Confirm fetch tables was successful .eq(0)
cy.get(".spectrum-Table-body").eq(0) .within(() => {
.find('tr') cy.get("input").type(queryName)
.its('length') })
.should('be.gt', 0) // Insert Query within Fields section
}) cy.get(".CodeMirror textarea")
.eq(0)
it("should define a One relationship type", () => { .type("SELECT * FROM JOBS", { force: true })
// Select relationship type & configure // Intercept query execution
cy.get(".spectrum-Button").contains("Define relationship").click({ force: true }) cy.intercept("**/queries/preview").as("query")
cy.get(".spectrum-Dialog-grid").within(() => { cy.get(".spectrum-Button").contains("Run Query").click({ force: true })
cy.get(".spectrum-Picker").eq(0).click() cy.wait(500)
cy.get(".spectrum-Popover").contains("One").click() cy.wait("@query")
cy.get(".spectrum-Picker").eq(1).click() // Assert against Status Code & Body
cy.get(".spectrum-Popover").contains("REGIONS").click() cy.get("@query").its("response.statusCode").should("eq", 200)
cy.get(".spectrum-Picker").eq(2).click() cy.get("@query").its("response.body").should("not.be.empty")
cy.get(".spectrum-Popover").contains("REGION_ID").click() // Save query
cy.get(".spectrum-Picker").eq(3).click() cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".spectrum-Popover").contains("COUNTRIES").click() cy.get(".nav-item").should("contain", queryName)
cy.get(".spectrum-Picker").eq(4).click() })
cy.get(".spectrum-Popover").contains("REGION_ID").click()
// Save relationship & reload page it("should duplicate a query", () => {
cy.get(".spectrum-Button").contains("Save").click({ force: true }) // Get query nav item
cy.reload() cy.get(".nav-item")
}) .contains(queryName)
// Confirm table length & column name .parent()
cy.get(".spectrum-Table-body").eq(1) .within(() => {
.find('tr') cy.get(".spectrum-Icon").eq(1).click({ force: true })
.its('length') })
.should('eq', 1) // Select and confirm duplication
cy.get(".spectrum-Table-cell").should('contain', "COUNTRIES to REGIONS") cy.get(".spectrum-Menu").contains("Duplicate").click()
}) cy.get(".nav-item").should("contain", queryName + " (1)")
})
it("should define a Many relationship type", () => {
// Select relationship type & configure it("should edit a query name", () => {
cy.get(".spectrum-Button").contains("Define relationship").click({ force: true }) // Rename query
cy.get(".spectrum-Dialog-grid").within(() => { cy.get(".spectrum-Form-item")
cy.get(".spectrum-Picker").eq(0).click() .eq(0)
cy.get(".spectrum-Popover").contains("Many").click() .within(() => {
cy.get(".spectrum-Picker").eq(1).click() cy.get("input").clear().type(queryRename)
cy.get(".spectrum-Popover").contains("LOCATIONS").click() })
cy.get(".spectrum-Picker").eq(2).click() // Save query
cy.get(".spectrum-Popover").contains("REGIONS").click() cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".spectrum-Picker").eq(3).click() cy.get(".nav-item").should("contain", queryRename)
cy.get(".spectrum-Popover").contains("COUNTRIES").click() })
cy.get(".spectrum-Picker").eq(4).click()
cy.get(".spectrum-Popover").contains("COUNTRY_ID").click() it("should delete a query", () => {
cy.get(".spectrum-Picker").eq(5).click() // Get query nav item - QueryName
cy.get(".spectrum-Popover").contains("REGION_ID").click() cy.get(".nav-item")
// Save relationship & reload page .contains(queryName)
cy.get(".spectrum-Button").contains("Save").click({ force: true }) .parent()
cy.reload() .within(() => {
}) cy.get(".spectrum-Icon").eq(1).click({ force: true })
// Confirm table length & relationship name })
cy.get(".spectrum-Table-body").eq(1)
.find('tr') // Select Delete
.its('length') cy.get(".spectrum-Menu").contains("Delete").click()
.should('eq', 2) cy.get(".spectrum-Button")
cy.get(".spectrum-Table-cell") .contains("Delete Query")
.should('contain', "LOCATIONS through COUNTRIES → REGIONS") .click({ force: true })
}) cy.wait(1000)
it("should delete relationships", () => { // Confirm deletion
// Delete both relationships cy.get(".nav-item").should("not.contain", queryName)
cy.get(".spectrum-Table-body") })
.eq(1).find('tr').its('length') }
.then((len) => { })
for (let i = 0; i < len; i++) {
cy.get(".spectrum-Table-body").eq(1).within(() => {
cy.get(".spectrum-Table-row").eq(0).click()
cy.wait(500)
})
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Button").contains("Delete").click({ force: true })
})
cy.reload()
}
// Confirm relationships no longer exist
cy.get(".spectrum-Body").should('contain', 'No relationships configured')
})
})
it("should add a query", () => {
// Add query
cy.get(".spectrum-Button").contains("Add query").click({ force: true })
cy.get(".spectrum-Form-item").eq(0).within(() => {
cy.get("input").type(queryName)
})
// Insert Query within Fields section
cy.get(".CodeMirror textarea").eq(0)
.type("SELECT * FROM JOBS", { force: true })
// Intercept query execution
cy.intercept('**/queries/preview').as('query')
cy.get(".spectrum-Button").contains("Run Query").click({ force: true })
cy.wait(500)
cy.wait("@query")
// Assert against Status Code & Body
cy.get("@query").its('response.statusCode')
.should('eq', 200)
cy.get("@query").its('response.body')
.should('not.be.empty')
// Save query
cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".nav-item").should('contain', queryName)
})
it("should duplicate a query", () => {
// Get query nav item
cy.get(".nav-item").contains(queryName).parent().within(() => {
cy.get(".spectrum-Icon").eq(1).click({ force: true })
})
// Select and confirm duplication
cy.get(".spectrum-Menu").contains("Duplicate").click()
cy.get(".nav-item").should('contain', queryName + ' (1)')
})
it("should edit a query name", () => {
// Rename query
cy.get(".spectrum-Form-item").eq(0).within(() => {
cy.get("input").clear().type(queryRename)
})
// Save query
cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".nav-item").should('contain', queryRename)
})
it("should delete a query", () => {
// Get query nav item - QueryName
cy.get(".nav-item").contains(queryName).parent().within(() => {
cy.get(".spectrum-Icon").eq(1).click({ force: true })
})
// Select Delete
cy.get(".spectrum-Menu").contains("Delete").click()
cy.get(".spectrum-Button").contains("Delete Query").click({ force: true })
cy.wait(1000)
// Confirm deletion
cy.get(".nav-item").should('not.contain', queryName)
})
}
})
}) })

View file

@ -1,241 +1,285 @@
import filterTests from "../../support/filterTests" import filterTests from "../../support/filterTests"
filterTests(['all'], () => { filterTests(["all"], () => {
context("PostgreSQL Datasource Testing", () => { context("PostgreSQL Datasource Testing", () => {
if (Cypress.env("TEST_ENV")) { if (Cypress.env("TEST_ENV")) {
before(() => {
before(() => { cy.login()
cy.login() cy.createTestApp()
cy.createTestApp() })
const datasource = "PostgreSQL"
const queryName = "Cypress Test Query"
const queryRename = "CT Query Rename"
it("Should add PostgreSQL data source without configuration", () => {
// Select PostgreSQL data source
cy.selectExternalDatasource(datasource)
// Attempt to fetch tables without applying configuration
cy.intercept("**/datasources").as("datasource")
cy.get(".spectrum-Button")
.contains("Save and fetch tables")
.click({ force: true })
// Intercept Request after button click & apply assertions
cy.wait("@datasource")
cy.get("@datasource")
.its("response.body")
.should(
"have.property",
"message",
"connect ECONNREFUSED 127.0.0.1:5432"
)
cy.get("@datasource")
.its("response.body")
.should("have.property", "status", 500)
})
it("should add PostgreSQL data source and fetch tables", () => {
// Add & configure PostgreSQL data source
cy.selectExternalDatasource(datasource)
cy.intercept("**/datasources").as("datasource")
cy.addDatasourceConfig(datasource)
// Check response from datasource after adding configuration
cy.wait("@datasource")
cy.get("@datasource").its("response.statusCode").should("eq", 200)
// Confirm fetch tables was successful
cy.get(".spectrum-Table")
.eq(0)
.find(".spectrum-Table-row")
.its("length")
.should("be.gt", 0)
})
it("should define a One relationship type", () => {
// Select relationship type & configure
cy.get(".spectrum-Button")
.contains("Define relationship")
.click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Picker").eq(0).click()
cy.get(".spectrum-Popover").contains("One").click()
cy.get(".spectrum-Picker").eq(1).click()
cy.get(".spectrum-Popover").contains("REGIONS").click()
cy.get(".spectrum-Picker").eq(2).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
cy.get(".spectrum-Picker").eq(3).click()
cy.get(".spectrum-Popover").contains("COUNTRIES").click()
cy.get(".spectrum-Picker").eq(4).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
// Save relationship & reload page
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.reload()
})
// Confirm table length & column name
cy.get(".spectrum-Table")
.eq(1)
.find(".spectrum-Table-row")
.its("length")
.should("eq", 1)
cy.get(".spectrum-Table-cell").should("contain", "COUNTRIES to REGIONS")
})
it("should define a Many relationship type", () => {
// Select relationship type & configure
cy.get(".spectrum-Button")
.contains("Define relationship")
.click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Picker").eq(0).click()
cy.get(".spectrum-Popover").contains("Many").click()
cy.get(".spectrum-Picker").eq(1).click()
cy.get(".spectrum-Popover").contains("LOCATIONS").click()
cy.get(".spectrum-Picker").eq(2).click()
cy.get(".spectrum-Popover").contains("REGIONS").click()
cy.get(".spectrum-Picker").eq(3).click()
cy.get(".spectrum-Popover").contains("COUNTRIES").click()
cy.get(".spectrum-Picker").eq(4).click()
cy.get(".spectrum-Popover").contains("COUNTRY_ID").click()
cy.get(".spectrum-Picker").eq(5).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
// Save relationship & reload page
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.reload()
})
// Confirm table length & relationship name
cy.get(".spectrum-Table")
.eq(1)
.find(".spectrum-Table-row")
.its("length")
.should("eq", 2)
cy.get(".spectrum-Table-cell").should(
"contain",
"LOCATIONS through COUNTRIES → REGIONS"
)
})
it("should delete a relationship", () => {
cy.get(".hierarchy-items-container").contains(datasource).click()
cy.reload()
// Delete one relationship
cy.get(".spectrum-Table")
.eq(1)
.within(() => {
cy.get(".spectrum-Table-row").eq(0).click()
cy.wait(500)
})
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Button").contains("Delete").click({ force: true })
})
cy.reload()
// Confirm relationship was deleted
cy.get(".spectrum-Table")
.eq(1)
.find(".spectrum-Table-row")
.its("length")
.should("eq", 1)
})
it("should add a query", () => {
// Add query
cy.get(".spectrum-Button").contains("Add query").click({ force: true })
cy.get(".spectrum-Form-item")
.eq(0)
.within(() => {
cy.get("input").type(queryName)
})
// Insert Query within Fields section
cy.get(".CodeMirror textarea")
.eq(0)
.type("SELECT * FROM books", { force: true })
// Intercept query execution
cy.intercept("**/queries/preview").as("query")
cy.get(".spectrum-Button").contains("Run Query").click({ force: true })
cy.wait(500)
cy.wait("@query")
// Assert against Status Code & Body
cy.get("@query").its("response.statusCode").should("eq", 200)
cy.get("@query").its("response.body").should("not.be.empty")
// Save query
cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".hierarchy-items-container").should("contain", queryName)
})
it("should switch to schema with no tables", () => {
// Switch Schema - To one without any tables
cy.get(".hierarchy-items-container").contains(datasource).click()
switchSchema("randomText")
// No tables displayed
cy.get(".spectrum-Body").eq(2).should("contain", "No tables found")
// Previously created query should be visible
cy.get(".spectrum-Table").should("contain", queryName)
})
it("should switch schemas", () => {
// Switch schema - To one with tables
switchSchema("1")
// Confirm tables exist - Check for specific one
cy.get(".spectrum-Table").eq(0).should("contain", "test")
cy.get(".spectrum-Table")
.eq(0)
.find(".spectrum-Table-row")
.its("length")
.should("eq", 1)
// Confirm specific table visible within left nav bar
cy.get(".hierarchy-items-container").should("contain", "test")
// Switch back to public schema
switchSchema("public")
// Confirm tables exist - again
cy.get(".spectrum-Table").eq(0).should("contain", "REGIONS")
cy.get(".spectrum-Table")
.eq(0)
.find(".spectrum-Table-row")
.its("length")
.should("be.gt", 1)
// Confirm specific table visible within left nav bar
cy.get(".hierarchy-items-container").should("contain", "REGIONS")
// No relationships and one query
cy.get(".spectrum-Body")
.eq(3)
.should("contain", "No relationships configured.")
cy.get(".spectrum-Table").eq(1).should("contain", queryName)
})
it("should duplicate a query", () => {
// Get last nav item - The query
cy.get(".nav-item")
.last()
.within(() => {
cy.get(".icon").eq(1).click({ force: true })
})
// Select and confirm duplication
cy.get(".spectrum-Menu").contains("Duplicate").click()
cy.get(".nav-item").should("contain", queryName + " (1)")
})
it("should edit a query name", () => {
// Access query
cy.get(".hierarchy-items-container")
.contains(queryName + " (1)")
.click()
// Rename query
cy.get(".spectrum-Form-item")
.eq(0)
.within(() => {
cy.get("input").clear().type(queryRename)
})
// Run and Save query
cy.get(".spectrum-Button").contains("Run Query").click({ force: true })
cy.wait(500)
cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".nav-item").should("contain", queryRename)
})
it("should delete a query", () => {
// Get last nav item - The query
for (let i = 0; i < 2; i++) {
cy.get(".nav-item")
.last()
.within(() => {
cy.get(".icon").eq(1).click({ force: true })
}) })
const datasource = "PostgreSQL" // Select Delete
const queryName = "Cypress Test Query" cy.get(".spectrum-Menu").contains("Delete").click()
const queryRename = "CT Query Rename" cy.get(".spectrum-Button")
.contains("Delete Query")
it("Should add PostgreSQL data source without configuration", () => { .click({ force: true })
// Select PostgreSQL data source cy.wait(1000)
cy.selectExternalDatasource(datasource)
// Attempt to fetch tables without applying configuration
cy.intercept('**/datasources').as('datasource')
cy.get(".spectrum-Button")
.contains("Save and fetch tables")
.click({ force: true })
// Intercept Request after button click & apply assertions
cy.wait("@datasource")
cy.get("@datasource").its('response.body')
.should('have.property', 'message', 'connect ECONNREFUSED 127.0.0.1:5432')
cy.get("@datasource").its('response.body')
.should('have.property', 'status', 500)
})
it("should add PostgreSQL data source and fetch tables", () => {
// Add & configure PostgreSQL data source
cy.selectExternalDatasource(datasource)
cy.intercept('**/datasources').as('datasource')
cy.addDatasourceConfig(datasource)
// Check response from datasource after adding configuration
cy.wait("@datasource")
cy.get("@datasource").its('response.statusCode')
.should('eq', 200)
// Confirm fetch tables was successful
cy.get(".spectrum-Table-body").eq(0)
.find('tr')
.its('length')
.should('be.gt', 0)
})
it("should define a One relationship type", () => {
// Select relationship type & configure
cy.get(".spectrum-Button").contains("Define relationship").click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Picker").eq(0).click()
cy.get(".spectrum-Popover").contains("One").click()
cy.get(".spectrum-Picker").eq(1).click()
cy.get(".spectrum-Popover").contains("REGIONS").click()
cy.get(".spectrum-Picker").eq(2).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
cy.get(".spectrum-Picker").eq(3).click()
cy.get(".spectrum-Popover").contains("COUNTRIES").click()
cy.get(".spectrum-Picker").eq(4).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
// Save relationship & reload page
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.reload()
})
// Confirm table length & column name
cy.get(".spectrum-Table-body").eq(1)
.find('tr')
.its('length')
.should('eq', 1)
cy.get(".spectrum-Table-cell").should('contain', "COUNTRIES to REGIONS")
})
it("should define a Many relationship type", () => {
// Select relationship type & configure
cy.get(".spectrum-Button").contains("Define relationship").click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Picker").eq(0).click()
cy.get(".spectrum-Popover").contains("Many").click()
cy.get(".spectrum-Picker").eq(1).click()
cy.get(".spectrum-Popover").contains("LOCATIONS").click()
cy.get(".spectrum-Picker").eq(2).click()
cy.get(".spectrum-Popover").contains("REGIONS").click()
cy.get(".spectrum-Picker").eq(3).click()
cy.get(".spectrum-Popover").contains("COUNTRIES").click()
cy.get(".spectrum-Picker").eq(4).click()
cy.get(".spectrum-Popover").contains("COUNTRY_ID").click()
cy.get(".spectrum-Picker").eq(5).click()
cy.get(".spectrum-Popover").contains("REGION_ID").click()
// Save relationship & reload page
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.reload()
})
// Confirm table length & relationship name
cy.get(".spectrum-Table-body").eq(1)
.find('tr')
.its('length')
.should('eq', 2)
cy.get(".spectrum-Table-cell")
.should('contain', "LOCATIONS through COUNTRIES → REGIONS")
})
it("should delete a relationship", () => {
cy.get(".hierarchy-items-container").contains(datasource).click()
cy.reload()
// Delete one relationship
cy.get(".spectrum-Table-body").eq(1).within(() => {
cy.get(".spectrum-Table-row").eq(0).click()
cy.wait(500)
})
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Button").contains("Delete").click({ force: true })
})
cy.reload()
// Confirm relationship was deleted
cy.get(".spectrum-Table-body")
.eq(1).find('tr').its('length').should('eq', 1)
})
it("should add a query", () => {
// Add query
cy.get(".spectrum-Button").contains("Add query").click({ force: true })
cy.get(".spectrum-Form-item").eq(0).within(() => {
cy.get("input").type(queryName)
})
// Insert Query within Fields section
cy.get(".CodeMirror textarea").eq(0)
.type("SELECT * FROM books", { force: true })
// Intercept query execution
cy.intercept('**/queries/preview').as('query')
cy.get(".spectrum-Button").contains("Run Query").click({ force: true })
cy.wait(500)
cy.wait("@query")
// Assert against Status Code & Body
cy.get("@query").its('response.statusCode')
.should('eq', 200)
cy.get("@query").its('response.body')
.should('not.be.empty')
// Save query
cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".hierarchy-items-container").should('contain', queryName)
})
it("should switch to schema with no tables", () => {
// Switch Schema - To one without any tables
cy.get(".hierarchy-items-container").contains(datasource).click()
switchSchema("randomText")
// No tables displayed
cy.get(".spectrum-Body").eq(2).should('contain', 'No tables found')
// Previously created query should be visible
cy.get(".spectrum-Table-body").should('contain', queryName)
})
it("should switch schemas", () => {
// Switch schema - To one with tables
switchSchema("1")
// Confirm tables exist - Check for specific one
cy.get(".spectrum-Table-body").eq(0).should('contain', 'test')
cy.get(".spectrum-Table-body").eq(0).find('tr').its('length').should('eq', 1)
// Confirm specific table visible within left nav bar
cy.get(".hierarchy-items-container").should('contain', 'test')
// Switch back to public schema
switchSchema("public")
// Confirm tables exist - again
cy.get(".spectrum-Table-body").eq(0).should('contain', 'REGIONS')
cy.get(".spectrum-Table-body").eq(0)
.find('tr').its('length').should('be.gt', 1)
// Confirm specific table visible within left nav bar
cy.get(".hierarchy-items-container").should('contain', 'REGIONS')
// No relationships and one query
cy.get(".spectrum-Body").eq(3).should('contain', 'No relationships configured.')
cy.get(".spectrum-Table-body").eq(1).should('contain', queryName)
})
it("should duplicate a query", () => {
// Get last nav item - The query
cy.get(".nav-item").last().within(() => {
cy.get(".icon").eq(1).click({ force: true })
})
// Select and confirm duplication
cy.get(".spectrum-Menu").contains("Duplicate").click()
cy.get(".nav-item").should('contain', queryName + ' (1)')
})
it("should edit a query name", () => {
// Access query
cy.get(".hierarchy-items-container").contains(queryName + ' (1)').click()
// Rename query
cy.get(".spectrum-Form-item").eq(0).within(() => {
cy.get("input").clear().type(queryRename)
})
// Run and Save query
cy.get(".spectrum-Button").contains("Run Query").click({ force: true })
cy.wait(500)
cy.get(".spectrum-Button").contains("Save Query").click({ force: true })
cy.get(".nav-item").should('contain', queryRename)
})
it("should delete a query", () => {
// Get last nav item - The query
for (let i = 0; i < 2; i++) {
cy.get(".nav-item").last().within(() => {
cy.get(".icon").eq(1).click({ force: true })
})
// Select Delete
cy.get(".spectrum-Menu").contains("Delete").click()
cy.get(".spectrum-Button").contains("Delete Query").click({ force: true })
cy.wait(1000)
}
// Confirm deletion
cy.get(".nav-item").should('not.contain', queryName)
cy.get(".nav-item").should('not.contain', queryRename)
})
const switchSchema = (schema) => {
// Edit configuration - Change Schema
cy.get(".spectrum-Textfield").eq(6).within(() => {
cy.get('input').clear().type(schema)
})
// Save configuration & fetch
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.get(".spectrum-Button").contains("Fetch tables").click({ force: true })
// Click fetch tables again within modal
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Button").contains("Fetch tables").click({ force: true })
})
cy.reload()
cy.wait(5000)
}
} }
}) // Confirm deletion
cy.get(".nav-item").should("not.contain", queryName)
cy.get(".nav-item").should("not.contain", queryRename)
})
const switchSchema = schema => {
// Edit configuration - Change Schema
cy.get(".spectrum-Textfield")
.eq(6)
.within(() => {
cy.get("input").clear().type(schema)
})
// Save configuration & fetch
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.get(".spectrum-Button")
.contains("Fetch tables")
.click({ force: true })
// Click fetch tables again within modal
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(".spectrum-Button")
.contains("Fetch tables")
.click({ force: true })
})
cy.reload()
cy.wait(5000)
}
}
})
}) })