Skip to content

Commit 2dfdcd6

Browse files
committed
update request-extension feature and fillDateField
1 parent 0e8ab86 commit 2dfdcd6

File tree

5 files changed

+133
-26
lines changed

5 files changed

+133
-26
lines changed

features/rope-record/rope-details/request-extension.feature

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ Feature: Rope Records
33

44
Background: Login
55
Given I navigate to the Rope record page
6+
And I navigate to the Rope Detail Page for an In Service rope with Serial number 'CUCSNO168681'
67

7-
Scenario: User requests an extension for an In Service rope
8-
Given I navigate to the Rope Detail Page for an In Service rope with Serial number 'CUCSNO168681'
9-
And I provide the following information in the Request Extension form
10-
| Request by days | 6 |
8+
Scenario: User requests an extension by days for an In Service rope
9+
When I request an extension for '6' days
10+
Then I should be able to see the request in Extension history section
11+
12+
Scenario: User requests an extension by date for an In Service rope
13+
When I request an extension until 'Dec 20, 2026'
1114
Then I should be able to see the request in Extension history section

src/pages/CreateRopeRecord.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class CreateRopeRecord {
3636
{ name: 'The percentage by mass of', type: 'input' },
3737
{ name: 'The trade name of the', type: 'input' },
3838
{ name: 'Request by days', type: 'input' },
39+
{ name: 'Request by date', type: 'date' },
3940
];
4041

4142
// Dynamic field value setter

