Skip to content

Commit

Permalink
fix: improve Cypress selectors, wait for requests
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
  • Loading branch information
enjeck committed Jul 23, 2024
1 parent 02b5c74 commit 147500c
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 16 deletions.
201 changes: 201 additions & 0 deletions cypress/e2e/context.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
let localUser
let nonLocalUser
let tableTitlePrefix = 'test table'
let tableTitle = tableTitlePrefix
let viewTitle = 'test view'
let contextTitlePrefix = 'test application'
let contextTitle = contextTitlePrefix
let testNumber = 0

describe('Manage a context', () => {
before(function () {
cy.createRandomUser().then(user => {
localUser = user
})
cy.createRandomUser().then(user => {
nonLocalUser = user
})
})

beforeEach(function () {
testNumber += 1
contextTitle = contextTitlePrefix + ' ' + testNumber
tableTitle = tableTitlePrefix + ' ' + testNumber
cy.login(localUser)
cy.visit('apps/tables')
cy.createContext(contextTitle)
cy.loadContext(contextTitle)
})

it('Update and add resources', () => {
cy.createTable(tableTitle)
cy.loadTable(tableTitle)
cy.createTextLineColumn('title', null, null, true)
cy.get('button').contains('Create row').click()
cy.fillInValueTextLine('title', 'first row')
cy.get('[data-cy="createRowSaveButton"]').click()
cy.createView(viewTitle)

cy.openContextEditModal(contextTitle)
cy.get('[data-cy="editContextTitle"]').clear().type(`updated ${contextTitle}`)
cy.get('[data-cy="contextResourceForm"] input').clear().type(tableTitle)
cy.get('ul.vs__dropdown-menu li div').contains(tableTitle).click()
cy.get('[data-cy="contextResourceList"]').should('contain.text', tableTitle)
cy.get('[data-cy="contextResourcePerms"]').should('contain.text', tableTitle)
cy.get('[data-cy="contextResourceForm"] input').clear().type(viewTitle)
cy.get('ul.vs__dropdown-menu li div').contains(viewTitle).click()
cy.get('[data-cy="contextResourceList"]').should('contain.text', viewTitle)
cy.get('[data-cy="contextResourcePerms"]').should('contain.text', viewTitle)
cy.get('[data-cy="editContextSubmitBtn"]').click()
cy.get('[data-cy="navigationContextItem"]').contains(`updated ${contextTitle}`).should('exist')
cy.get('[data-cy="navigationContextItem"]').contains(`updated ${contextTitle}`).click({ force: true })
cy.contains('h1', `updated ${contextTitle}`).should('exist')
cy.contains('h1', tableTitle).should('exist')
cy.contains('h1', viewTitle).should('exist')

})

it('Share context with resources', () => {
cy.createTable(tableTitle)
cy.openContextEditModal(contextTitle)
cy.get('[data-cy="contextResourceForm"] input').clear().type(tableTitle)
cy.get('ul.vs__dropdown-menu li div').contains(tableTitle).click()
cy.get('[data-cy="contextResourceShare"] input').clear().type(nonLocalUser.userId)
cy.get(`.vs__dropdown-menu [id="${nonLocalUser.userId}"]`).click()
cy.get('[data-cy="contextResourceShare"] span').contains(nonLocalUser.userId).should('exist')
cy.get('[data-cy="editContextSubmitBtn"]').click()
cy.loadContext(contextTitle)
cy.contains('h1', contextTitle).should('exist')
cy.contains('h1', tableTitle).should('exist')

// verify context was shared properly
cy.login(nonLocalUser)
cy.visit('apps/tables')
cy.loadContext(contextTitle)
cy.contains('header .app-menu-entry', contextTitle).should('exist')
cy.contains('h1', contextTitle).should('exist')
cy.contains('h1', tableTitle).should('exist')

cy.login(localUser)
cy.visit('apps/tables')
cy.loadContext(contextTitle)
cy.contains('h1', contextTitle).should('exist')
})

it('Transfer context', () => {
cy.createTable(tableTitle)
cy.openContextEditModal(contextTitle)
cy.get('[data-cy="transferContextSubmitBtn"]').click()
cy.get('[data-cy="transferContextModal"]').should('be.visible')
cy.get('[data-cy="transferContextModal"] input').clear().type(nonLocalUser.userId)
cy.get(`.vs__dropdown-menu [id="${nonLocalUser.userId}"]`).click()
cy.get('[data-cy="transferContextButton"]').click()

// verify that context was properly transferred
cy.login(nonLocalUser)
cy.visit('apps/tables')
cy.loadContext(contextTitle)
cy.contains('header .app-menu-entry', contextTitle).should('exist')
cy.contains('h1', contextTitle).should('exist')
})

it('Delete context with shares', () => {
cy.loadContext(contextTitle)
cy.openContextEditModal(contextTitle)
cy.get('[data-cy="contextResourceShare"] input').clear().type(nonLocalUser.userId)
cy.get(`.vs__dropdown-menu [id="${nonLocalUser.userId}"]`).click()
cy.get('[data-cy="contextResourceShare"] span').contains(nonLocalUser.userId).should('exist')
cy.get('[data-cy="editContextSubmitBtn"]').click()
cy.wait(1000)

// verify that context was deleted from current user
cy.get(`[data-cy="navigationContextItem"]:contains("${contextTitle}")`).find('button').click({ force: true })
cy.get('[data-cy="navigationContextDeleteBtn"]').contains('Delete application').click({ force: true })
cy.get('[data-cy="deleteContextModal"]').should('be.visible')
cy.get('[data-cy="deleteContextModal"] button').contains('Delete').click()
cy.get('li').contains(contextTitle).should('not.exist')
cy.contains('h1', contextTitle).should('not.exist')

// verify that context was deleted from shared user
cy.login(nonLocalUser)
cy.visit('apps/tables')
cy.get('li').contains(contextTitle).should('not.exist')
})

it('Remove context resource', () => {
cy.createTable(tableTitle)
cy.loadContext(contextTitle)
cy.openContextEditModal(contextTitle)
cy.get('[data-cy="contextResourceForm"] input').clear().type(tableTitle)
cy.get('ul.vs__dropdown-menu li div').contains(tableTitle).click()
cy.get('[data-cy="contextResourceList"]').should('contain.text', tableTitle)
cy.get('[data-cy="contextResourcePerms"]').should('contain.text', tableTitle)
cy.get('[data-cy="editContextSubmitBtn"]').click()

cy.contains('h1', contextTitle).should('exist')
cy.contains('h1', tableTitle).should('exist')
cy.openContextEditModal(contextTitle)
cy.get('[data-cy="contextResourceList"] button').contains('Delete').click({ force: true })
cy.get('[data-cy="contextResourceList"]').contains(tableTitle).should('not.exist')
cy.get('[data-cy="editContextSubmitBtn"]').click()
cy.contains('h1', contextTitle).should('exist')
cy.contains('h1', tableTitle).should('not.exist')
})

it('Modify resource rows and columns from context', () => {
cy.createTable(tableTitle)
cy.loadContext(contextTitle)
cy.contains('h1', contextTitle).should('exist')
cy.openContextEditModal(contextTitle)
cy.get('[data-cy="contextResourceForm"] input').clear().type(tableTitle)
cy.get('ul.vs__dropdown-menu li div').contains(tableTitle).click()
cy.get('[data-cy="contextResourceList"]').should('contain.text', tableTitle)
cy.get('[data-cy="contextResourcePerms"]').should('contain.text', tableTitle)
cy.get('[data-cy="editContextSubmitBtn"]').click()
cy.createTextLineColumn('title', null, null, true)
cy.get('button').contains('Create row').click()
cy.fillInValueTextLine('title', 'first row')
cy.get('[data-cy="createRowSaveButton"]').click()
cy.get('[data-cy="ncTable"] table').contains('first row').should('exist')
})

it('Modify context resources and their permissions', () => {
cy.createTable(tableTitle)
cy.loadTable(tableTitle)
cy.createTextLineColumn('title', null, null, true)
cy.loadContext(contextTitle)
cy.contains('h1', contextTitle).should('exist')
cy.openContextEditModal(contextTitle)
cy.get('[data-cy="contextResourceForm"] input').clear().type(tableTitle)
cy.get('ul.vs__dropdown-menu li div').contains(tableTitle).click()
cy.get('[data-cy="contextResourceList"]').should('contain.text', tableTitle)
cy.get('[data-cy="contextResourcePerms"]').should('contain.text', tableTitle)
// give delete permission for resource
cy.get('[data-cy="resourceSharePermsActions"] button').click()
cy.get('li .action-checkbox').contains('Delete resource').click()
cy.get('li [aria-checked="true"]').contains('Delete resource').should('exist')

cy.get('[data-cy="contextResourceShare"] input').clear().type(nonLocalUser.userId)
cy.get(`.vs__dropdown-menu [id="${nonLocalUser.userId}"]`).click()
cy.get('[data-cy="contextResourceShare"] span').contains(nonLocalUser.userId).should('exist')
cy.get('[data-cy="editContextSubmitBtn"]').click()
cy.contains('h1', contextTitle).should('exist')
cy.contains('h1', tableTitle).should('exist')

// verify that shared user can modify and delete data in the resource
cy.login(nonLocalUser)
cy.visit('apps/tables')
cy.loadContext(contextTitle)
cy.contains('header .app-menu-entry', contextTitle).should('exist')
cy.contains('h1', contextTitle).should('exist')
cy.contains('h1', tableTitle).should('exist')
cy.get('button').contains('Create row').click()
cy.fillInValueTextLine('title', 'first row')
cy.get('[data-cy="createRowSaveButton"]').click()
cy.get('[data-cy="ncTable"] table').contains('first row').should('exist')
cy.get('[data-cy="ncTable"] table').contains('first row').parent().parent().find('[aria-label="Edit row"]').click()
cy.get('[data-cy="editRowDeleteButton"]').click()
cy.get('[data-cy="editRowEditConfirmButton"]').click()
cy.get('[data-cy="ncTable"] table').contains('first row').should('not.exist')
})
})
6 changes: 4 additions & 2 deletions cypress/e2e/tables-import.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ describe('Import csv', () => {
cy.get('.file-picker__files').contains('test-import').click()
cy.get('.file-picker button span').contains('Choose test-import.csv').click()
cy.get('.modal__content .import-filename', { timeout: 5000 }).should('be.visible')
cy.intercept({ method: 'POST', url: '**/apps/tables/import/table/*'}).as('importUploadReq')
cy.get('.modal__content button').contains('Import').click()

cy.wait('@importUploadReq')
cy.get('[data-cy="importResultColumnsFound"]').should('contain.text', '4')
cy.get('[data-cy="importResultColumnsMatch"]').should('contain.text', '4')
cy.get('[data-cy="importResultColumnsCreated"]').should('contain.text', '0')
Expand All @@ -37,8 +38,9 @@ describe('Import csv', () => {
cy.clickOnTableThreeDotMenu('Import')
cy.get('.modal__content button').contains('Upload from device').click()
cy.get('input[type="file"]').selectFile('cypress/fixtures/test-import.csv', { force: true })
cy.intercept({ method: 'POST', url: '**/apps/tables/importupload/table/*'}).as('importUploadReq')
cy.get('.modal__content button').contains('Import').click()

cy.wait('@importUploadReq')
cy.get('[data-cy="importResultColumnsFound"]', { timeout: 20000 }).should('contain.text', '4')
cy.get('[data-cy="importResultColumnsMatch"]').should('contain.text', '4')
cy.get('[data-cy="importResultColumnsCreated"]').should('contain.text', '0')
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/tables-rows.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ describe('Rows for a table', () => {
})

it('Check mandatory fields error', () => {
cy.contains('.app-menu-entry--label', 'Tables').click()
cy.contains('button', 'Create new table').click()
cy.get('.icon-loading').should('not.exist')
cy.get('[data-cy="navigationCreateTableIcon"]').click({ force: true })
cy.get('.tile').contains('ToDo').click({ force: true })
cy.get('.modal__content').should('be.visible')
cy.get('.modal__content input[type="text"]').clear().type('to do list')
cy.get('[data-cy="createTableModal"]').should('be.visible')
cy.get('[data-cy="createTableModal"] input[type="text"]').clear().type('to do list')
cy.contains('button', 'Create table').click()

cy.get('.app-navigation-entry-link').contains('to do list').click({ force: true })
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/tables-share.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('Manage a table', () => {
cy.visit('apps/tables')

// create table to share
cy.contains('.app-menu-entry--label', 'Tables').click()
cy.contains('button', 'Create new table').click()
cy.get('.icon-loading').should('not.exist')
cy.get('[data-cy="navigationCreateTableIcon"]').click({ force: true })
cy.get('.tile').contains('ToDo').click({ force: true })
cy.get('.modal__content input[type="text"]').clear().type('Shared todo')
cy.contains('button', 'Create table').click()
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/tables-table.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe('Manage a table', () => {
})

it('Create', () => {
cy.contains('.app-menu-entry--label', 'Tables').click()
cy.contains('button', 'Create new table').click()
cy.get('.icon-loading').should('not.exist')
cy.get('[data-cy="navigationCreateTableIcon"]').click({ force: true })
cy.get('.tile').contains('ToDo').click({ force: true })
cy.get('.modal__content').should('be.visible')
cy.get('.modal__content input[type="text"]').clear().type('to do list')
Expand Down Expand Up @@ -61,8 +61,8 @@ describe('Manage a table', () => {
})

it('Transfer', () => {
cy.contains('.app-menu-entry--label', 'Tables').click()
cy.contains('button', 'Create new table').click()
cy.get('.icon-loading').should('not.exist')
cy.get('[data-cy="navigationCreateTableIcon"]').click({ force: true })
cy.get('.tile').contains('ToDo').click({ force: true })
cy.get('.modal__content').should('be.visible')
cy.get('.modal__content input[type="text"]').clear().type('test table')
Expand Down
6 changes: 3 additions & 3 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ Cypress.env('baseUrl', url)
addCommands()

Cypress.Commands.add('createTable', (title) => {
cy.get('.icon-loading').should('not.exist')
cy.get('[data-cy="navigationCreateTableIcon"]').click({ force: true })
cy.wait(1000)
cy.get('[data-cy="createTableModal"]').should('be.visible')
cy.get('.tile').contains('Custom table').click({ force: true })
cy.get('.modal__content input[type="text"]').clear().type(title)
cy.get('[data-cy="createTableModal"] input[type="text"]').clear().type(title)
cy.contains('button', 'Create table').click()

cy.contains('h1', title).should('be.visible')
})

Expand Down
2 changes: 1 addition & 1 deletion src/modules/modals/CreateTable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<NcModal v-if="showModal" size="normal"
@close="actionCancel">
data-cy="createTableModal" @close="actionCancel">
<div class="modal__content">
<div class="row">
<div class="col-4">
Expand Down

0 comments on commit 147500c

Please sign in to comment.