Skip to content

Commit 5f64986

Browse files
authored
refactor(copy-dialog): extract field validation logic into a separate test (#28)
- Split P-CPAP-1/P-CDAD-1 tests into P-CPAP-1.1/P-CDAD-1.1 (dedicated field validation logic) and P-CPAP-1.2/P-CDAD-1.2 (empty package copying) - Improve locator usage in an Autocomplete component with more precise RegExp matching - Add detailed test descriptions for all test cases - Fix chip selection in test assertions - Replace commented code with proper assertions - Update revision validation to be more robust against test retries - Change source version constant for better test data organization
1 parent 9bdf4c4 commit 5f64986

File tree

4 files changed

+182
-61
lines changed

4 files changed

+182
-61
lines changed

src/packages/shared/components/base/text-fields/Autocomplete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export class Autocomplete extends TextField {
2626

2727
getChip(chipName?: string): Chip {
2828
if (chipName) {
29-
return new Chip(this.page.locator('.MuiChip-root').filter({ hasText: chipName }).first(), chipName)
29+
return new Chip(this.rootLocator.locator('.MuiChip-root').filter({ hasText: new RegExp(`^${chipName}$`) }), chipName)
3030
}
31-
return new Chip(this.page.locator('.MuiChip-root'))
31+
return new Chip(this.rootLocator.locator('.MuiChip-root'))
3232
}
3333

3434
async set(listItem: string | string[], options?: { clearBefore?: boolean; fillItemName?: boolean }): Promise<void> {

src/test-data/portal/copying/versions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ export const V_P_DSH_COPYING_SOURCE_R: Version = {
2626
...V_P_DSH_CHANGELOG_REST_CHANGED_R,
2727
pkg: P_DSH_CP_SOURCE,
2828
previousVersion: '',
29+
metadata: { versionLabels: ['source-label-1', 'source-label-2'] },
2930
} as const
3031
export const V_P_DSH_COPYING_RELEASE_N: Version = {
3132
...V_P_DSH_CHANGELOG_REST_BASE_R,
3233
pkg: P_DSH_CP_RELEASE,
3334
version: '2000.1',
35+
metadata: { versionLabels: ['release-label-1', 'release-label-2'] },
3436
} as const

src/tests/portal/14-copying/14.1-copying-package-version.spec.ts

Lines changed: 88 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,22 @@ import { test } from '@fixtures'
22
import { PortalPage } from '@portal/pages/PortalPage'
33
import { expect } from '@services/expect-decorator'
44
import { DRAFT_VERSION_STATUS, NO_PREV_RELEASE_VERSION, RELEASE_VERSION_STATUS } from '@shared/entities'
5-
import {
6-
P_PK_CP_EMPTY,
7-
P_PK_CP_PATTERN,
8-
P_PK_CP_RELEASE,
9-
P_WS_MAIN_R,
10-
RV_PATTERN_NEW,
11-
V_P_PKG_CHANGELOG_REST_CHANGED_R,
12-
V_P_PKG_COPYING_RELEASE_N,
13-
VERSION_COPIED_MSG,
14-
} from '@test-data/portal'
5+
import { P_PK_CP_EMPTY, P_PK_CP_PATTERN, P_PK_CP_RELEASE, P_WS_MAIN_R, RV_PATTERN_NEW, V_P_PKG_COPYING_RELEASE_N, V_P_PKG_COPYING_SOURCE_R, VERSION_COPIED_MSG } from '@test-data/portal'
156
import { PUBLISH_TIMEOUT, TICKET_BASE_URL } from '@test-setup'
167
import { SYSADMIN } from '@test-data'
178

189
test.describe('14.1 Copying Package Version', () => {
1910

20-
const sourceVersion = V_P_PKG_CHANGELOG_REST_CHANGED_R
11+
const sourceVersion = V_P_PKG_COPYING_SOURCE_R
2112

22-
test('[P-CPAP-1] Copy Version to an empty package',
13+
test.skip('[P-CPAP-1.1] Copy Version dialog field validation logic',
2314
{
2415
tag: '@smoke',
2516
annotation: [
26-
{ type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-9365` },
17+
{
18+
type: 'Description',
19+
description: 'Verifies the behavior of fields in the Copy Version dialog. The test checks pre-populated fields in the dialog, field clearing behavior, package field disabling when workspace is cleared, and ensures cleared target version fields are not auto-populated when workspace/package is selected.',
20+
},
2721
{ type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-9363` },
2822
{ type: 'Issue', description: `${TICKET_BASE_URL}TestCase-B-1403` },
2923
],
@@ -32,22 +26,29 @@ test.describe('14.1 Copying Package Version', () => {
3226

3327
const portalPage = new PortalPage(page)
3428
const { versionPackagePage: versionPage } = portalPage
35-
const { overviewTab, operationsTab, deprecatedTab, documentsTab, copyVersionDialog } = versionPage
29+
const { copyVersionDialog } = versionPage
3630
const targetWorkspace = P_WS_MAIN_R
3731
const targetPackage = P_PK_CP_EMPTY
3832

39-
await test.step('Open source Version', async () => {
33+
await test.step('Open Copy Version dialog', async () => {
4034
await portalPage.gotoVersion(sourceVersion)
4135
await versionPage.toolbar.copyBtn.click()
4236

4337
await expect(copyVersionDialog.workspaceAc).toHaveValue(targetWorkspace.name)
38+
await expect(copyVersionDialog.packageAc).toBeEnabled()
39+
await expect(copyVersionDialog.packageAc).toBeEmpty()
4440
await expect(copyVersionDialog.versionAc).toHaveValue(sourceVersion.version)
41+
await expect(copyVersionDialog.statusAc).toHaveValue(sourceVersion.status)
42+
for (const label of sourceVersion.metadata!.versionLabels!) {
43+
await expect(copyVersionDialog.labelsAc.getChip(label)).toBeVisible()
44+
}
4545
})
4646

4747
await test.step('Clear fields', async () => {
4848
await copyVersionDialog.workspaceAc.clear()
4949
await copyVersionDialog.versionAc.clear()
50-
await copyVersionDialog.statusAc.clear()
50+
await copyVersionDialog.labelsAc.hover()
51+
await copyVersionDialog.labelsAc.clearBtn.click()
5152

5253
await expect(copyVersionDialog.packageAc).toBeDisabled()
5354
})
@@ -57,24 +58,76 @@ test.describe('14.1 Copying Package Version', () => {
5758
workspace: targetWorkspace,
5859
})
5960

61+
await expect(copyVersionDialog.workspaceAc).toHaveValue(targetWorkspace.name)
6062
await expect(copyVersionDialog.packageAc).toBeEnabled()
61-
/*!await expect(copyVersionDialog.versionAc).toHaveValue(sourceVersion.version) //Issue: TestCase-B-1403
63+
await expect(copyVersionDialog.packageAc).toBeEmpty()
64+
await expect(copyVersionDialog.versionAc).toBeEmpty()
6265
await expect(copyVersionDialog.statusAc).toHaveValue(sourceVersion.status)
63-
for (const label of sourceVersion.metadata!.versionLabels!) {
64-
await expect(copyVersionDialog.labelsAc).toContainText(label)
65-
}*/
66+
await expect(copyVersionDialog.labelsAc.getChip()).toHaveCount(0)
6667
})
6768

6869
await test.step('Set target Package', async () => {
6970
await copyVersionDialog.fillForm({
7071
package: targetPackage,
7172
})
7273

73-
/*!await expect(copyVersionDialog.versionAc).toHaveValue(sourceVersion.version) //Issue: TestCase-B-1403
74+
await expect(copyVersionDialog.packageAc).toHaveValue(targetPackage.name)
75+
await expect(copyVersionDialog.versionAc).toBeEmpty()
7476
await expect(copyVersionDialog.statusAc).toHaveValue(sourceVersion.status)
75-
for (const label of sourceVersion.metadata!.versionLabels!) {
76-
await expect(copyVersionDialog.labelsAc).toContainText(label)
77-
}*/
77+
await expect(copyVersionDialog.labelsAc.getChip()).toHaveCount(0)
78+
})
79+
80+
await test.step('Set target Version Info', async () => {
81+
await copyVersionDialog.fillForm({
82+
version: '2000.2',
83+
status: DRAFT_VERSION_STATUS,
84+
labels: ['label-1', 'label-2'],
85+
previousVersion: NO_PREV_RELEASE_VERSION,
86+
})
87+
88+
await expect(copyVersionDialog.workspaceAc).toHaveValue(targetWorkspace.name)
89+
await expect(copyVersionDialog.packageAc).toHaveValue(targetPackage.name)
90+
await expect(copyVersionDialog.versionAc).toHaveValue('2000.2')
91+
await expect(copyVersionDialog.statusAc).toHaveValue(DRAFT_VERSION_STATUS)
92+
await expect(copyVersionDialog.labelsAc.getChip()).toHaveCount(2)
93+
await expect(copyVersionDialog.labelsAc.getChip('label-1')).toBeVisible()
94+
await expect(copyVersionDialog.labelsAc.getChip('label-2')).toBeVisible()
95+
})
96+
})
97+
98+
test('[P-CPAP-1.2] Copy Version to an empty package',
99+
{
100+
tag: '@smoke',
101+
annotation: [
102+
{
103+
type: 'Description',
104+
description: 'Verifies the Copy Version functionality to an empty package. The test validates version copying process and verifies the copied version content (operations, documents, deprecated items).',
105+
},
106+
{ type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-9363` },
107+
{ type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-9365` },
108+
],
109+
},
110+
async ({ sysadminPage: page }) => {
111+
112+
const portalPage = new PortalPage(page)
113+
const { versionPackagePage: versionPage } = portalPage
114+
const { overviewTab, operationsTab, deprecatedTab, documentsTab, copyVersionDialog } = versionPage
115+
const targetWorkspace = P_WS_MAIN_R
116+
const targetPackage = P_PK_CP_EMPTY
117+
118+
await test.step('Open Copy Version dialog', async () => {
119+
await portalPage.gotoVersion(sourceVersion)
120+
await versionPage.toolbar.copyBtn.click()
121+
122+
await expect(copyVersionDialog.workspaceAc).toHaveValue(targetWorkspace.name)
123+
})
124+
125+
await test.step('Set target Package', async () => {
126+
await copyVersionDialog.fillForm({
127+
package: targetPackage,
128+
})
129+
130+
await expect(copyVersionDialog.packageAc).toHaveValue(targetPackage.name)
78131
})
79132

80133
await test.step('Set target Version Info and copy Version', async () => {
@@ -140,9 +193,12 @@ test.describe('14.1 Copying Package Version', () => {
140193
{
141194
tag: '@smoke',
142195
annotation: [
143-
{ type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-9371` },
196+
{
197+
type: 'Description',
198+
description: 'Verifies copying a version to a package using previous version. Tests specifying a previous version during copying, validating the status can be set to Release, and proper version relationship is established. Confirms all copied content (operations, API changes, deprecated items, documents) are correctly displayed, and verifies version history shows both versions.',
199+
},
144200
{ type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-9370` },
145-
{ type: 'Issue', description: `${TICKET_BASE_URL}TestCase-B-1403` },
201+
{ type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-9371` },
146202
],
147203
},
148204
async ({ sysadminPage: page }) => {
@@ -153,7 +209,7 @@ test.describe('14.1 Copying Package Version', () => {
153209
const targetWorkspace = P_WS_MAIN_R
154210
const targetPackage = P_PK_CP_RELEASE
155211

156-
await test.step('Open source Version', async () => {
212+
await test.step('Open Copy Version dialog', async () => {
157213
await portalPage.gotoVersion(sourceVersion)
158214
await versionPage.toolbar.copyBtn.click()
159215

@@ -166,11 +222,6 @@ test.describe('14.1 Copying Package Version', () => {
166222
})
167223

168224
await expect(copyVersionDialog.packageAc).toHaveValue(targetPackage.name)
169-
/*!await expect(copyVersionDialog.versionAc).toHaveValue(sourceVersion.version) //Issue: TestCase-B-1403
170-
await expect(copyVersionDialog.statusAc).toHaveValue(sourceVersion.status)
171-
for (const label of sourceVersion.metadata!.versionLabels!) {
172-
await expect(copyVersionDialog.labelsAc).toContainText(label)
173-
}*/
174225
await expect(copyVersionDialog.previousVersionAc).toHaveValue(NO_PREV_RELEASE_VERSION)
175226
})
176227

@@ -193,7 +244,7 @@ test.describe('14.1 Copying Package Version', () => {
193244
await expect(overviewTab.summaryTab.body.labels).toContainText('label-1')
194245
await expect(overviewTab.summaryTab.body.labels).toContainText('label-2')
195246
await expect(overviewTab.summaryTab.body.summary.currentVersion).toHaveText('2000.2')
196-
await expect(overviewTab.summaryTab.body.summary.revision).toHaveText('1')
247+
await expect(overviewTab.summaryTab.body.summary.revision).not.toBeEmpty() //not a specific number because it changes every retry
197248
await expect(overviewTab.summaryTab.body.summary.previousVersion).toHaveText(V_P_PKG_COPYING_RELEASE_N.version)
198249
await expect(overviewTab.summaryTab.body.summary.publishedBy).toHaveText(SYSADMIN.name)
199250
await expect(overviewTab.summaryTab.body.summary.publicationDate).not.toBeEmpty()
@@ -236,6 +287,10 @@ test.describe('14.1 Copying Package Version', () => {
236287
{
237288
tag: '@smoke',
238289
annotation: [
290+
{
291+
type: 'Description',
292+
description: 'The test attempts to create a version that violates the target package pattern requirement and confirms the appropriate error message is displayed, preventing invalid version creation.',
293+
},
239294
{ type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-9369` },
240295
{ type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-9370` },
241296
],

0 commit comments

Comments
 (0)