src/steps/nagivation.steps.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,18 @@ Given(
6161
} catch {
6262
const statusHeader = page.locator('.ag-cell-label-container').filter({ hasText: 'Status' });
6363
await statusHeader.locator('.menu-icon').click();
64-
await page.getByLabel('(Select All)').uncheck();
64+
try {
65+
await page.getByLabel('(Select All)').uncheck();
66+
} catch (error) {
67+
if (
68+
error instanceof Error
69+
&& error.message.includes('Clicking the checkbox did not change its state')
70+
) {
71+
// Ignore the "did not change its state" error
72+
return;
73+
}
74+
throw error;
75+
}
6576
await page.getByLabel('In Service').check();
6677

6778
try {
Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,54 @@
1-
import { DataTable, Then, When } from '@cucumber/cucumber';
1+
import { Then, When } from '@cucumber/cucumber';
22
import { expect } from '@playwright/test';
33

44
import { CreateRopeRecord } from '../../../pages/CreateRopeRecord';
55
import { EmailVerification } from '../../../pages/EmailVerification';
66
import { IHoistWorld } from '../../../support/hoist-world';
77

8-
When(
9-
'I provide the following information in the Request Extension form',
10-
async function (this: IHoistWorld, requestExtensionInfo: DataTable) {
8+
Then(
9+
'I should be able to see the request in Extension history section',
10+
async function (this: IHoistWorld) {
1111
const page = this.page!;
12-
await page.getByTestId('requestExtButton').click();
13-
const ropeRecord = new CreateRopeRecord(page);
14-
const requestExtensionData = requestExtensionInfo.rowsHash();
15-
for (const [fieldName, value] of Object.entries(requestExtensionData)) {
16-
await ropeRecord.setFieldValue(fieldName, value, ropeRecord.ropeMetadata);
17-
}
12+
13+
// save the number of days that were requested
14+
const daysRequestedLocator = page.getByLabel('Request by days').getByRole('textbox');
15+
const daysRequested = await daysRequestedLocator.inputValue();
16+
17+
// save the form
1818
await page.getByRole('button', { name: 'Next' }).click();
19-
// for download and Confirmation modal
19+
20+
// download the Request Extension eml
2021
const download1Promise = page.waitForEvent('download');
22+
// confirmation modal
2123
await page.getByRole('button', { name: 'Confirm' }).click();
2224
const download1 = await download1Promise;
2325
const emailPage = new EmailVerification(this.page!);
2426
emailPage.verifyRequestExtensionEmailName(download1);
27+
28+
// navigate to Rope information tab to verify the extension request
29+
await page.getByRole('tab', { name: 'Rope information' }).click();
30+
console.log('searching for days', daysRequested);
31+
await expect(page.getByText(`Requested: ${daysRequested} days`).first()).toBeVisible();
2532
},
2633
);
2734

28-
Then(
29-
'I should be able to see the request in Extension history section',
30-
async function (this: IHoistWorld) {
31-
await this.page?.getByRole('tab', { name: 'Rope information' }).click();
35+
When(
36+
'I request an extension for {string} days',
37+
async function (this: IHoistWorld, daysReq: string) {
3238
const page = this.page!;
33-
const expectedValue = '6';
34-
await expect(page.getByText(`Requested: ${expectedValue} days`).first()).toBeVisible();
39+
await page.getByTestId('requestExtButton').click();
40+
const ropeRecord = new CreateRopeRecord(page);
41+
await ropeRecord.setFieldValue('Request by days', daysReq, ropeRecord.ropeMetadata);
42+
},
43+
);
44+
45+
When(
46+
'I request an extension until {string}',
47+
async function (this: IHoistWorld, dateString: string) {
48+
const page = this.page!;
49+
await page.getByTestId('requestExtButton').click();
50+
await page.getByRole('button', { name: 'By date' }).click();
51+
const ropeRecord = new CreateRopeRecord(page);
52+
await ropeRecord.setFieldValue('Request by date', dateString, ropeRecord.ropeMetadata);
3553
},
3654
);

src/support/FormHelper.ts

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class FormHelper {
3636
break;
3737

3838
case 'date':
39-
await this.fillDateField(page, name);
39+
await this.fillDateField(page, name, value);
4040
break;
4141

4242
case 'input':
@@ -71,9 +71,83 @@ export class FormHelper {
7171
}
7272

7373
// Method to fill date fields
74-
private async fillDateField(page: Page, name: string): Promise<void> {
75-
await page.getByRole('textbox', { name }).click();
76-
await page.getByRole('button', { name: 'OK', exact: true }).click();
74+
private async fillDateField(page: Page, name: string, dateString?: string): Promise<void> {
75+
await page.getByText(name).click();
76+
77+
if (!dateString) {
78+
await page.getByRole('button', { name: 'OK', exact: true }).click();
79+
return;
80+
}
81+
82+
const date = new Date(dateString);
83+
const targetYear = date.getFullYear().toString();
84+
const targetMonth = date.toLocaleString('default', { month: 'long' });
85+
const targetDay = date.getDate().toString();
86+
87+
// click the current year to display the year list
88+
await page.getByRole('button', { name: targetYear }).click();
89+
// then select the target year
90+
await page
91+
.locator('div')
92+
.filter({ hasText: new RegExp(`^${targetYear}$`) })
93+
.click();
94+
95+
// get current month and year
96+
const getCurrentHeader = async () => {
97+
const headerLocator = page.locator('div').filter({
98+
hasText: new RegExp(`^${targetMonth} ${targetYear}SuMoTuWeThFrSa$`),
99+
});
100+
const exists = (await headerLocator.count()) > 0;
101+
if (!exists) return null;
102+
const header = await headerLocator.textContent();
103+
return header?.split(' ')[0] ?? null;
104+
};
105+
106+
let currentMonth = await getCurrentHeader();
107+
108+
// navigate until we reach target month
109+
while (currentMonth !== targetMonth) {
110+
if (!currentMonth) {
111+
// move forward until header (selected month) matches target month
112+
await page
113+
.locator('div')
114+
.filter({
115+
hasText: /^[A-Za-z]+ \d{4}SuMoTuWeThFrSa$/,
116+
})
117+
.getByRole('button')
118+
.nth(1)
119+
.click();
120+
} else {
121+
const currentDate = new Date(`${currentMonth} 1 ${targetYear}`);
122+
const targetDate = new Date(`${targetMonth} 1 ${targetYear}`);
123+
124+
if (currentDate < targetDate) {
125+
await page
126+
.locator('div')
127+
.filter({
128+
hasText: new RegExp(`^${currentMonth} ${targetYear}SuMoTuWeThFrSa$`),
129+
})
130+
.getByRole('button')
131+
.nth(1)
132+
.click();
133+
} else {
134+
await page
135+
.locator('div')
136+
.filter({
137+
hasText: new RegExp(`^${currentMonth} ${targetYear}SuMoTuWeThFrSa$`),
138+
})
139+
.getByRole('button')
140+
.first()
141+
.click();
142+
}
143+
}
144+
145+
await page.waitForTimeout(100);
146+
currentMonth = await getCurrentHeader();
147+
}
148+
149+
// select the date
150+
await page.getByRole('button', { name: targetDay, exact: true }).click();
77151
}
78152

79153
public getFieldMetadata(

0 commit comments

Comments
 (0)