From cf084f28775ac7caab6d06135535d5eef16f2a0a Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 10 Aug 2020 15:34:37 +0100 Subject: [PATCH] cypress + unit test framework --- .../integration/createComponents.spec.js | 2 +- .../cypress/integration/createTable.spec.js | 37 +++-- .../integration/createWorkflow.spec.js | 2 +- packages/builder/cypress/support/commands.js | 26 ++-- .../builder/src/builderStore/store/backend.js | 13 +- .../ModelDataTable/ModelDataTable.svelte | 54 +++---- .../modals/CreateEditColumn.svelte | 10 +- .../ModelDataTable/modals/DeleteTable.svelte | 64 +++++++++ .../popovers/ColumnHeader.svelte | 27 ++-- ...ateEditTable.svelte => CreateTable.svelte} | 5 +- .../nav/ModelNavigator/EditTable.svelte | 133 ++++++++++++++++++ .../nav/ModelNavigator/ListItem.svelte | 3 +- .../nav/ModelNavigator/ModelNavigator.svelte | 7 +- .../builder/src/constants/backend/index.js | 18 +-- 14 files changed, 296 insertions(+), 105 deletions(-) create mode 100644 packages/builder/src/components/database/ModelDataTable/modals/DeleteTable.svelte rename packages/builder/src/components/nav/ModelNavigator/{CreateEditTable.svelte => CreateTable.svelte} (94%) create mode 100644 packages/builder/src/components/nav/ModelNavigator/EditTable.svelte diff --git a/packages/builder/cypress/integration/createComponents.spec.js b/packages/builder/cypress/integration/createComponents.spec.js index d6c471b74f..2e247f7110 100644 --- a/packages/builder/cypress/integration/createComponents.spec.js +++ b/packages/builder/cypress/integration/createComponents.spec.js @@ -5,7 +5,7 @@ xcontext('Create Components', () => { cy.visit('localhost:4001/_builder') // https://on.cypress.io/type cy.createApp('Model App', 'Model App Description') - cy.createModel('dog', 'name', 'age') + cy.createTable('dog', 'name', 'age') cy.addRecord('bob', '15') }) diff --git a/packages/builder/cypress/integration/createTable.spec.js b/packages/builder/cypress/integration/createTable.spec.js index d44a7cc6d6..7a567af426 100644 --- a/packages/builder/cypress/integration/createTable.spec.js +++ b/packages/builder/cypress/integration/createTable.spec.js @@ -1,42 +1,41 @@ -xcontext('Create a Table', () => { +context('Create a Table', () => { before(() => { cy.visit('localhost:4001/_builder') - // https://on.cypress.io/type cy.createApp('Table App', 'Table App Description') }) // https://on.cypress.io/interacting-with-elements it('should create a new Table', () => { - cy.createTable('dog', 'name', 'age') + cy.createTable('dog') // Check if Table exists cy.get('.title').should('have.text', 'dog') }) - it('adds a new column to the table', () => { - cy.addRecord('bob', '15') + // it('adds a new column to the table', () => { + // cy.addRecord('bob', '15') - cy.contains('bob').should('have.text', 'bob') - }) + // cy.contains('bob').should('have.text', 'bob') + // }) - it('updates a column on the table', () => { - cy.addRecord('bob', '15') + // it('updates a column on the table', () => { + // cy.addRecord('bob', '15') - cy.contains('bob').should('have.text', 'bob') - }) + // cy.contains('bob').should('have.text', 'bob') + // }) - it('edits a record', () => { - cy.addRecord('bob', '15') + // it('edits a record', () => { + // cy.addRecord('bob', '15') - cy.contains('bob').should('have.text', 'bob') - }) + // cy.contains('bob').should('have.text', 'bob') + // }) - it('deletes a record', () => { - cy.addRecord('bob', '15') + // it('deletes a record', () => { + // cy.addRecord('bob', '15') - cy.contains('bob').should('have.text', 'bob') - }) + // cy.contains('bob').should('have.text', 'bob') + // }) }) diff --git a/packages/builder/cypress/integration/createWorkflow.spec.js b/packages/builder/cypress/integration/createWorkflow.spec.js index ed14ce1487..f341bf86b1 100644 --- a/packages/builder/cypress/integration/createWorkflow.spec.js +++ b/packages/builder/cypress/integration/createWorkflow.spec.js @@ -9,7 +9,7 @@ xcontext('Create a workflow', () => { // https://on.cypress.io/interacting-with-elements it('should create a workflow', () => { - cy.createModel('dog', 'name', 'age') + cy.createTable('dog', 'name', 'age') cy.contains('workflow').click() cy.contains('Create New Workflow').click() diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index abd44d7061..d6e2ce5ad5 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -57,22 +57,28 @@ Cypress.Commands.add("createApp", name => { }) }) -Cypress.Commands.add("createModel", modelName => { +Cypress.Commands.add("createTable", tableName => { // Enter model name cy.contains("Create New Table").click() - cy.get("[data-cy=table-name-input]").type(modelName) + cy.get("[placeholder='Table Name']").type(tableName) // Add 'name' field - cy.contains("Add").click() - cy.contains("Plain Text").click() - - // Add 'age' field - cy.contains("Add").click() - cy.contains("Number").click() - cy.contains("Save").click() + cy.contains(tableName).should("be.visible") +}) - cy.contains(modelName).click() +Cypress.Commands.add("addColumn", (tableName, columnName, type) => { + // Select Table + cy.contains(tableName).click() + + // Click "Create New Column" + // Fill in dropdown + //hit save + // assertions + + // Add 'name' field + cy.contains("Save").click() + cy.contains(modelName).should("be.visible").click() }) Cypress.Commands.add("addRecord", (firstField, secondField) => { diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index 3063c71a82..09227c09a7 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -83,13 +83,16 @@ export const getBackendUiStore = () => { await store.actions.models.fetch() store.actions.models.select(savedModel) }, + delete: async model => { + await api.delete(`/api/models/${model._id}/${model._rev}`) + store.update(state => { + state.selectedModel = state.models[0] || {} + state.models = state.models.filter(existing => existing._id !== model._id) + return state + }) + }, saveField: ({ originalName, field }) => { store.update(state => { - // TODO: is this necessary? - // if (!state.draftModel.schema) { - // state.draftModel.schema = {} - // } - // delete the original if renaming delete state.draftModel.schema[originalName] diff --git a/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte b/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte index 7476e7454e..8bebccd07d 100644 --- a/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte +++ b/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte @@ -1,6 +1,6 @@
- + +