From b473b56817b44b0776b925d9c99cb80b35c58ff3 Mon Sep 17 00:00:00 2001 From: grnd-alt Date: Mon, 26 Aug 2024 14:23:46 +0200 Subject: [PATCH] add cypress test for scheme export import Signed-off-by: grnd-alt --- REUSE.toml | 2 +- cypress/e2e/ToDo list.json | 1 + cypress/e2e/tables-import-export-scheme.cy.js | 59 +++++++++++++++++++ lib/Controller/ApiTablesController.php | 2 +- 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 cypress/e2e/ToDo list.json create mode 100644 cypress/e2e/tables-import-export-scheme.cy.js diff --git a/REUSE.toml b/REUSE.toml index cde04c60a..ffc1d9dfb 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -6,7 +6,7 @@ SPDX-PackageSupplier = "Nextcloud " SPDX-PackageDownloadLocation = "https://github.com/nextcloud/tables" [[annotations]] -path = [".tx/config", "l10n/**.js", "l10n/**.json", "composer.json", "composer.lock", "package.json", "package-lock.json"] +path = [".tx/config", "l10n/**.js", "l10n/**.json", "composer.json", "composer.lock", cypress/e2e/ToDo list.json", "package.json", "package-lock.json"] precedence = "aggregate" SPDX-FileCopyrightText = "2021 Nextcloud GmbH and Nextcloud contributors" SPDX-License-Identifier = "AGPL-3.0-or-later" diff --git a/cypress/e2e/ToDo list.json b/cypress/e2e/ToDo list.json new file mode 100644 index 000000000..a9d37a099 --- /dev/null +++ b/cypress/e2e/ToDo list.json @@ -0,0 +1 @@ +{"title":"ToDo list","emoji":"\u2705","columns":[{"id":491,"tableId":132,"title":"Task","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"text","subtype":"line","mandatory":true,"description":"","numberDefault":null,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false},{"id":492,"tableId":132,"title":"Description","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"text","subtype":"rich","mandatory":false,"description":"Title or short description","numberDefault":null,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false},{"id":493,"tableId":132,"title":"Target","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"text","subtype":"rich","mandatory":false,"description":"Date, time or whatever","numberDefault":null,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false},{"id":494,"tableId":132,"title":"Progress","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"number","subtype":"progress","mandatory":false,"description":"","numberDefault":0,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false},{"id":495,"tableId":132,"title":"Comments","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"text","subtype":"rich","mandatory":false,"description":"","numberDefault":null,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false},{"id":496,"tableId":132,"title":"Proofed","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"selection","subtype":"check","mandatory":false,"description":"","numberDefault":null,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false}],"views":[],"description":"","tablesVersion":"0.8.0-beta.2"} \ No newline at end of file diff --git a/cypress/e2e/tables-import-export-scheme.cy.js b/cypress/e2e/tables-import-export-scheme.cy.js new file mode 100644 index 000000000..43ac22e8b --- /dev/null +++ b/cypress/e2e/tables-import-export-scheme.cy.js @@ -0,0 +1,59 @@ +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +let localUser + +const omitSubFields = (array, fields) => { + return array.map( + (item) => Object.keys(item).filter( + filterKey => !fields.includes(filterKey)).reduce( + (obj, key) => { + obj[key] = item[key] + return obj + }, {}), + ) +} + +describe('Import Export Scheme', () => { + + before(function() { + cy.createRandomUser().then(user => { + localUser = user + }) + }) + + beforeEach(function() { + cy.login(localUser) + cy.visit('apps/tables') + }) + + it('Import table from scheme', () => { + cy.get('.icon-loading').should('not.exist') + cy.get('[data-cy="navigationCreateTableIcon"]').click({ force: true }) + cy.get('p').contains('Import Scheme').click({ force: true }) + cy.contains('button', 'Create table').scrollIntoView().click() + cy.get('input[type=file].hidden-visually').selectFile('./cypress/e2e/ToDo list.json', { force: true }) + cy.get('button').contains('Import').click() + cy.get('.app-navigation-toggle-wrapper').should('be.visible').click() + cy.get('.app-navigation__list').contains('ToDo list').should('exist') + }) + + it('Export scheme to json', () => { + const columnFieldsToIgnore = ['id', 'tableId', 'createdAt', 'lastEditAt', 'createdBy', 'createdByDisplayName', 'lastEditBy', 'lastEditByDisplayName'] + cy.get('.app-navigation-toggle-wrapper').should('be.visible').click() + cy.get('.app-navigation__list').contains('ToDo list').click() + cy.get('.row.first-row').should('be.visible') + cy.get('.app-navigation__list').contains('ToDo list').trigger('mouseover') + cy.get('.app-navigation-entry__actions').last('').click() + cy.get('.action-button__text').contains('Export').click() + const downloadsFolder = Cypress.config('downloadsFolder') + cy.readFile('./cypress/e2e/ToDo list.json').then(content => { + cy.readFile(`${downloadsFolder}/ToDo list.json`).then(expectedContent => { + expectedContent.columns = omitSubFields(expectedContent.columns, columnFieldsToIgnore) + content.columns = omitSubFields(content.columns, columnFieldsToIgnore) + expect(JSON.stringify(expectedContent)).to.eq(JSON.stringify(content)) + }) + }) + }) +}) diff --git a/lib/Controller/ApiTablesController.php b/lib/Controller/ApiTablesController.php index 4e275d2ff..2d6ab5fc6 100644 --- a/lib/Controller/ApiTablesController.php +++ b/lib/Controller/ApiTablesController.php @@ -163,7 +163,7 @@ public function createFromScheme(string $title, string $emoji, string $descripti $column['datetimeDefault'], - $column['usergroupDefault'] || [], + $column['usergroupDefault'][0] ?? '', $column['usergroupMultipleItems'], $column['usergroupSelectUsers'], $column['usergroupSelectGroups'],