Skip to content

Commit

Permalink
add cypress test for scheme export import
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <[email protected]>
  • Loading branch information
grnd-alt committed Aug 27, 2024
1 parent 814849b commit b473b56
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-PackageSupplier = "Nextcloud <[email protected]>"
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"
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/ToDo list.json
Original file line number Diff line number Diff line change
@@ -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"}
59 changes: 59 additions & 0 deletions cypress/e2e/tables-import-export-scheme.cy.js
Original file line number Diff line number Diff line change
@@ -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))
})
})
})
})
2 changes: 1 addition & 1 deletion lib/Controller/ApiTablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit b473b56

Please sign in to comment.