Skip to content

Commit b1e3888

Browse files
committed
enh(Cypress): improve some selectors
Signed-off-by: Cleopatra Enjeck M. <patrathewhiz@gmail.com>
1 parent 955697a commit b1e3888

File tree

14 files changed

+72
-70
lines changed

14 files changed

+72
-70
lines changed

cypress/e2e/column-selection.cy.js

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ describe('Test column ' + columnTitle, () => {
1818
beforeEach(function() {
1919
cy.login(localUser)
2020
cy.visit('apps/tables')
21-
})
22-
23-
it('Table and column setup', () => {
2421
cy.createTable(tableTitle)
2522
})
2623

@@ -29,52 +26,46 @@ describe('Test column ' + columnTitle, () => {
2926
cy.createSelectionColumn(columnTitle, ['first option', 'second option', '👋 third option', '🤷🏻 fifths'], 'second option', true)
3027

3128
// check if default value is set on row creation
32-
cy.get('button').contains('Create row').click()
33-
cy.get('.modal-container__content h2').contains('Create row').should('be.visible')
34-
cy.get('.modal__content .title').contains(columnTitle).should('be.visible')
35-
cy.get('.modal__content .title').click()
29+
cy.get('[data-cy="createRowBtn"]').click()
30+
cy.get('[data-cy="createRowModal"]').should('be.visible')
31+
cy.get('[data-cy="createRowModal"] .title').should('be.visible')
32+
cy.get('[data-cy="createRowModal"] .title').click()
3633
cy.get('.vs__dropdown-toggle .vs__selected span[title="second option"]').should('exist')
37-
cy.get('button').contains('Save').click()
38-
cy.get('.custom-table table tr td div').contains('second option').should('be.visible')
34+
cy.get('[data-cy="createRowSaveButton"]').click()
35+
cy.get('[data-cy="ncTable"] tr td div').contains('second option').should('be.visible')
3936

4037
// create a row and select non default value
4138
cy.get('button').contains('Create row').click()
42-
cy.get('.modal__content .slot input').first().click()
39+
cy.get('[data-cy="createRowModal"] .slot input').first().click()
4340
cy.get('ul.vs__dropdown-menu li span[title="👋 third option"]').click()
44-
cy.get('button').contains('Save').click()
45-
cy.get('.custom-table table tr td div').contains('third option').should('be.visible')
41+
cy.get('[data-cy="createRowSaveButton"]').click()
42+
cy.get('[data-cy="ncTable"] tr td div').contains('third option').should('be.visible')
4643

47-
// delete first row
48-
cy.get('.NcTable tr td button').first().click()
49-
cy.get('button').contains('Delete').click()
50-
cy.get('button').contains('I really').click()
51-
cy.get('.custom-table table tr td div').contains('second').should('not.exist')
44+
cy.deleteRow(0)
45+
cy.get('[data-cy="ncTable"] tr td div').contains('second').should('not.exist')
5246

5347
// edit second row
54-
cy.get('.NcTable tr td button').first().click()
55-
cy.get('.modal__content .slot input').first().click()
48+
cy.get('[data-cy="ncTable"] [data-cy="editRowBtn"]').first().click()
49+
cy.get('[data-cy="editRowModal"] .slot input').first().click()
5650
cy.get('ul.vs__dropdown-menu li span[title="first option"]').click()
57-
cy.get('button').contains('Save').click()
58-
cy.get('.custom-table table tr td div').contains('first option').should('be.visible')
51+
cy.get('[data-cy="editRowSaveButton"]').click()
52+
cy.get('[data-cy="ncTable"] tr td div').contains('first option').should('be.visible')
5953

60-
// delete first row
61-
cy.get('.NcTable tr td button').first().click()
62-
cy.get('button').contains('Delete').click()
63-
cy.get('button').contains('I really').click()
54+
cy.deleteRow(0)
6455

65-
cy.removeColumn(columnTitle)
56+
cy.deleteTable(tableTitle)
6657
})
6758

6859
it('Test empty selection', () => {
6960
cy.loadTable(tableTitle)
7061
cy.createSelectionColumn(columnTitle, ['first option', 'second option', '👋 third option', '🤷🏻 fifths'], null, true)
7162

7263
// check if default value is set on row creation
73-
cy.get('button').contains('Create row').click()
74-
cy.get('.modal-container__content h2').contains('Create row').should('be.visible')
75-
cy.get('button').contains('Save').click()
76-
cy.get('.custom-table table tr td div').should('exist')
77-
cy.get('.NcTable tr td button').should('exist')
64+
cy.get('[data-cy="createRowBtn"]').click()
65+
cy.get('[data-cy="createRowModal"]').should('be.visible')
66+
cy.get('[data-cy="createRowSaveButton"]').click()
67+
cy.get('[data-cy="ncTable"] tr td div').should('exist')
68+
cy.get('[data-cy="ncTable"] [data-cy="editRowBtn"]').should('exist')
7869
})
7970

8071
})

