Skip to content

Commit d3fce3e

Browse files
test: Make e2e tests more robust
AI-assistant: GitHub Copilot v1.0.24 (GPT-5.4 (medium)) Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent fd235a6 commit d3fce3e

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

playwright/e2e/context.spec.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
loadContext,
1616
loadTable,
1717
openContextEditModal,
18+
openCreateRowModal,
1819
} from '../support/commands'
1920
import { login } from '../support/login'
2021

@@ -240,11 +241,16 @@ test.describe('Manage a context', () => {
240241
await page.locator('[data-cy="editContextSubmitBtn"]').click()
241242

242243
await createTextLineColumn(page, 'title', '', '', true)
243-
await page.locator('button').filter({ hasText: 'Create row' }).click()
244+
await openCreateRowModal(page)
244245
await fillInValueTextLine(page, 'title', 'first row')
246+
const createRowResponse = page.waitForResponse(r => r.url().includes('/rows') && r.request().method() === 'POST')
245247
await page.locator('[data-cy="createRowSaveButton"]').click()
248+
await createRowResponse
249+
await expect(page.locator('[data-cy="createRowModal"]')).toBeHidden()
246250

247-
await expect(page.locator('[data-cy="ncTable"] table').filter({ hasText: 'first row' })).toBeVisible()
251+
await expect(
252+
page.locator('[data-cy="customTableRow"]').filter({ hasText: 'first row' }).first(),
253+
).toBeVisible()
248254
})
249255

250256
test('Modify context resources and their permissions', async ({ userPage: { page }, request }) => {
@@ -294,16 +300,20 @@ test.describe('Manage a context', () => {
294300
await expect(page.locator('h1', { hasText: contextTitle })).toBeVisible()
295301
await expect(page.locator('h1', { hasText: tableTitle })).toBeVisible()
296302

297-
await page.locator('button').filter({ hasText: 'Create row' }).click()
303+
await openCreateRowModal(page)
298304
await fillInValueTextLine(page, 'title', 'first row')
305+
const createRowResponse = page.waitForResponse(r => r.url().includes('/rows') && r.request().method() === 'POST')
299306
await page.locator('[data-cy="createRowSaveButton"]').click()
307+
await createRowResponse
308+
await expect(page.locator('[data-cy="createRowModal"]')).toBeHidden()
300309

301-
await expect(page.locator('[data-cy="ncTable"] table').filter({ hasText: 'first row' })).toBeVisible()
310+
const createdRow = page.locator('[data-cy="customTableRow"]').filter({ hasText: 'first row' }).first()
311+
await expect(createdRow).toBeVisible()
302312

303-
await page.locator('[data-cy="ncTable"] [data-cy="customTableRow"]').filter({ hasText: 'first row' }).locator('[data-cy="editRowBtn"]').click()
313+
await createdRow.locator('[data-cy="editRowBtn"]').click()
304314
await page.locator('[data-cy="editRowDeleteButton"]').click()
305315
await page.locator('[data-cy="editRowDeleteConfirmButton"]').click()
306316

307-
await expect(page.locator('[data-cy="ncTable"] table', { hasText: 'first row' })).toBeHidden()
317+
await expect(createdRow).toBeHidden()
308318
})
309319
})

playwright/e2e/view-mandatory-state.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { test, expect } from '../support/fixtures'
88
import type { BrowserContext, Page } from '@playwright/test'
99
import { createRandomUser } from '../support/api'
1010
import { login } from '../support/login'
11-
import { createTable, createTextLineColumn, fillInValueTextLine, loadTable } from '../support/commands'
11+
import { createTable, createTextLineColumn, fillInValueTextLine, loadTable, openCreateRowModal } from '../support/commands'
1212

1313
const tableTitle = 'Mandatory test table'
1414

