Skip to content

Commit

Permalink
enh: add more context e2e tests
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 Jun 18, 2024
1 parent 0d3fa13 commit f76bfb2
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 55 deletions.
111 changes: 60 additions & 51 deletions cypress/e2e/context.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
let localUser
let nonLocalUser
let tableTitle = 'test table'
let tableTitlePrefix = 'test table'
let tableTitle = tableTitlePrefix
let viewTitle = 'test view'
let contextTitle = 'test application'
let contextTitlePrefix = 'test application'
let contextTitle = contextTitlePrefix
let testNumber = 0

describe('Manage a context', () => {
before(function () {
Expand All @@ -15,22 +18,15 @@ describe('Manage a context', () => {
})

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

afterEach(function () {
// Delete context
cy.get('[data-cy="navigationContextItem"] button').click({ force: true })
cy.get('[data-cy="navigationContextDeleteBtn"]').contains('Delete application').click({ force: true })
cy.wait(1000)
cy.get('[data-cy="deleteContextModal"]').should('be.visible')
cy.get('[data-cy="deleteContextModal"] button').contains('Delete').click()
cy.get('[data-cy="navigationContextItem"]').should('not.exist')
})

it('Update and add resources', () => {
cy.createTable(tableTitle)
cy.loadTable(tableTitle)
Expand All @@ -40,10 +36,7 @@ describe('Manage a context', () => {
cy.get('[data-cy="createRowSaveButton"]').click()
cy.createView(viewTitle)


cy.get('[data-cy="navigationContextItem"] button').last().click({ force: true })
cy.get('[data-cy="navigationContextEditBtn"]').contains('Edit application').click({ force: true })
cy.get('[data-cy="editContextModal"]').should('be.visible')
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()
Expand All @@ -59,21 +52,21 @@ describe('Manage a context', () => {
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.get('[data-cy="navigationContextItem"] button').last().click({ force: true })
cy.get('[data-cy="navigationContextEditBtn"]').contains('Edit application').click({ force: true })
cy.get('[data-cy="editContextModal"]').should('be.visible')

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 [user="${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)
Expand All @@ -91,15 +84,14 @@ describe('Manage a context', () => {

it('Transfer context', () => {
cy.createTable(tableTitle)
cy.get('[data-cy="navigationContextItem"] button').last().click({ force: true })
cy.get('[data-cy="navigationContextEditBtn"]').contains('Edit application').click({ force: true })
cy.get('[data-cy="editContextModal"]').should('be.visible')
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 [user="${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)
Expand All @@ -109,85 +101,102 @@ describe('Manage a context', () => {

it('Delete context with shares', () => {
cy.loadContext(contextTitle)
cy.get('[data-cy="navigationContextItem"] button').last().click({ force: true })
cy.get('[data-cy="navigationContextEditBtn"]').contains('Edit application').click({ force: true })
cy.get('[data-cy="editContextModal"]').should('be.visible')
cy.get('[data-cy="editContextTitle"]').clear().type(`to delete ${contextTitle}`)
cy.openContextEditModal(contextTitle)
cy.get('[data-cy="contextResourceShare"] input').clear().type(nonLocalUser.userId)
cy.get(`.vs__dropdown-menu [user="${nonLocalUser.userId}"]`).click()
cy.get('[data-cy="contextResourceShare"] span').contains(nonLocalUser.userId).should('exist')
cy.get('[data-cy="editContextSubmitBtn"]').click()
cy.get('[data-cy="editContextSubmitBtn"]').click()
cy.wait(1000)

cy.get('[data-cy="navigationContextItem"] button').last().click({ force: true })
// 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('[data-cy="navigationContextItem"]').contains(`to delete ${contextTitle}`).should('not.exist')
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('[data-cy="navigationContextItem"]').contains(`to delete ${contextTitle}`).should('not.exist')
cy.get('li').contains(contextTitle).should('not.exist')
})

it('Remove context resources', () => {
it('Remove context resource', () => {
cy.createTable(tableTitle)
cy.loadContext(contextTitle)
cy.get('[data-cy="navigationContextItem"] button').last().click({ force: true })
cy.get('[data-cy="navigationContextEditBtn"]').contains('Edit application').click({ force: true })
cy.get('[data-cy="editContextModal"]').should('be.visible')
cy.contains('header .header-left .app-menu li.app-menu-entry__active', 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.get('[data-cy="navigationContextItem"] button').last().click({ force: true })
cy.get('[data-cy="navigationContextEditBtn"]').contains('Edit application').click({ force: true })
cy.get('[data-cy="editContextModal"]').should('be.visible')
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.loadContext(contextTitle)
cy.contains('h1', contextTitle).should('exist')
cy.contains('h1', tableTitle).should('not.exist')
})

cy.login(nonLocalUser)
cy.visit('apps/tables')
cy.get('[data-cy="navigationContextItem"]').contains(`to delete ${contextTitle}`).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.get('[data-cy="navigationContextItem"] button').last().click({ force: true })
cy.get('[data-cy="navigationContextEditBtn"]').contains('Edit application').click({ force: true })
cy.get('[data-cy="editContextModal"]').should('be.visible')
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 [user="${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') // doing this to give Cypress time to load
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.contains('header .header-left .app-menu li.app-menu-entry', contextTitle).should('exist')
cy.loadContext(contextTitle)
cy.contains('header .header-left .app-menu li.app-menu-entry__active', contextTitle).should('exist')
cy.contains('h1', contextTitle).should('exist')
cy.contains('h1', tableTitle).should('exist')
cy.createTextLineColumn('text line', 'test', '12', true)
cy.get('button').contains('Create row').click()
cy.fillInValueTextLine('title', 'first row')
cy.get('[data-cy="createRowSaveButton]').click()

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')
})
})
12 changes: 9 additions & 3 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Cypress.Commands.add('createView', (title) => {

Cypress.Commands.add('createContext', (title) => {
cy.get('ul:nth-of-type(2) [data-cy="createContextIcon"]').click({ force: true })
cy.get('[data-cy="createContextModal"]').should('be.visible')
cy.get('[data-cy="createContextTitle"]').clear().type(title)
cy.get('[data-cy="createContextModal"]').should('be.visible')
cy.get('[data-cy="createContextTitle"]').clear().type(title)
cy.get('[data-cy="createContextSubmitBtn"]').click()

// verify context was created properly
Expand All @@ -68,7 +68,13 @@ Cypress.Commands.add('createContext', (title) => {
})

Cypress.Commands.add('loadContext', (title) => {
cy.get('[data-cy="navigationContextItem"]').contains(title).last().click({ force: true })
cy.get('[data-cy="navigationContextItem"]').contains(title).click({ force: true })
})

Cypress.Commands.add('openContextEditModal', (title) => {
cy.get(`[data-cy="navigationContextItem"]:contains("${title}")`).find('button').click({ force: true })
cy.get('[data-cy="navigationContextEditBtn"]').contains('Edit application').click({ force: true })
cy.get('[data-cy="editContextModal"]').should('be.visible')
})

Cypress.Commands.add('clickOnTableThreeDotMenu', (optionName) => {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/ncTable/NcTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ deselect-all-rows -> unselect all rows, e.g. after deleting selected rows
-->

<template>
<div class="NcTable">
<div class="NcTable" data-cy="ncTable">
<div class="options row" style="padding-right: calc(var(--default-grid-baseline) * 2);">
<Options :rows="rows" :columns="parsedColumns" :element-id="elementId" :is-view="isView"
:selected-rows="localSelectedRows" :show-options="parsedColumns.length !== 0"
Expand Down

0 comments on commit f76bfb2

Please sign in to comment.