cypress/e2e/context.cy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ describe('Manage a context', () => {
112112

113113
// verify that context was deleted from current user
114114
cy.get(`[data-cy="navigationContextItem"]:contains("${contextTitle}")`).find('button').click({ force: true })
115+
cy.wait(1000)
115116
cy.get('[data-cy="navigationContextDeleteBtn"]').contains('Delete application').click({ force: true })
116117
cy.get('[data-cy="deleteContextModal"]').should('be.visible')
117118
cy.get('[data-cy="deleteContextModal"] button').contains('Delete').click()
@@ -196,7 +197,7 @@ describe('Manage a context', () => {
196197
cy.get('[data-cy="ncTable"] table').contains('first row').should('exist')
197198
cy.get('[data-cy="ncTable"] table').contains('first row').parent().parent().find('[aria-label="Edit row"]').click()
198199
cy.get('[data-cy="editRowDeleteButton"]').click()
199-
cy.get('[data-cy="editRowEditConfirmButton"]').click()
200+
cy.get('[data-cy="editRowDeleteConfirmButton"]').click()
200201
cy.get('[data-cy="ncTable"] table').contains('first row').should('not.exist')
201202
})
202203
})

cypress/e2e/tables-share.cy.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
let localUser
66
let localUser2
7+
let tableTitle = 'Shared todo'
78

89
describe('Manage a table', () => {
910

@@ -16,32 +17,25 @@ describe('Manage a table', () => {
1617
})
1718
})
1819

19-
beforeEach(function() {
20-
})
2120

2221
it('Share table', () => {
2322
cy.login(localUser)
2423
cy.visit('apps/tables')
2524

26-
// create table to share
27-
cy.get('.icon-loading').should('not.exist')
2825
cy.get('[data-cy="navigationCreateTableIcon"]').click({ force: true })
2926
cy.get('.tile').contains('ToDo').click({ force: true })
30-
cy.get('.modal__content input[type="text"]').clear().type('Shared todo')
31-
cy.contains('button', 'Create table').click()
32-
33-
cy.get('.app-navigation-entry-link').contains('Shared todo').click({ force: true })
34-
cy.get('.NcTable table tr th').last().find('button').click({ force: true })
35-
cy.get('.v-popper__popper.v-popper--theme-dropdown.action-item__popper.v-popper__popper--shown').contains('Share').click({ force: true })
36-
cy.get('.sharing input').type(localUser2.userId)
37-
cy.wait(1000).get('.sharing input').type('{enter}')
38-
39-
cy.get('h3').contains('Shares').parent().find('ul').contains(localUser2.userId).should('exist')
40-
})
27+
cy.get('.modal__content input[type="text"]').clear().type(tableTitle)
28+
cy.get('[data-cy="createTableSubmitBtn"]').scrollIntoView().click()
29+
cy.loadTable(tableTitle)
30+
cy.get('[data-cy="customTableAction"] button').click()
31+
cy.get('[data-cy="dataTableShareBtn"]').click()
32+
cy.get('[data-cy="shareFormSelect"] input').type(localUser2.userId)
33+
cy.get(`.vs__dropdown-menu [user="${localUser2.userId}"]`).click()
34+
cy.wait(1000)
35+
cy.get('[data-cy="sharedWithList"]').contains(localUser2.userId).should('exist')
4136

