full cypress suite for new backend

This commit is contained in:
Martin McKeaveney 2020-08-10 17:51:30 +01:00
parent 8a4646ca4c
commit 2a04147c4b
9 changed files with 91 additions and 42 deletions

View File

@ -1,41 +1,70 @@
context('Create a Table', () => { context('Create a Table', () => {
before(() => { before(() => {
cy.visit('localhost:4001/_builder') cy.visit('localhost:4001/_builder')
cy.createApp('Table App', 'Table App Description') cy.createApp('Table App', 'Table App Description')
}) })
// https://on.cypress.io/interacting-with-elements
it('should create a new Table', () => { it('should create a new Table', () => {
cy.createTable('dog') cy.createTable('dog')
// Check if Table exists // Check if Table exists
cy.get('.title').should('have.text', 'dog') cy.get('.title').should('have.text', 'dog')
}) })
// it('adds a new column to the table', () => { it('adds a new column to the table', () => {
// cy.addRecord('bob', '15') cy.addColumn('dog', 'name', 'Plain Text')
// cy.contains('bob').should('have.text', 'bob') cy.contains('name').should("be.visible")
// }) })
// it('updates a column on the table', () => { it('creates a record in the table', () => {
// cy.addRecord('bob', '15') cy.addRecord(["Rover"])
// cy.contains('bob').should('have.text', 'bob') cy.contains('Rover').should("be.visible")
// }) })
// it('edits a record', () => { it('updates a column on the table', () => {
// cy.addRecord('bob', '15') cy.contains("name").click()
cy.get("[data-cy='edit-column-header']").click()
// cy.contains('bob').should('have.text', 'bob') cy.get("[placeholder=Name]").type("updated")
// }) cy.get("select").select("Plain Text")
// it('deletes a record', () => { cy.contains("Save Column").click()
// cy.addRecord('bob', '15')
// cy.contains('bob').should('have.text', 'bob') cy.contains('nameupdated').should('have.text', 'nameupdated ')
// }) })
it('edits a record', () => {
cy.get("tbody .ri-more-line").click()
cy.get("[data-cy=edit-row]").click()
cy.get(".actions input").type("updatedRecord")
cy.contains("Save").click()
cy.contains('updatedRecord').should('have.text', 'updatedRecord')
})
it('deletes a record', () => {
cy.get("tbody .ri-more-line").click()
cy.get("[data-cy=delete-row]").click()
cy.get(".modal-actions").contains("Delete").click()
cy.contains('updatedRecord').should('not.exist')
})
it('deletes a column', () => {
cy.contains("name").click()
cy.get("[data-cy='delete-column-header']").click()
cy.contains('nameupdated').should('not.exist')
})
it('deletes a table', () => {
cy.contains("div", "dog").get(".ri-more-line").click()
cy.get("[data-cy=delete-table]").click()
cy.get(".modal-actions").contains("Delete").click()
cy.contains('dog').should('not.exist')
})
}) })

View File

