forked from tsai/budibase
72 changed files with 2747 additions and 648 deletions
@ -1,9 +1,11 @@ |
|||||
{ |
{ |
||||
"baseUrl": "http://localhost:10001/builder/", |
"baseUrl": "http://localhost:10001", |
||||
"video": true, |
"video": true, |
||||
"projectId": "bmbemn", |
"projectId": "bmbemn", |
||||
"env": { |
"env": { |
||||
"PORT": "10001", |
"PORT": "10001", |
||||
"JWT_SECRET": "test" |
"JWT_SECRET": "test", |
||||
|
"HOST_IP": "52.49.184.138", |
||||
|
"TEST_ENV" : false |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,47 @@ |
|||||
|
context("Auto Screens UI", () => { |
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
cy.createTestApp() |
||||
|
}) |
||||
|
|
||||
|
it("should generate internal table screens", () => { |
||||
|
// Create autogenerated screens from the internal table
|
||||
|
cy.createAutogeneratedScreens(["Cypress Tests"]) |
||||
|
// Confirm screens have been auto generated
|
||||
|
cy.get(".nav-items-container").contains("cypress-tests").click() |
||||
|
cy.get(".nav-items-container").should('contain', 'cypress-tests/:id') |
||||
|
.and('contain', 'cypress-tests/new/row') |
||||
|
}) |
||||
|
|
||||
|
it("should generate multiple internal table screens at once", () => { |
||||
|
// Create a second internal table
|
||||
|
const initialTable = "Cypress Tests" |
||||
|
const secondTable = "Table Two" |
||||
|
cy.createTable(secondTable) |
||||
|
// Create autogenerated screens from the internal tables
|
||||
|
cy.createAutogeneratedScreens([initialTable, secondTable]) |
||||
|
// Confirm screens have been auto generated
|
||||
|
cy.get(".nav-items-container").contains("cypress-tests").click() |
||||
|
// Previously generated tables are suffixed with numbers - as expected
|
||||
|
cy.get(".nav-items-container").should('contain', 'cypress-tests-2/:id') |
||||
|
.and('contain', 'cypress-tests-2/new/row') |
||||
|
cy.get(".nav-items-container").contains("table-two").click() |
||||
|
cy.get(".nav-items-container").should('contain', 'table-two/:id') |
||||
|
.and('contain', 'table-two/new/row') |
||||
|
}) |
||||
|
|
||||
|
if (Cypress.env("TEST_ENV")) { |
||||
|
it("should generate data source screens", () => { |
||||
|
// Using MySQL data source for testing this
|
||||
|
const datasource = "MySQL" |
||||
|
// Select & configure MySQL data source
|
||||
|
cy.selectExternalDatasource(datasource) |
||||
|
cy.addDatasourceConfig(datasource) |
||||
|
// Create autogenerated screens from a MySQL table - MySQL contains books table
|
||||
|
cy.createAutogeneratedScreens(["books"]) |
||||
|
cy.get(".nav-items-container").contains("books").click() |
||||
|
cy.get(".nav-items-container").should('contain', 'books/:id') |
||||
|
.and('contain', 'books/new/row') |
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
@ -0,0 +1,39 @@ |
|||||
|
context("Change Application Icon and Colour", () => { |
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
}) |
||||
|
|
||||
|
it("should change the icon and colour for an application", () => { |
||||
|
// Search for test application
|
||||
|
cy.searchForApplication("Cypress Tests") |
||||
|
cy.get(".appTable") |
||||
|
.within(() => { |
||||
|
cy.get(".spectrum-Icon").eq(1).click() |
||||
|
}) |
||||
|
cy.get(".spectrum-Menu").contains("Edit icon").click() |
||||
|
// Select random icon
|
||||
|
cy.get(".grid").within(() => { |
||||
|
cy.get(".icon-item").eq(Math.floor(Math.random() * 23) + 1).click() |
||||
|
}) |
||||
|
// Select random colour
|
||||
|
cy.get(".fill").click() |
||||
|
cy.get(".colors").within(() => { |
||||
|
cy.get(".color").eq(Math.floor(Math.random() * 33) + 1).click() |
||||
|
}) |
||||
|
cy.intercept('**/applications/**').as('iconChange') |
||||
|
cy.get(".spectrum-Button").contains("Save").click({ force: true }) |
||||
|
cy.wait("@iconChange") |
||||
|
cy.get("@iconChange").its('response.statusCode') |
||||
|
.should('eq', 200) |
||||
|
cy.wait(1000) |
||||
|
// Confirm icon has changed from default
|
||||
|
// Confirm colour has been applied - There is no default colour
|
||||
|
cy.get(".appTable") |
||||
|
.within(() => { |
||||
|
cy.get('[aria-label]').eq(0).children() |
||||
|
.should('have.attr', 'xlink:href').and('not.contain', '#spectrum-icon-18-Apps') |
||||
|
cy.get(".title").children().children() |
||||
|
.should('have.attr', 'style').and('contains', 'color') |
||||
|
}) |
||||
|
}) |
||||
|
}) |
||||
@ -1,10 +0,0 @@ |
|||||
context("Create a User", () => { |
|
||||
before(() => { |
|
||||
cy.login() |
|
||||
}) |
|
||||
|
|
||||
it("should create a user", () => { |
|
||||
cy.createUser("bbuser@test.com") |
|
||||
cy.contains("bbuser").should("be.visible") |
|
||||
}) |
|
||||
}) |
|
||||
@ -0,0 +1,128 @@ |
|||||
|
context("Create a User and Assign Roles", () => { |
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
}) |
||||
|
|
||||
|
it("should create a user", () => { |
||||
|
cy.createUser("bbuser@test.com") |
||||
|
cy.get(".spectrum-Table-body").should('contain', 'bbuser') |
||||
|
}) |
||||
|
|
||||
|
it("should confirm there is No Access for a New User", () => { |
||||
|
// Click into the user
|
||||
|
cy.contains("bbuser").click() |
||||
|
cy.wait(500) |
||||
|
// Get No Access table - Confirm it has apps in it
|
||||
|
cy.get(".spectrum-Table").eq(1).should('not.contain', 'No rows found') |
||||
|
// Get Configure Roles table - Confirm it has no apps
|
||||
|
cy.get(".spectrum-Table").eq(0).contains('No rows found') |
||||
|
}) |
||||
|
|
||||
|
it("should assign role types", () => { |
||||
|
// 3 apps minimum required - to assign an app to each role type
|
||||
|
cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`) |
||||
|
.its("body") |
||||
|
.then(val => { |
||||
|
if (val.length < 3) { |
||||
|
for (let i = 1; i < 3; i++) { |
||||
|
const uuid = () => Cypress._.random(0, 1e6) |
||||
|
const name = uuid() |
||||
|
cy.createApp(name) |
||||
|
} |
||||
|
} |
||||
|
}) |
||||
|
// Navigate back to the user
|
||||
|
cy.visit(`${Cypress.config().baseUrl}/builder`) |
||||
|
cy.wait(1000) |
||||
|
cy.get(".spectrum-SideNav").contains("Users").click() |
||||
|
cy.get(".spectrum-Table").contains("bbuser").click() |
||||
|
cy.wait(500) |
||||
|
for (let i = 0; i < 3; i++) { |
||||
|
cy.get(".spectrum-Table-body").eq(1).find('tr').eq(0).click() |
||||
|
cy.wait(500) |
||||
|
cy.get(".spectrum-Dialog-grid").contains("Choose an option").click().then(() => { |
||||
|
cy.wait(500) |
||||
|
if (i == 0) { |
||||
|
cy.get(".spectrum-Popover").contains("Admin").click() |
||||
|
} |
||||
|
if (i == 1) { |
||||
|
cy.get(".spectrum-Popover").contains("Power").click() |
||||
|
} |
||||
|
if (i == 2) { |
||||
|
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
|
||||
|
cy.wait(500) |
||||
|
cy.get(".spectrum-Table-body").eq(0).within((assginedRoles) => { |
||||
|
expect(assginedRoles).to.contain("Admin") |
||||
|
expect(assginedRoles).to.contain("Power") |
||||
|
expect(assginedRoles).to.contain("Basic") |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
it("should unassign role types", () => { |
||||
|
// Set each app within Configure roles table to 'No Access'
|
||||
|
cy.get(".spectrum-Table-body").eq(0).find('tr').its('length').then((len) => { |
||||
|
for (let i = 0; i < len; i ++){ |
||||
|
cy.get(".spectrum-Table-body").eq(0).find('tr').eq(0).click().then(() => { |
||||
|
cy.get(".spectrum-Form-item").contains("Role").parent().within(() => { |
||||
|
cy.get(".spectrum-Picker").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) |
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
|
// Confirm Configure roles table no longer has any apps in it
|
||||
|
cy.get(".spectrum-Table-body").eq(0).contains('No rows found') |
||||
|
}) |
||||
|
|
||||
|
it("should enable Developer access", () => { |
||||
|
// Enable Developer access
|
||||
|
cy.get(".field").eq(4).within(() => { |
||||
|
cy.get(".spectrum-Switch-input").click({ force: true }) |
||||
|
}) |
||||
|
// No Access table should now be empty
|
||||
|
cy.get(".container").contains("No Access").parent().within(() => { |
||||
|
cy.get(".spectrum-Table").contains("No rows found") |
||||
|
}) |
||||
|
|
||||
|
// Each app within Configure roles should have Admin access
|
||||
|
cy.get(".spectrum-Table-body").eq(0).find('tr').its('length').then((len) => { |
||||
|
for (let i = 0; i < len; i++) { |
||||
|
cy.get(".spectrum-Table-body").eq(0).find('tr').eq(i).contains("Admin") |
||||
|
cy.wait(500) |
||||
|
} |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
it("should disable Developer access", () => { |
||||
|
// Disable Developer access
|
||||
|
cy.get(".field").eq(4).within(() => { |
||||
|
cy.get(".spectrum-Switch-input").click({ force: true }) |
||||
|
}) |
||||
|
// Configure roles table should now be empty
|
||||
|
cy.get(".container").contains("Configure roles").parent().within(() => { |
||||
|
cy.get(".spectrum-Table").contains("No rows found") |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
it("should delete a user", () => { |
||||
|
// Click Delete user button
|
||||
|
cy.get(".spectrum-Button").contains("Delete user").click({force: true}).then(() => { |
||||
|
// Confirm deletion within modal
|
||||
|
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-body").should("not.have.text", "bbuser") |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,37 @@ |
|||||
|
context("Datasource Wizard", () => { |
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
cy.createTestApp() |
||||
|
}) |
||||
|
|
||||
|
it("should navigate in and out of a datasource via wizard", () => { |
||||
|
// Select PostgreSQL and add config (without fetch)
|
||||
|
const datasource = "Oracle" |
||||
|
cy.selectExternalDatasource(datasource) |
||||
|
cy.addDatasourceConfig(datasource, true) |
||||
|
|
||||
|
// Navigate back within datasource wizard
|
||||
|
cy.get(".spectrum-Dialog-grid").within(() => { |
||||
|
cy.get(".spectrum-Button").contains("Back").click({ force: true }) |
||||
|
cy.wait(1000) |
||||
|
}) |
||||
|
|
||||
|
// Select PostgreSQL datasource again
|
||||
|
cy.get(".item-list").contains(datasource).click() |
||||
|
cy.get(".spectrum-Dialog-grid").within(() => { |
||||
|
cy.get(".spectrum-Button").contains("Continue").click({ force: true }) |
||||
|
}) |
||||
|
|
||||
|
// Fetch tables after selection
|
||||
|
// Previously entered config should not have been saved
|
||||
|
// Config is back to default values
|
||||
|
// Modal will close and provide 500 error
|
||||
|
cy.intercept('**/datasources').as('datasourceConnection') |
||||
|
cy.get(".spectrum-Dialog-grid").within(() => { |
||||
|
cy.get(".spectrum-Button").contains("Save and fetch tables").click({ force: true }) |
||||
|
}) |
||||
|
cy.wait("@datasourceConnection") |
||||
|
cy.get("@datasourceConnection").its('response.body') |
||||
|
.should('have.property', 'status', 500) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,187 @@ |
|||||
|
context("MySQL Datasource Testing", () => { |
||||
|
if (Cypress.env("TEST_ENV")) { |
||||
|
|
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
cy.createTestApp() |
||||
|
}) |
||||
|
const datasource = "MySQL" |
||||
|
const queryName = "Cypress Test Query" |
||||
|
const queryRename = "CT Query Rename" |
||||
|
|
||||
|
it("Should add MySQL data source without configuration", () => { |
||||
|
// Select MySQL 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: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-body").eq(0) |
||||
|
.find('tr') |
||||
|
.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-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() |
||||
|
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) |
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
@ -0,0 +1,191 @@ |
|||||
|
context("Oracle Datasource Testing", () => { |
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
cy.createTestApp() |
||||
|
}) |
||||
|
const datasource = "Oracle" |
||||
|
const queryName = "Cypress Test Query" |
||||
|
const queryRename = "CT Query Rename" |
||||
|
|
||||
|
it("Should add Oracle data source and skip table fetch", () => { |
||||
|
// Select Oracle data source
|
||||
|
cy.selectExternalDatasource(datasource) |
||||
|
// Skip table fetch - no config added
|
||||
|
cy.get(".spectrum-Button").contains("Skip table fetch").click({ force: true }) |
||||
|
cy.wait(500) |
||||
|
// Confirm config contains localhost
|
||||
|
cy.get(".spectrum-Textfield-input").eq(1).should('have.value', 'localhost') |
||||
|
// Add another Oracle data source, configure & skip table fetch
|
||||
|
cy.selectExternalDatasource(datasource) |
||||
|
cy.addDatasourceConfig(datasource, true) |
||||
|
// Confirm config and no tables
|
||||
|
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
|
||||
|
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', 'NJS-007: invalid value for "user" in parameter 1') |
||||
|
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-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 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 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) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,237 @@ |
|||||
|
context("PostgreSQL Datasource Testing", () => { |
||||
|
if (Cypress.env("TEST_ENV")) { |
||||
|
|
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
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-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) |
||||
|
} |
||||
|
} |
||||
|
}) |
||||
@ -0,0 +1,39 @@ |
|||||
|
context("REST Datasource Testing", () => { |
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
cy.createTestApp() |
||||
|
}) |
||||
|
|
||||
|
const datasource = "REST" |
||||
|
const restUrl = "https://api.openbrewerydb.org/breweries" |
||||
|
|
||||
|
it("Should add REST data source with incorrect API", () => { |
||||
|
// Select REST data source
|
||||
|
cy.selectExternalDatasource(datasource) |
||||
|
// Enter incorrect api & attempt to send query
|
||||
|
cy.wait(500) |
||||
|
cy.get(".spectrum-Button").contains("Add query").click({ force: true }) |
||||
|
cy.intercept('**/preview').as('queryError') |
||||
|
cy.get("input").clear().type("random text") |
||||
|
cy.get(".spectrum-Button").contains("Send").click({ force: true }) |
||||
|
// Intercept Request after button click & apply assertions
|
||||
|
cy.wait("@queryError") |
||||
|
cy.get("@queryError").its('response.body') |
||||
|
.should('have.property', 'message', 'request to http://random/%20text? failed, reason: getaddrinfo ENOTFOUND random') |
||||
|
cy.get("@queryError").its('response.body') |
||||
|
.should('have.property', 'status', 400) |
||||
|
}) |
||||
|
|
||||
|
it("should add and configure a REST datasource", () => { |
||||
|
// Select REST datasource and create query
|
||||
|
cy.selectExternalDatasource(datasource) |
||||
|
cy.wait(500) |
||||
|
// createRestQuery confirms query creation
|
||||
|
cy.createRestQuery("GET", restUrl) |
||||
|
// Confirm status code response within REST datasource
|
||||
|
cy.get(".spectrum-FieldLabel") |
||||
|
.contains("Status") |
||||
|
.children() |
||||
|
.should('contain', 200) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,112 @@ |
|||||
|
context("Query Level Transformers", () => { |
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
cy.deleteApp("Cypress Tests") |
||||
|
cy.createApp("Cypress Tests") |
||||
|
}) |
||||
|
|
||||
|
it("should write a transformer function", () => { |
||||
|
// Add REST datasource - contains API for breweries
|
||||
|
const datasource = "REST" |
||||
|
const restUrl = "https://api.openbrewerydb.org/breweries" |
||||
|
cy.selectExternalDatasource(datasource) |
||||
|
cy.createRestQuery("GET", restUrl) |
||||
|
cy.get(".spectrum-Tabs-itemLabel").contains("Transformer").click() |
||||
|
// Get Transformer Function from file
|
||||
|
cy.readFile("cypress/support/queryLevelTransformerFunction.js").then((transformerFunction) => { |
||||
|
cy.get(".CodeMirror textarea") |
||||
|
// Highlight current text and overwrite with file contents
|
||||
|
.type(Cypress.platform === 'darwin' ? '{cmd}a' : '{ctrl}a', { force: true }) |
||||
|
.type(transformerFunction, { parseSpecialCharSequences: false }) |
||||
|
}) |
||||
|
// Send Query
|
||||
|
cy.intercept('**/queries/preview').as('query') |
||||
|
cy.get(".spectrum-Button").contains("Send").click({ force: true }) |
||||
|
cy.wait("@query") |
||||
|
// Assert against Status Code, body, & body rows
|
||||
|
cy.get("@query").its('response.statusCode') |
||||
|
.should('eq', 200) |
||||
|
cy.get("@query").its('response.body').should('not.be.empty') |
||||
|
cy.get("@query").its('response.body.rows').should('not.be.empty') |
||||
|
}) |
||||
|
|
||||
|
it("should add data to the previous query", () => { |
||||
|
// Add REST datasource - contains API for breweries
|
||||
|
const datasource = "REST" |
||||
|
const restUrl = "https://api.openbrewerydb.org/breweries" |
||||
|
cy.selectExternalDatasource(datasource) |
||||
|
cy.createRestQuery("GET", restUrl) |
||||
|
cy.get(".spectrum-Tabs-itemLabel").contains("Transformer").click() |
||||
|
// Get Transformer Function with Data from file
|
||||
|
cy.readFile("cypress/support/queryLevelTransformerFunctionWithData.js").then((transformerFunction) => { |
||||
|
//console.log(transformerFunction[1])
|
||||
|
cy.get(".CodeMirror textarea") |
||||
|
// Highlight current text and overwrite with file contents
|
||||
|
.type(Cypress.platform === 'darwin' ? '{cmd}a' : '{ctrl}a', { force: true }) |
||||
|
.type(transformerFunction, { parseSpecialCharSequences: false }) |
||||
|
}) |
||||
|
// Send Query
|
||||
|
cy.intercept('**/queries/preview').as('query') |
||||
|
cy.get(".spectrum-Button").contains("Send").click({ force: true }) |
||||
|
cy.wait("@query") |
||||
|
// Assert against Status Code, body, & body rows
|
||||
|
cy.get("@query").its('response.statusCode') |
||||
|
.should('eq', 200) |
||||
|
cy.get("@query").its('response.body').should('not.be.empty') |
||||
|
cy.get("@query").its('response.body.rows').should('not.be.empty') |
||||
|
}) |
||||
|
|
||||
|
it("should run an invalid query within the transformer section", () => { |
||||
|
// Add REST datasource - contains API for breweries
|
||||
|
const datasource = "REST" |
||||
|
const restUrl = "https://api.openbrewerydb.org/breweries" |
||||
|
cy.selectExternalDatasource(datasource) |
||||
|
cy.createRestQuery("GET", restUrl) |
||||
|
cy.get(".spectrum-Tabs-itemLabel").contains("Transformer").click() |
||||
|
// Clear the code box and add "test"
|
||||
|
cy.get(".CodeMirror textarea") |
||||
|
.type(Cypress.platform === 'darwin' ? '{cmd}a' : '{ctrl}a', { force: true }) |
||||
|
.type("test") |
||||
|
// Run Query and intercept
|
||||
|
cy.intercept('**/preview').as('queryError') |
||||
|
cy.get(".spectrum-Button").contains("Send").click({ force: true }) |
||||
|
cy.wait("@queryError") |
||||
|
cy.wait(500) |
||||
|
// Assert against message and status for the query error
|
||||
|
cy.get("@queryError").its('response.body').should('have.property', 'message', "test is not defined") |
||||
|
cy.get("@queryError").its('response.body').should('have.property', 'status', 400) |
||||
|
}) |
||||
|
|
||||
|
it("should run an invalid query via POST request", () => { |
||||
|
// POST request with transformer as null
|
||||
|
cy.request({method: 'POST', |
||||
|
url: `${Cypress.config().baseUrl}/api/queries/`, |
||||
|
body: {fields : {"headers":{},"queryString":null,"path":null}, |
||||
|
parameters : [], |
||||
|
schema : {}, |
||||
|
name : "test", |
||||
|
queryVerb : "read", |
||||
|
transformer : null, |
||||
|
datasourceId: "test"}, |
||||
|
// Expected 400 error - Transformer must be a string
|
||||
|
failOnStatusCode: false}).then((response) => { |
||||
|
expect(response.status).to.equal(400) |
||||
|
expect(response.body.message).to.include('Invalid body - "transformer" must be a string') |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
it("should run an empty query", () => { |
||||
|
// POST request with Transformer as an empty string
|
||||
|
cy.request({method: 'POST', |
||||
|
url: `${Cypress.config().baseUrl}/api/queries/preview`, |
||||
|
body: {fields : {"headers":{},"queryString":null,"path":null}, |
||||
|
queryVerb : "read", |
||||
|
transformer : "", |
||||
|
datasourceId: "test"}, |
||||
|
// Expected 400 error - Transformer is not allowed to be empty
|
||||
|
failOnStatusCode: false}).then((response) => { |
||||
|
expect(response.status).to.equal(400) |
||||
|
expect(response.body.message).to.include('Invalid body - "transformer" is not allowed to be empty') |
||||
|
}) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,62 @@ |
|||||
|
context("Revert apps", () => { |
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
cy.createTestApp() |
||||
|
}) |
||||
|
|
||||
|
it("should try to revert an unpublished app", () => { |
||||
|
// Click revert icon
|
||||
|
cy.get(".toprightnav").within(() => { |
||||
|
cy.get(".spectrum-Icon").eq(1).click() |
||||
|
}) |
||||
|
cy.get(".spectrum-Dialog-grid").within(() => { |
||||
|
// Enter app name before revert
|
||||
|
cy.get("input").type("Cypress Tests") |
||||
|
cy.intercept('**/revert').as('revertApp') |
||||
|
// Click Revert
|
||||
|
cy.get(".spectrum-Button").contains("Revert").click({ force: true }) |
||||
|
// Intercept Request after button click & apply assertions
|
||||
|
cy.wait("@revertApp") |
||||
|
cy.get("@revertApp").its('response.body').should('have.property', 'message', "App has not yet been deployed") |
||||
|
cy.get("@revertApp").its('response.body').should('have.property', 'status', 400) |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
it("should revert a published app", () => { |
||||
|
// Add initial component - Paragraph
|
||||
|
cy.addComponent("Elements", "Paragraph") |
||||
|
// Publish app
|
||||
|
cy.get(".spectrum-Button").contains("Publish").click({ force: true }) |
||||
|
cy.get(".spectrum-ButtonGroup").within(() => { |
||||
|
cy.get(".spectrum-Button").contains("Publish").click({ force: true }) |
||||
|
}) |
||||
|
// Add second component - Button
|
||||
|
cy.addComponent("Elements", "Button") |
||||
|
// Click Revert
|
||||
|
cy.get(".toprightnav").within(() => { |
||||
|
cy.get(".spectrum-Icon").eq(1).click() |
||||
|
}) |
||||
|
cy.get(".spectrum-Dialog-grid").within(() => { |
||||
|
// Click Revert
|
||||
|
cy.get(".spectrum-Button").contains("Revert").click({ force: true }) |
||||
|
cy.wait(1000) |
||||
|
}) |
||||
|
// Confirm Paragraph component is still visible
|
||||
|
cy.get(".root").contains("New Paragraph") |
||||
|
// Confirm Button component is not visible
|
||||
|
cy.get(".root").should("not.have.text", "New Button") |
||||
|
}) |
||||
|
|
||||
|
it("should enter incorrect app name when reverting", () => { |
||||
|
// Click Revert
|
||||
|
cy.get(".toprightnav").within(() => { |
||||
|
cy.get(".spectrum-Icon").eq(1).click() |
||||
|
}) |
||||
|
// Enter incorrect app name
|
||||
|
cy.get(".spectrum-Dialog-grid").within(() => { |
||||
|
cy.get("input").type("Cypress Tests") |
||||
|
// Revert button within modal should be disabled
|
||||
|
cy.get(".spectrum-Button").eq(1).should('be.disabled') |
||||
|
}) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,14 @@ |
|||||
|
// eslint-disable-next-line
|
||||
|
const breweries = data |
||||
|
const totals = {} |
||||
|
|
||||
|
for (let brewery of breweries) { |
||||
|
const state = brewery.state |
||||
|
if (totals[state] == null) { |
||||
|
totals[state] = 1 |
||||
|
} else { |
||||
|
totals[state]++ |
||||
|
} |
||||
|
} |
||||
|
const entries = Object.entries(totals) |
||||
|
return entries.map(([state, count]) => ({ state, count })) |
||||
@ -0,0 +1,31 @@ |
|||||
|
// eslint-disable-next-line
|
||||
|
const breweries = data |
||||
|
const totals = {} |
||||
|
for (let brewery of breweries) { |
||||
|
const state = brewery.state |
||||
|
if (totals[state] == null) { |
||||
|
totals[state] = 1 |
||||
|
} else { |
||||
|
totals[state]++ |
||||
|
} |
||||
|
} |
||||
|
const stateCodes = { |
||||
|
texas: "tx", |
||||
|
colorado: "co", |
||||
|
florida: "fl", |
||||
|
iwoa: "ia", |
||||
|
louisiana: "la", |
||||
|
california: "ca", |
||||
|
pennsylvania: "pa", |
||||
|
georgia: "ga", |
||||
|
"new hampshire": "nh", |
||||
|
virginia: "va", |
||||
|
michigan: "mi", |
||||
|
maryland: "md", |
||||
|
ohio: "oh", |
||||
|
} |
||||
|
const entries = Object.entries(totals) |
||||
|
return entries.map(([state, count]) => { |
||||
|
stateCodes[state.toLowerCase()] |
||||
|
return { state, count, flag: "http://flags.ox3.in/svg/us/${stateCode}.svg" } |
||||
|
}) |
||||
@ -0,0 +1,47 @@ |
|||||
|
<script> |
||||
|
import { Multiselect } from "@budibase/bbui" |
||||
|
import { |
||||
|
getDatasourceForProvider, |
||||
|
getSchemaForDatasource, |
||||
|
} from "builderStore/dataBinding" |
||||
|
import { currentAsset } from "builderStore" |
||||
|
import { tables } from "stores/backend" |
||||
|
import { createEventDispatcher } from "svelte" |
||||
|
import { getFields } from "helpers/searchFields" |
||||
|
|
||||
|
export let componentInstance = {} |
||||
|
export let value = "" |
||||
|
export let placeholder |
||||
|
|
||||
|
const dispatch = createEventDispatcher() |
||||
|
$: datasource = getDatasourceForProvider($currentAsset, componentInstance) |
||||
|
$: schema = getSchemaForDatasource($currentAsset, datasource).schema |
||||
|
$: options = getOptions(datasource, schema || {}) |
||||
|
$: boundValue = getSelectedOption(value, options) |
||||
|
|
||||
|
function getOptions(ds, dsSchema) { |
||||
|
let base = Object.values(dsSchema) |
||||
|
if (!ds?.tableId) { |
||||
|
return base |
||||
|
} |
||||
|
const currentTable = $tables.list.find(table => table._id === ds.tableId) |
||||
|
return getFields(base, { allowLinks: currentTable.sql }).map( |
||||
|
field => field.name |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
function getSelectedOption(selectedOptions, allOptions) { |
||||
|
// Fix the hardcoded default string value |
||||
|
if (!Array.isArray(selectedOptions)) { |
||||
|
selectedOptions = [] |
||||
|
} |
||||
|
return selectedOptions.filter(val => allOptions.indexOf(val) !== -1) |
||||
|
} |
||||
|
|
||||
|
const setValue = value => { |
||||
|
boundValue = getSelectedOption(value.detail, options) |
||||
|
dispatch("change", boundValue) |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<Multiselect {placeholder} value={boundValue} on:change={setValue} {options} /> |
||||
@ -0,0 +1,31 @@ |
|||||
|
import { tables } from "../stores/backend" |
||||
|
import { BannedSearchTypes } from "../constants/backend" |
||||
|
import { get } from "svelte/store" |
||||
|
|
||||
|
export function getTableFields(linkField) { |
||||
|
const table = get(tables).list.find(table => table._id === linkField.tableId) |
||||
|
if (!table || !table.sql) { |
||||
|
return [] |
||||
|
} |
||||
|
const linkFields = getFields(Object.values(table.schema), { |
||||
|
allowLinks: false, |
||||
|
}) |
||||
|
return linkFields.map(field => ({ |
||||
|
...field, |
||||
|
name: `${table.name}.${field.name}`, |
||||
|
})) |
||||
|
} |
||||
|
|
||||
|
export function getFields(fields, { allowLinks } = { allowLinks: true }) { |
||||
|
let filteredFields = fields.filter( |
||||
|
field => !BannedSearchTypes.includes(field.type) |
||||
|
) |
||||
|
if (allowLinks) { |
||||
|
const linkFields = fields.filter(field => field.type === "link") |
||||
|
for (let linkField of linkFields) { |
||||
|
// only allow one depth of SQL relationship filtering
|
||||
|
filteredFields = filteredFields.concat(getTableFields(linkField)) |
||||
|
} |
||||
|
} |
||||
|
return filteredFields |
||||
|
} |
||||
File diff suppressed because it is too large
@ -1,16 +1,26 @@ |
|||||
export const Cookies = { |
export const Cookies = { |
||||
Auth: "budibase:auth", |
Auth: "budibase:auth", |
||||
CurrentApp: "budibase:currentapp", |
CurrentApp: "budibase:currentapp", |
||||
|
ReturnUrl: "budibase:returnurl", |
||||
|
} |
||||
|
|
||||
|
export function setCookie(name, value) { |
||||
|
if (getCookie(name)) { |
||||
|
removeCookie(name) |
||||
|
} |
||||
|
window.document.cookie = `${name}=${value}; Path=/;` |
||||
} |
} |
||||
|
|
||||
export function getCookie(cookieName) { |
export function getCookie(cookieName) { |
||||
return document.cookie.split(";").some(cookie => { |
const value = `; ${document.cookie}` |
||||
return cookie.trim().startsWith(`${cookieName}=`) |
const parts = value.split(`; ${cookieName}=`) |
||||
}) |
if (parts.length === 2) { |
||||
|
return parts[1].split(";").shift() |
||||
|
} |
||||
} |
} |
||||
|
|
||||
export function removeCookie(cookieName) { |
export function removeCookie(cookieName) { |
||||
if (getCookie(cookieName)) { |
if (getCookie(cookieName)) { |
||||
document.cookie = `${cookieName}=; Max-Age=-99999999;` |
document.cookie = `${cookieName}=; Max-Age=-99999999; Path=/;` |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue