forked from tsai/budibase
Browse Source
New tests: -Query Level Transformers -Table pagination -User Roles -Data Sources (correct config, incorrect config, Wizard) Also: -New Commands to support Testing -Cypress Updatedmaster
11 changed files with 1535 additions and 430 deletions
@ -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,125 @@ |
|||
context("Create a User and Assign Roles", () => { |
|||
before(() => { |
|||
cy.login() |
|||
}) |
|||
|
|||
it("should create a user", () => { |
|||
cy.createUser("bbuser@test.com") |
|||
cy.contains("bbuser").should("be.visible") |
|||
}) |
|||
|
|||
it("should confirm there is No Access for a New User", () => { |
|||
// Click into the user
|
|||
cy.contains("bbuser").click() |
|||
// 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(`localhost:${Cypress.env("PORT")}/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(`localhost:${Cypress.env("PORT")}/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.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.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-Form-item").click() |
|||
}) |
|||
// 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-Form-item").click() |
|||
}) |
|||
// 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,50 @@ |
|||
context("Add and Configure External Data Sources", () => { |
|||
before(() => { |
|||
cy.login() |
|||
cy.createTestApp() |
|||
}) |
|||
|
|||
it("should add and configure a PostgreSQL data source", () => { |
|||
// Select PostgreSQL datasource and add config
|
|||
const datasource = "PostgreSQL" |
|||
cy.selectExternalDatasource(datasource) |
|||
cy.addSqlDatasourceConfig(datasource) |
|||
|
|||
// Confirm fetch tables was successful
|
|||
cy.get(".query-list").then(() => { |
|||
cy.get(".query-list-item").should('exist') |
|||
}) |
|||
}) |
|||
|
|||
it("should add and configure a MySQL data source", () => { |
|||
// Select MySQL datasource and add config
|
|||
const datasource = "MySQL" |
|||
cy.selectExternalDatasource(datasource) |
|||
cy.addSqlDatasourceConfig(datasource) |
|||
|
|||
// Confirm fetch tables was successful
|
|||
cy.get(".query-list").then(() => { |
|||
cy.get(".query-list-item").should('exist') |
|||
}) |
|||
}) |
|||
|
|||
it("should add and configure a REST data source", () => { |
|||
// Select REST datasource and add config
|
|||
const datasource = "REST" |
|||
const restUrl = "https://api.openbrewerydb.org/breweries" |
|||
cy.selectExternalDatasource(datasource) |
|||
cy.addRestDatasourceConfig(restUrl) |
|||
|
|||
// Following config - Click Add Query, then Run Query
|
|||
cy.get(".spectrum-Button").contains("Add Query").click({ force: true }) |
|||
cy.wait(500) |
|||
cy.get(".viewer-controls").within(() => { |
|||
cy.get(".spectrum-Button").contains("Run Query").click({ force: true }) |
|||
}) |
|||
// Get the results from running query
|
|||
cy.get(".viewer").within(() => { |
|||
cy.get(".preview").should( |
|||
'not.have.value', 'Please run your query to fetch some data.') |
|||
}) |
|||
}) |
|||
}) |
|||
@ -0,0 +1,39 @@ |
|||
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 = "PostgreSQL" |
|||
cy.selectExternalDatasource(datasource) |
|||
cy.addSqlDatasourceConfig(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 }) |
|||
}) |
|||
|
|||
// Immediately fetch tables after selection
|
|||
// Previously entered config should not have been saved
|
|||
// Config is back to default values - Modal will not close (incorrect config)
|
|||
cy.get(".spectrum-Dialog-grid").within(() => { |
|||
cy.get(".spectrum-Button").contains("Fetch tables from database").click({ force: true }) |
|||
}) |
|||
cy.wait(2000) |
|||
cy.get(".spectrum-Dialog-grid").should('be.visible') |
|||
|
|||
// Close the modal
|
|||
cy.get(".spectrum-Dialog-grid").within(() => { |
|||
cy.get(".close-icon").click() |
|||
}) |
|||
}) |
|||
}) |
|||
@ -0,0 +1,29 @@ |
|||
context("Incorrect Datasource Configuration", () => { |
|||
before(() => { |
|||
cy.login() |
|||
cy.createTestApp() |
|||
}) |
|||
|
|||
it("should add incorrect config for PostgreSQL", () => { |
|||
// This test tries to fetch immediately after selecting the datasource
|
|||
// No config is entered (default values used)
|
|||
// Select PostgreSQL datasource
|
|||
cy.selectExternalDatasource("PostgreSQL") |
|||
|
|||
// Attempt to fetch tables without applying config
|
|||
cy.get(".spectrum-Dialog-grid").within(() => { |
|||
cy.get(".spectrum-Button").contains( |
|||
"Fetch tables from database").click({ force: true }) |
|||
}) |
|||
|
|||
// Wait 2 seconds then assert Modal has not closed
|
|||
// Modal will not close if config is incorrect
|
|||
cy.wait(2000) |
|||
cy.get(".spectrum-Dialog-grid").should('be.visible') |
|||
|
|||
// Close the modal
|
|||
cy.get(".spectrum-Dialog-grid").within(() => { |
|||
cy.get(".close-icon").click() |
|||
}) |
|||
}) |
|||
}) |
|||
@ -0,0 +1,124 @@ |
|||
context("Query Level Transformers", () => { |
|||
before(() => { |
|||
cy.login() |
|||
cy.createTestApp() |
|||
}) |
|||
|
|||
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.addRestDatasourceConfig(restUrl) |
|||
// Add Query
|
|||
cy.get(".spectrum-Button").contains("Add Query").click({ force: true }) |
|||
cy.wait(500) |
|||
addTransformerQuery() |
|||
// Run Query
|
|||
cy.get(".spectrum-Button").contains("Run Query").click({ force: true }) |
|||
cy.wait(500) |
|||
// Confirm JSON results
|
|||
cy.get(".preview").should('have.text', '{\n "state": "Indiana",\n "count": 1\n}') |
|||
}) |
|||
|
|||
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.addRestDatasourceConfig(restUrl) |
|||
// Add Query
|
|||
cy.get(".spectrum-Button").contains("Add Query").click({ force: true }) |
|||
cy.wait(500) |
|||
addTransformerQuery(true) |
|||
// Run Query
|
|||
cy.get(".spectrum-Button").contains("Run Query").click({ force: true }) |
|||
cy.wait(500) |
|||
// Confirm JSON results
|
|||
cy.get(".preview").should( |
|||
'have.text', |
|||
'{\n "state": "Indiana",\n "count": 1,\n "flag": "http://flags.ox3.in/svg/us/${stateCode}.svg"\n}') |
|||
}) |
|||
|
|||
it("should run an invalid query via POST request", () => { |
|||
// POST request with transformer as null
|
|||
cy.request({method: 'POST', |
|||
url: 'https://test.budi.live/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: 'https://test.budi.live/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') |
|||
}) |
|||
}) |
|||
|
|||
const addTransformerQuery = (addData = false) => { |
|||
// Adds query within the Transformer section of Query REST API
|
|||
cy.get(".CodeMirror textarea") |
|||
// Highlight current text within CodeMirror
|
|||
.type(Cypress.platform === 'darwin' ? '{cmd}a' : '{ctrl}a', { force: true }) |
|||
// Overwrite current text with function
|
|||
.type("const breweries = data\n" + |
|||
"const totals = {}\n" + |
|||
"for (let brewery of breweries) {") |
|||
// Delete key in place to remove extra brackets that are added
|
|||
.type('{del}') |
|||
.type("\n const state = brewery.state\n" + |
|||
" if (totals[state] == null) {") |
|||
.type('{del}') |
|||
.type("\n totals[state] = 1\n" + |
|||
"} else {") |
|||
.type('{del}') |
|||
.type("\n totals[state]++\n" + |
|||
"}}\n", { parseSpecialCharSequences: false }) |
|||
|
|||
if (addData) { |
|||
cy.get(".CodeMirror textarea") |
|||
.type('const stateCodes = {"texas":"tx",\n' + |
|||
'"colorado":"co",\n' + |
|||
'"florida":"fl",\n' + |
|||
'"iwoa":"ia",\n' + |
|||
'"louisiana":"la",\n' + |
|||
'"california":"ca",\n' + |
|||
'"pennsylvania":"pa",\n' + |
|||
'"georgia":"ga",\n' + |
|||
'"new hampshire":"nh",\n' + |
|||
'"virginia":"va",\n' + |
|||
'"michigan":"mi",\n' + |
|||
'"maryland":"md",\n' + |
|||
'"ohio":"oh"}\n') |
|||
.type('const entries = Object.entries(totals)\n' + |
|||
"return entries.map(([state, count]) => \n" + |
|||
"{ const stateCode = stateCodes[state.toLowerCase()]\n" + |
|||
"return {state, count, flag: 'http://flags.ox3.in/svg/us/${stateCode}.svg'", |
|||
{ parseSpecialCharSequences: false }) |
|||
} |
|||
else{ |
|||
cy.get(".CodeMirror textarea") |
|||
.type("const entries = Object.entries(totals)\n" + |
|||
"return entries.map(([state, count]) => ({state, count}))", |
|||
{ parseSpecialCharSequences: false }) |
|||
} |
|||
} |
|||
}) |
|||
File diff suppressed because it is too large
Loading…
Reference in new issue