@@ -18,7 +18,7 @@ async function setupMandatoryTable(page: Page) {
1818
await createTextLineColumn(page, 'description', '', '', false)
1919

2020
// create one row
21-
await page.locator('[data-cy="createRowBtn"]').click()
21+
await openCreateRowModal(page)
2222
await fillInValueTextLine(page, 'title', 'first row')
2323
await fillInValueTextLine(page, 'description', 'desc 1')
2424
await page.locator('[data-cy="createRowSaveButton"]').click()
@@ -135,11 +135,12 @@ test.describe('Mandatory Column Functionality', () => {
135135
await expect(page.locator('[data-cy="editRowModal"]')).toBeVisible()
136136

137137
// should show error when mandatory field is empty
138-
const input = page.locator('[data-cy="editRowModal"] input').first()
138+
const input = page.locator('[data-cy="editRowModal"] [data-cy="title"] input').first()
139139
await input.fill('')
140-
await input.blur()
141140

142-
await expect(page.locator('[data-cy="editRowModal"]').locator('.notecard--error, .note-card--error, .error, [type="error"]').first()).toBeVisible({ timeout: 15000 })
141+
await expect(
142+
page.locator('[data-cy="editRowModal"] [data-cy="rowMandatoryError"]'),
143+
).toBeVisible({ timeout: 15000 })
143144

144145
// Check that save button is disabled
145146
const saveBtn = page.locator('[data-cy="editRowSaveButton"]')

playwright/support/commands.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,15 @@ export async function openCreateColumnModal(
268268
timeout: 10000,
269269
})
270270
if (isFirstColumn) {
271-
const createBtn = page
272-
.locator('.button-vue__text')
273-
.filter({ hasText: 'Create column' })
271+
const createBtn = page.locator('[data-cy="emptyTableCreateColumnBtn"]')
274272
await createBtn.waitFor({ state: 'visible' })
275273
await createBtn.click({ force: true })
276274
} else {
277275
await clickOnTableThreeDotMenu(page, 'Create column')
278276
}
277+
await expect(page.getByRole('dialog', { name: /^Create column$/ })).toBeVisible({
278+
timeout: 10000,
279+
})
279280
await expect(page.locator('[data-cy="columnTypeFormInput"]')).toBeVisible()
280281
}
281282

@@ -422,7 +423,9 @@ export async function loadContext(page: Page, title: string) {
422423
await contextItem.scrollIntoViewIfNeeded()
423424
const contextLink = contextItem.locator('a').first()
424425
await navigateViaNavLink(page, contextLink)
425-
await expect(page.locator('.icon-loading').first()).toBeHidden()
426+
await expect(
427+
page.locator('h1').filter({ hasText: new RegExp(`^${escapeRegExp(title)}$`) }).first(),
428+
).toBeVisible({ timeout: 15000 })
426429
}
427430

428431
export async function unifiedSearch(page: Page, term: string) {

src/modules/main/sections/EmptyTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{{ table.emoji }}
1010
</template>
1111
<template v-if="canManageTable(table)" #action>
12-
<NcButton :aria-label="t('table', 'Create column')" type="primary" @click="createColumn()">
12+
<NcButton data-cy="emptyTableCreateColumnBtn" :aria-label="t('table', 'Create column')" type="primary" @click="createColumn()">
1313
{{ t('tables', 'Create column') }}
1414
</NcButton>
1515
</template>

src/modules/modals/EditRow.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
</div>
3535

3636
<div v-if="activeTabId === 'edit'" class="row">
37-
<div v-for="column in nonMetaColumns" :key="column.id">
37+
<div v-for="column in nonMetaColumns" :key="column.id" :data-cy="column.title">
3838
<ColumnFormComponent
3939
:column="column"
4040
:value.sync="localRow[column.id]" />
4141
<NcNoteCard v-if="isMandatory(column) && !isValueValidForColumn(localRow[column.id], column)"
42+
data-cy="rowMandatoryError"
4243
type="error">
4344
{{ t('tables', '"{columnTitle}" should not be empty', { columnTitle: column.title }) }}
4445
</NcNoteCard>

0 commit comments

Comments
 (0)