42-
it('Check for shared table', () => {
4337
cy.login(localUser2)
4438
cy.visit('apps/tables')
45-
cy.get('.app-navigation-entry-link').contains('Shared todo').should('exist')
39+
cy.get('[data-cy="navigationTableItem"]').contains(tableTitle).should('exist')
4640
})
4741
})

cypress/e2e/tables-table.cy.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,14 @@ describe('Manage a table', () => {
7575
})
7676

7777
it('Delete', () => {
78-
cy.get('.app-navigation__list').contains('ToDo list').click({ force: true })
79-
cy.get('[data-cy="customTableAction"] button').click()
80-
cy.get('.action-button__text').contains('Edit table').click()
81-
82-
cy.get('.modal-container button').contains('Delete').click()
83-
cy.get('.modal-container button').contains('I really want to delete this table!').click()
84-
85-
cy.wait(10).get('.toastify.toast-success').should('be.visible')
86-
cy.get('.app-navigation__list').contains('to do list').should('not.exist')
78+
cy.deleteTable('ToDo list')
8779
})
8880

8981
it('Transfer', () => {
9082
cy.get('.icon-loading').should('not.exist')
9183
cy.get('[data-cy="navigationCreateTableIcon"]').click({ force: true })
9284
cy.get('.tile').contains('ToDo').click({ force: true })
93-
cy.get('.modal__content input[type="text"]').clear().type('test table')
85+
cy.get('[data-cy="createTableModal"] input[type="text"]').clear().type('test table')
9486
cy.contains('button', 'Create table').click()
9587

9688
cy.get('.app-navigation__list').contains('test table').click({ force: true })

cypress/e2e/view.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe('Interact with views', () => {
126126
// Delete rows in the view
127127
cy.get('[data-cy="customTableRow"]').contains('first row').parent().parent().find('[data-cy="editRowBtn"]').click()
128128
cy.get('[data-cy="editRowModal"] [data-cy="editRowDeleteButton"]').contains('Delete').click()
129-
cy.get('[data-cy="editRowModal"] [data-cy="editRowEditConfirmButton"]').contains('I really want to delete this row!').click()
129+
cy.get('[data-cy="editRowModal"] [data-cy="editRowDeleteConfirmButton"]').contains('I really want to delete this row!').click()
130130

131131
cy.get('[data-cy="editRowModal"]').should('not.exist')
132132
cy.get('[data-cy="customTableRow"]').contains('first row').should('not.exist')

cypress/support/commands.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ Cypress.Commands.add('createTable', (title) => {
8686
cy.contains('h1', title).should('be.visible')
8787
})
8888

89+
Cypress.Commands.add('deleteTable', (title) => {
90+
cy.get('[data-cy="navigationTableItem"]').contains(title).click({ force: true })
91+
cy.get('[data-cy="customTableAction"] button').click()
92+
cy.get('[data-cy="dataTableEditTableBtn"]').click()
93+
cy.get('[data-cy="editTableModal"] [data-cy="editTableDeleteBtn"]').click()
94+
cy.get('[data-cy="editTableModal"] [data-cy="editTableConfirmDeleteBtn"]').click()
95+
cy.wait(10).get('.toastify.toast-success').should('be.visible')
96+
cy.get('[data-cy="navigationTableItem"]').contains('to do list').should('not.exist')
97+
})
98+
99+
100+
Cypress.Commands.add('deleteRow', (rowIndex) => {
101+
cy.get('[data-cy="ncTable"] [data-cy="editRowBtn"]').eq(rowIndex).click()
102+
cy.get('[data-cy="editRowDeleteButton"]').click({ force: true })
103+
cy.get('[data-cy="editRowDeleteConfirmButton"]').click({ force: true })
104+
})
105+
89106
Cypress.Commands.add('createView', (title) => {
90107
cy.get('[data-cy="customTableAction"] button').click()
91108
cy.get('[data-cy="dataTableCreateViewBtn"]').contains('Create view').click({ force: true })
@@ -123,6 +140,7 @@ Cypress.Commands.add('createContext', (title) => {
123140

124141
Cypress.Commands.add('openContextEditModal', (title) => {
125142
cy.get(`[data-cy="navigationContextItem"]:contains("${title}")`).find('button').click({ force: true })
143+
cy.wait(1000)
126144
cy.get('[data-cy="navigationContextEditBtn"]').contains('Edit application').click({ force: true })
127145
cy.get('[data-cy="editContextModal"]').should('be.visible')
128146
})
@@ -142,7 +160,7 @@ Cypress.Commands.add('sortTableColumn', (columnTitle, mode = 'ASC') => {
142160
})
143161

144162
Cypress.Commands.add('loadTable', (name) => {
145-
cy.get('[data-cy="navigationTableItem"] a[title="' + name + '"]').click({ force: true })
163+
cy.get('[data-cy="navigationTableItem"] a[title="' + name + '"]').last().click({ force: true })
146164
})
147165

148166
Cypress.Commands.add('getTutorialTableName', () => {

src/modules/main/sections/DataTable.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<IconTool :size="20" />
1414
</template>
1515
<NcActionCaption v-if="canManageElement(table)" :name="t('tables', 'Manage table')" />
16-
<NcActionButton v-if="canManageElement(table) "
16+
<NcActionButton v-if="canManageElement(table)"
17+
data-cy="dataTableEditTableBtn"
1718
:close-after-click="true"
1819
@click="emit('tables:table:edit', table.id)">
1920
<template #icon>
@@ -122,10 +123,11 @@
122123
</NcActionButton>
123124
<NcActionButton v-if="canReadData(table)" :close-after-click="true"
124125
icon="icon-download"
125-
data-cy="dataTableExportBtn" @click="$emit('download-csv')">
126+
data-cy="dataTableDownloadCSVBtn" @click="$emit('download-csv')">
126127
{{ t('tables', 'Export as CSV') }}
127128
</NcActionButton>
128129
<NcActionButton v-if="canShareElement(table)"
130+
data-cy="dataTableShareBtn"
129131
:close-after-click="true"
130132
icon="icon-share"
131133
@click="$emit('toggle-share')">

src/modules/modals/CreateTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
</div>
7575
<div class="row space-R">
7676
<div class="fix-col-4 end">
77-
<NcButton type="primary" :aria-label="t('tables', 'Create table')" @click="submit">
77+
<NcButton type="primary" :aria-label="t('tables', 'Create table')" data-cy="createTableSubmitBtn" @click="submit">
7878
{{ t('tables', 'Create table') }}
7979
</NcButton>
8080
</div>

src/modules/modals/EditRow.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
{{ t('tables', 'Delete') }}
2525
</NcButton>
2626
<NcButton v-if="prepareDeleteRow"
27-
data-cy="editRowEditConfirmButton"
27+
data-cy="editRowDeleteConfirmButton"
2828
:wide="true"
2929
:aria-label="t('tables', 'I really want to delete this row!')"
3030
type="error"

src/modules/modals/EditTable.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@
4848
</div>
4949
<div class="row">
5050
<div class="fix-col-4 space-T justify-between">
51-
<NcButton v-if="!prepareDeleteTable" type="error" @click="prepareDeleteTable = true">
51+
<NcButton v-if="!prepareDeleteTable" type="error" data-cy="editTableDeleteBtn" @click="prepareDeleteTable = true">
5252
{{ t('tables', 'Delete') }}
5353
</NcButton>
5454
<NcButton v-if="prepareDeleteTable"
5555
:wide="true"
5656
type="error"
57+
data-cy="editTableConfirmDeleteBtn"
5758
@click="actionDeleteTable">
5859
{{ t('tables', 'I really want to delete this table!') }}
5960
</NcButton>

0 commit comments

Comments
 (0)