Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: add context e2e tests #1149

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 202 additions & 0 deletions cypress/e2e/context.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
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 .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.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 .header-left .app-menu li.app-menu-entry__active', 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.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.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 .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.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')
})
})
21 changes: 21 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ Cypress.Commands.add('createView', (title) => {
cy.contains('.app-navigation-entry-link span', title).should('exist')
})

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="createContextSubmitBtn"]').click()

// verify context was created properly
cy.get('[data-cy="navigationContextItem"]').contains(title).should('exist')
cy.contains('h1', title).should('exist')
})

Cypress.Commands.add('loadContext', (title) => {
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) => {
cy.get('[data-cy="customTableAction"] button').click()
cy.get('[data-cy="dataTableExportBtn"]').contains(optionName).click({ force: true })
Expand Down
8 changes: 4 additions & 4 deletions src/modules/modals/CreateContext.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<NcModal v-if="showModal" size="normal" @close="actionCancel">
<NcModal v-if="showModal" size="normal" data-cy="createContextModal" @close="actionCancel">
<div class="modal__content">
<div class="row">
<div class="col-4">
Expand All @@ -22,15 +22,15 @@
</template>
</NcButton>
</NcIconPicker>
<input ref="titleInput" v-model="title" :class="{ missing: errorTitle }" type="text"
<input ref="titleInput" v-model="title" :class="{ missing: errorTitle }" type="text" data-cy="createContextTitle"
:placeholder="t('tables', 'Title of the new application')" @input="titleChangedManually">
</div>
</div>
<div class="col-4 row space-T">
<div class="col-4">
{{ t('tables', 'Description') }}
</div>
<input v-model="description" type="text"
<input v-model="description" type="text" data-cy="createContextDes"
:placeholder="t('tables', 'Description of the new application')">
</div>
<div class="col-4 row space-T">
Expand All @@ -41,7 +41,7 @@
</div>
<div class="row space-R row space-T">
<div class="fix-col-4 end">
<NcButton type="primary" :aria-label="t('tables', 'Create application')" @click="submit">
<NcButton type="primary" :aria-label="t('tables', 'Create application')" data-cy="createContextSubmitBtn" @click="submit">
{{ t('tables', 'Create application') }}
</NcButton>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/modules/modals/DeleteContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
:confirm-title="t('tables', 'Delete')"
confirm-class="error"
:show-modal="showModal"
@confirm="deleteContext"
@cancel="$emit('cancel')" />
data-cy="deleteContextModal"
@confirm="deleteContext" @cancel="$emit('cancel')" />
</div>
</template>

Expand Down
10 changes: 5 additions & 5 deletions src/modules/modals/EditContext.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<NcModal v-if="showModal" size="normal" @close="actionCancel">
<NcModal v-if="showModal" size="normal" data-cy="editContextModal" @close="actionCancel">
<div class="modal__content" data-cy="editContextModal">
<div class="row">
<div class="col-4">
Expand All @@ -19,15 +19,15 @@
</template>
</NcButton>
</NcIconPicker>
<input v-model="title" :class="{ missing: errorTitle }" type="text"
<input v-model="title" :class="{ missing: errorTitle }" type="text" data-cy="editContextTitle"
:placeholder="t('tables', 'Title of the application')">
</div>
</div>
<div class="col-4 row space-T">
<div class="col-4">
{{ t('tables', 'Description') }}
</div>
<input v-model="description" type="text" :placeholder="t('tables', 'Description of the application')">
<input v-model="description" type="text" data-cy="editContextDes" :placeholder="t('tables', 'Description of the application')">
</div>
<div class="col-4 row space-T">
<div class="col-4">
Expand All @@ -45,10 +45,10 @@
{{ t('tables', 'I really want to delete this application!') }}
</NcButton>
<div class="right-additional-button">
<NcButton v-if="ownsContext(localContext)" @click="actionTransfer">
<NcButton v-if="ownsContext(localContext)" data-cy="transferContextSubmitBtn" @click="actionTransfer">
{{ t('tables', 'Transfer application') }}
</NcButton>
<NcButton type="primary" @click="submit">
<NcButton type="primary" data-cy="editContextSubmitBtn" @click="submit">
{{ t('tables', 'Save') }}
</NcButton>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/modules/modals/TransferContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</div>
</div>
<div class="row">
<h3>{{ t('tables', 'Transfer this application to another user') }}</h3>
<h3>{{ t('tables', 'Transfer the application "{context}" to another user', { context: context.name }) }}</h3>
<NcUserPicker :select-users="true" :select-groups="false" :selected-user-id.sync="newOwnerId" />
</div>
<div class="row">
<div class="fix-col-4 space-T end">
<NcButton type="warning" :disabled="newOwnerId === ''" data-cy="transferTableButton" @click="transferContext">
<NcButton type="warning" :disabled="newOwnerId === ''" data-cy="transferContextButton" @click="transferContext">
{{ t('tables', 'Transfer') }}
</NcButton>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/modules/navigation/partials/NavigationContextItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</template>
</template>
<template #actions>
<NcActionButton v-if="ownsContext(context)" :close-after-click="true" @click="editContext">
<NcActionButton v-if="ownsContext(context)" :close-after-click="true" data-cy="navigationContextEditBtn" @click="editContext">
<template #icon>
<PlaylistEdit :size="20" />
</template>
Expand All @@ -23,7 +23,7 @@
</template>
{{ t('tables', 'Transfer application') }}
</NcActionButton>
<NcActionButton v-if="ownsContext(context)" :close-after-click="true" @click="deleteContext">
<NcActionButton v-if="ownsContext(context)" :close-after-click="true" data-cy="navigationContextDeleteBtn" @click="deleteContext">
<template #icon>
<Delete :size="20" />
</template>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/navigation/sections/Navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<ul v-if="!contextsLoading">
<NcAppNavigationCaption :name="t('tables', 'Applications')">
<template #actions>
<NcActionButton :aria-label="t('tables', 'Create application')" icon="icon-add"
<NcActionButton :aria-label="t('tables', 'Create application')" icon="icon-add" data-cy="createContextIcon"
@click.prevent="createContext" />
</template>
</NcAppNavigationCaption>
Expand Down
8 changes: 4 additions & 4 deletions src/shared/components/ncContextResource/NcContextResource.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div>
<div>
<ResourceForm :resources="localResources" @add="addResource" />
<ResourceList :resources="localResources" @remove="removeResource" />
<ResourceSharees :select-users="true" :select-groups="false" :receivers="localReceivers" @update="updateReceivers" />
<ResourceSharePermissions :resources="localResources" @update="updateResourcePermissions" />
<ResourceForm :resources="localResources" data-cy="contextResourceForm" @add="addResource" />
<ResourceList :resources="localResources" data-cy="contextResourceList" @remove="removeResource" />
<ResourceSharees :select-users="true" :select-groups="false" :receivers="localReceivers" data-cy="contextResourceShare" @update="updateReceivers" />
<ResourceSharePermissions :resources="localResources" data-cy="contextResourcePerms" @update="updateResourcePermissions" />
</div>
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
</div>
<div class="fix-col-2" style="justify-content: end;">
<NcActions :force-menu="true">
<NcActions :force-menu="true" data-cy="resourceSharePermsActions">
<NcActionCaption :name="t('tables', 'Permissions')" />
<NcActionCheckbox :checked.sync="resource.permissionRead" :disabled="true"
@check="updatePermission(resource, 'permissionRead', true)"
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
Loading