@ -70,22 +70,22 @@ Cypress.Commands.add("createTable", tableName => {
Cypress.Commands.add("addColumn", (tableName, columnName, type) => { Cypress.Commands.add("addColumn", (tableName, columnName, type) => {
// Select Table // Select Table
cy.contains(tableName).click() cy.contains(tableName).click()
cy.contains("Create New Column").click()
// Click "Create New Column" cy.get("[placeholder=Name]").type(columnName)
// Fill in dropdown cy.get("select").select(type)
//hit save
// assertions cy.contains("Save Column")
// Add 'name' field
cy.contains("Save").click() cy.contains("Save").click()
cy.contains(modelName).should("be.visible").click()
}) })
Cypress.Commands.add("addRecord", (firstField, secondField) => { Cypress.Commands.add("addRecord", values => {
cy.contains("Create New Record").click() cy.contains("Create New Row").click()
cy.get("[data-cy='Plain Text-input']").type(firstField) for (let i = 0; i < values.length; i++) {
cy.get("[data-cy=Number-input]").type(secondField) cy.get("input").eq(i).type(values[i])
}
// Save // Save
cy.contains("Save").click() cy.contains("Save").click()

View File

@ -82,12 +82,13 @@ export const getBackendUiStore = () => {
const savedModel = await response.json() const savedModel = await response.json()
await store.actions.models.fetch() await store.actions.models.fetch()
store.actions.models.select(savedModel) store.actions.models.select(savedModel)
return savedModel
}, },
delete: async model => { delete: async model => {
await api.delete(`/api/models/${model._id}/${model._rev}`) await api.delete(`/api/models/${model._id}/${model._rev}`)
store.update(state => { store.update(state => {
state.selectedModel = state.models[0] || {}
state.models = state.models.filter(existing => existing._id !== model._id) state.models = state.models.filter(existing => existing._id !== model._id)
state.selectedModel = state.models[0] || {}
return state return state
}) })
}, },

View File

@ -45,17 +45,14 @@
<DropdownMenu bind:this={dropdown} {anchor} align="left"> <DropdownMenu bind:this={dropdown} {anchor} align="left">
{#if editing} {#if editing}
<h4>Edit Column</h4> <h4>Edit Column</h4>
<CreateEditColumn <CreateEditColumn onClosed={hideEditor} {field} />
onClosed={hideEditor}
field={field}
/>
{:else} {:else}
<ul> <ul>
<li on:click={showEditor}> <li data-cy="edit-column-header" on:click={showEditor}>
<Icon name="edit" /> <Icon name="edit" />
Edit Edit
</li> </li>
<li on:click={deleteField}> <li data-cy="delete-column-header" on:click={deleteField}>
<Icon name="delete" /> <Icon name="delete" />
Delete Delete
</li> </li>

View File

@ -48,11 +48,11 @@
<CreateEditRecord onClosed={hideEditor} record={row} /> <CreateEditRecord onClosed={hideEditor} record={row} />
{:else} {:else}
<ul> <ul>
<li on:click={showEditor}> <li data-cy="edit-row" on:click={showEditor}>
<Icon name="edit" /> <Icon name="edit" />
Edit Edit
</li> </li>
<li on:click={deleteRow}> <li data-cy="delete-row" on:click={deleteRow}>
<Icon name="delete" /> <Icon name="delete" />
Delete Delete
</li> </li>

View File

@ -1,4 +1,5 @@
<script> <script>
import { goto } from "@sveltech/routify"
import { backendUiStore } from "builderStore" import { backendUiStore } from "builderStore"
import { notifier } from "builderStore/store/notifications" import { notifier } from "builderStore/store/notifications"
import { DropdownMenu, Button, Icon, Input, Select } from "@budibase/bbui" import { DropdownMenu, Button, Icon, Input, Select } from "@budibase/bbui"
@ -10,11 +11,12 @@
let name let name
async function saveTable() { async function saveTable() {
await backendUiStore.actions.models.save({ const model = await backendUiStore.actions.models.save({
name, name,
schema: {}, schema: {},
}) })
notifier.success(`Table ${name} created successfully.`) notifier.success(`Table ${name} created successfully.`)
$goto(`./model/${model._id}`)
dropdown.hide() dropdown.hide()
} }
</script> </script>
@ -26,6 +28,7 @@
<div class="container"> <div class="container">
<h4>Create Table</h4> <h4>Create Table</h4>
<Input <Input
data-cy="table-name-input"
placeholder="Table Name" placeholder="Table Name"
thin thin
bind:value={name} /> bind:value={name} />

View File

@ -61,7 +61,7 @@
<Icon name="edit" /> <Icon name="edit" />
Edit Edit
</li> </li>
<li on:click={deleteTable}> <li data-cy="delete-table" on:click={deleteTable}>
<Icon name="delete" /> <Icon name="delete" />
Delete Delete
</li> </li>

View File

@ -23,4 +23,6 @@
{#if $backendUiStore.models.length === 0} {#if $backendUiStore.models.length === 0}
Please create a table Please create a table
{:else}Please select a table{/if} {:else}
Please select a table
{/if}

View File

@ -775,7 +775,7 @@
lodash "^4.17.13" lodash "^4.17.13"
to-fast-properties "^2.0.0" to-fast-properties "^2.0.0"
"@budibase/bbui@^1.18.0": "@budibase/bbui@^1.23.0":
version "1.23.0" version "1.23.0"
resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.23.0.tgz#ffcc35a378dca2bdb0a72076d2aec530a11a8a42" resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.23.0.tgz#ffcc35a378dca2bdb0a72076d2aec530a11a8a42"
integrity sha512-Ix3yFG4hRwmLjPcvCs+cU6hKtjIn+KMfEfzQjNM9RWKoSH08812606LDNf3r/povO6/sxpiUNWZJcGvvdW6gBQ== integrity sha512-Ix3yFG4hRwmLjPcvCs+cU6hKtjIn+KMfEfzQjNM9RWKoSH08812606LDNf3r/povO6/sxpiUNWZJcGvvdW6gBQ==
@ -3587,6 +3587,11 @@ fast-levenshtein@~2.0.6:
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=
fast-sort@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/fast-sort/-/fast-sort-2.2.0.tgz#20903763531fbcbb41c9df5ab1bf5f2cefc8476a"
integrity sha512-W7zqnn2zsYoQA87FKmYtgOsbJohOrh7XrtZrCVHN5XZKqTBTv5UG+rSS3+iWbg/nepRQUOu+wnas8BwtK8kiCg==
fastq@^1.6.0: fastq@^1.6.0:
version "1.7.0" version "1.7.0"
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.7.0.tgz#fcd79a08c5bd7ec5b55cd3f5c4720db551929801" resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.7.0.tgz#fcd79a08c5bd7ec5b55cd3f5c4720db551929801"
@ -3940,6 +3945,11 @@ har-validator@~5.1.3:
ajv "^6.5.5" ajv "^6.5.5"
har-schema "^2.0.0" har-schema "^2.0.0"
harmony-reflect@^1.4.6:
version "1.6.1"
resolved "https://registry.yarnpkg.com/harmony-reflect/-/harmony-reflect-1.6.1.tgz#c108d4f2bb451efef7a37861fdbdae72c9bdefa9"
integrity sha512-WJTeyp0JzGtHcuMsi7rw2VwtkvLa+JyfEKJCFyfcS0+CDkjQ5lHPu7zEhFZP+PDSRrEgXa5Ah0l1MbgbE41XjA==
has-ansi@^2.0.0: has-ansi@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
@ -4136,6 +4146,13 @@ idb-wrapper@^1.5.0:
resolved "https://registry.yarnpkg.com/idb-wrapper/-/idb-wrapper-1.7.2.tgz#8251afd5e77fe95568b1c16152eb44b396767ea2" resolved "https://registry.yarnpkg.com/idb-wrapper/-/idb-wrapper-1.7.2.tgz#8251afd5e77fe95568b1c16152eb44b396767ea2"
integrity sha512-zfNREywMuf0NzDo9mVsL0yegjsirJxHpKHvWcyRozIqQy89g0a3U+oBPOCN4cc0oCiOuYgZHimzaW/R46G1Mpg== integrity sha512-zfNREywMuf0NzDo9mVsL0yegjsirJxHpKHvWcyRozIqQy89g0a3U+oBPOCN4cc0oCiOuYgZHimzaW/R46G1Mpg==
identity-obj-proxy@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/identity-obj-proxy/-/identity-obj-proxy-3.0.0.tgz#94d2bda96084453ef36fbc5aaec37e0f79f1fc14"
integrity sha1-lNK9qWCERT7zb7xarsN+D3nx/BQ=
dependencies:
harmony-reflect "^1.4.6"
ignore@^5.1.1: ignore@^5.1.1:
version "5.1.4" version "5.1.4"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.4.tgz#84b7b3dbe64552b6ef0eca99f6743dbec6d97adf" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.4.tgz#84b7b3dbe64552b6ef0eca99f6743dbec6d97adf"