@rickcedwhat/playwright-smart-table 6.3.2 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/engine/rowFinder.d.ts +4 -1
- package/dist/engine/rowFinder.js +38 -15
- package/dist/filterEngine.js +9 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/minimalConfigContext.d.ts +6 -0
- package/dist/minimalConfigContext.js +78 -0
- package/dist/plugins.d.ts +7 -0
- package/dist/smartRow.d.ts +1 -1
- package/dist/smartRow.js +62 -29
- package/dist/strategies/fill.d.ts +1 -1
- package/dist/strategies/fill.js +19 -3
- package/dist/strategies/index.d.ts +9 -1
- package/dist/strategies/pagination.d.ts +17 -2
- package/dist/strategies/pagination.js +65 -43
- package/dist/strategies/rdg.d.ts +14 -0
- package/dist/strategies/rdg.js +43 -1
- package/dist/typeContext.d.ts +1 -1
- package/dist/typeContext.js +61 -32
- package/dist/types.d.ts +49 -36
- package/dist/useTable.d.ts +1 -43
- package/dist/useTable.js +54 -42
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -106,6 +106,14 @@ const allActive = await table.findRows({ Status: 'Active' });
|
|
|
106
106
|
- ❌ You don't need to find a row based on a value in a cell
|
|
107
107
|
- ❌ You don't need to find a cell based on a value in another cell in the same row
|
|
108
108
|
|
|
109
|
+
### ⚠️ Important Note on Pagination & Interactions
|
|
110
|
+
|
|
111
|
+
When using `findRows` across multiple pages, the returned `SmartRow` locators represent elements that may no longer be attached to the current DOM if the table paginated past them.
|
|
112
|
+
|
|
113
|
+
- **Data Extraction:** Safe. You can use `table.iterateThroughTable()` to extract data (`await row.toJSON()`) while the row is visible.
|
|
114
|
+
- **Interactions:** Unsafe directly. You cannot do `await row.click()` if the row is on Page 1 but the table is currently showing Page 3.
|
|
115
|
+
- **Solution:** If you need to interact with a row found on a previous page, you may be able to use `await row.bringIntoView()` before interacting with it to force the table to paginate back to that row (Note: this specific cross-page interaction flow is currently under testing).
|
|
116
|
+
|
|
109
117
|
## Documentation
|
|
110
118
|
|
|
111
119
|
**📚 Full documentation available at: https://rickcedwhat.github.io/playwright-smart-table/**
|
|
@@ -9,8 +9,11 @@ export declare class RowFinder<T = any> {
|
|
|
9
9
|
private filterEngine;
|
|
10
10
|
private tableMapper;
|
|
11
11
|
private makeSmartRow;
|
|
12
|
+
private tableState;
|
|
12
13
|
private resolve;
|
|
13
|
-
constructor(rootLocator: Locator, config: FinalTableConfig, resolve: (item: Selector, parent: Locator | Page) => Locator, filterEngine: FilterEngine, tableMapper: TableMapper, makeSmartRow: (loc: Locator, map: Map<string, number>, index: number) => SmartRow<T
|
|
14
|
+
constructor(rootLocator: Locator, config: FinalTableConfig, resolve: (item: Selector, parent: Locator | Page) => Locator, filterEngine: FilterEngine, tableMapper: TableMapper, makeSmartRow: (loc: Locator, map: Map<string, number>, index: number, tablePageIndex?: number) => SmartRow<T>, tableState?: {
|
|
15
|
+
currentPageIndex: number;
|
|
16
|
+
});
|
|
14
17
|
private log;
|
|
15
18
|
findRow(filters: Record<string, FilterValue>, options?: {
|
|
16
19
|
exact?: boolean;
|
package/dist/engine/rowFinder.js
CHANGED
|
@@ -25,12 +25,13 @@ const debugUtils_1 = require("../utils/debugUtils");
|
|
|
25
25
|
const smartRowArray_1 = require("../utils/smartRowArray");
|
|
26
26
|
const validation_1 = require("../strategies/validation");
|
|
27
27
|
class RowFinder {
|
|
28
|
-
constructor(rootLocator, config, resolve, filterEngine, tableMapper, makeSmartRow) {
|
|
28
|
+
constructor(rootLocator, config, resolve, filterEngine, tableMapper, makeSmartRow, tableState = { currentPageIndex: 0 }) {
|
|
29
29
|
this.rootLocator = rootLocator;
|
|
30
30
|
this.config = config;
|
|
31
31
|
this.filterEngine = filterEngine;
|
|
32
32
|
this.tableMapper = tableMapper;
|
|
33
33
|
this.makeSmartRow = makeSmartRow;
|
|
34
|
+
this.tableState = tableState;
|
|
34
35
|
this.resolve = resolve;
|
|
35
36
|
}
|
|
36
37
|
log(msg) {
|
|
@@ -82,7 +83,7 @@ class RowFinder {
|
|
|
82
83
|
const map = yield this.tableMapper.getMap();
|
|
83
84
|
const allRows = [];
|
|
84
85
|
const effectiveMaxPages = (_b = (_a = options.maxPages) !== null && _a !== void 0 ? _a : this.config.maxPages) !== null && _b !== void 0 ? _b : Infinity;
|
|
85
|
-
let
|
|
86
|
+
let pagesScanned = 1;
|
|
86
87
|
const collectMatches = () => __awaiter(this, void 0, void 0, function* () {
|
|
87
88
|
var _a, _b;
|
|
88
89
|
// ... logic ...
|
|
@@ -94,7 +95,7 @@ class RowFinder {
|
|
|
94
95
|
const currentRows = yield rowLocators.all();
|
|
95
96
|
const isRowLoading = (_b = this.config.strategies.loading) === null || _b === void 0 ? void 0 : _b.isRowLoading;
|
|
96
97
|
for (let i = 0; i < currentRows.length; i++) {
|
|
97
|
-
const smartRow = this.makeSmartRow(currentRows[i], map, allRows.length + i);
|
|
98
|
+
const smartRow = this.makeSmartRow(currentRows[i], map, allRows.length + i, this.tableState.currentPageIndex);
|
|
98
99
|
if (isRowLoading && (yield isRowLoading(smartRow)))
|
|
99
100
|
continue;
|
|
100
101
|
allRows.push(smartRow);
|
|
@@ -105,7 +106,7 @@ class RowFinder {
|
|
|
105
106
|
// Pagination Loop - Corrected logic
|
|
106
107
|
// We always scan at least 1 page.
|
|
107
108
|
// If maxPages > 1, and we have a pagination strategy, we try to go next.
|
|
108
|
-
while (
|
|
109
|
+
while (pagesScanned < effectiveMaxPages && this.config.strategies.pagination) {
|
|
109
110
|
const context = {
|
|
110
111
|
root: this.rootLocator,
|
|
111
112
|
config: this.config,
|
|
@@ -113,11 +114,22 @@ class RowFinder {
|
|
|
113
114
|
page: this.rootLocator.page()
|
|
114
115
|
};
|
|
115
116
|
// Check if we should stop? (e.g. if we found enough rows? No, findRows finds ALL)
|
|
116
|
-
|
|
117
|
+
let paginationResult;
|
|
118
|
+
if (typeof this.config.strategies.pagination === 'function') {
|
|
119
|
+
paginationResult = yield this.config.strategies.pagination(context);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// It's a PaginationPrimitives object, use goNext by default for findRows
|
|
123
|
+
if (!this.config.strategies.pagination.goNext) {
|
|
124
|
+
break; // Cannot paginate forward
|
|
125
|
+
}
|
|
126
|
+
paginationResult = yield this.config.strategies.pagination.goNext(context);
|
|
127
|
+
}
|
|
117
128
|
const didPaginate = yield (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
|
|
118
129
|
if (!didPaginate)
|
|
119
130
|
break;
|
|
120
|
-
|
|
131
|
+
this.tableState.currentPageIndex++;
|
|
132
|
+
pagesScanned++;
|
|
121
133
|
// Wait for reload logic if needed? Usually pagination handles it.
|
|
122
134
|
yield collectMatches();
|
|
123
135
|
}
|
|
@@ -129,7 +141,7 @@ class RowFinder {
|
|
|
129
141
|
var _a, _b;
|
|
130
142
|
const map = yield this.tableMapper.getMap();
|
|
131
143
|
const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : this.config.maxPages;
|
|
132
|
-
let
|
|
144
|
+
let pagesScanned = 1;
|
|
133
145
|
this.log(`Looking for row: ${JSON.stringify(filters)} (MaxPages: ${effectiveMaxPages})`);
|
|
134
146
|
while (true) {
|
|
135
147
|
// Check Loading
|
|
@@ -149,40 +161,51 @@ class RowFinder {
|
|
|
149
161
|
const allRows = this.resolve(this.config.rowSelector, this.rootLocator);
|
|
150
162
|
const matchedRows = this.filterEngine.applyFilters(allRows, filters, map, options.exact || false, this.rootLocator.page());
|
|
151
163
|
const count = yield matchedRows.count();
|
|
152
|
-
this.log(`Page ${
|
|
164
|
+
this.log(`Page ${this.tableState.currentPageIndex}: Found ${count} matches.`);
|
|
153
165
|
if (count > 1) {
|
|
154
166
|
const sampleData = [];
|
|
155
167
|
try {
|
|
156
168
|
const firstFewRows = yield matchedRows.all();
|
|
157
169
|
const sampleCount = Math.min(firstFewRows.length, 3);
|
|
158
170
|
for (let i = 0; i < sampleCount; i++) {
|
|
159
|
-
const rowData = yield this.makeSmartRow(firstFewRows[i], map, 0).toJSON();
|
|
171
|
+
const rowData = yield this.makeSmartRow(firstFewRows[i], map, 0, this.tableState.currentPageIndex).toJSON();
|
|
160
172
|
sampleData.push(JSON.stringify(rowData));
|
|
161
173
|
}
|
|
162
174
|
}
|
|
163
175
|
catch (e) { }
|
|
164
176
|
const sampleMsg = sampleData.length > 0 ? `\nSample matching rows:\n${sampleData.map((d, i) => ` ${i + 1}. ${d}`).join('\n')}` : '';
|
|
165
|
-
throw new Error(`Ambiguous Row: Found ${count} rows matching ${JSON.stringify(filters)} on page ${
|
|
177
|
+
throw new Error(`Ambiguous Row: Found ${count} rows matching ${JSON.stringify(filters)} on page ${this.tableState.currentPageIndex}. ` +
|
|
166
178
|
`Expected exactly one match. Try adding more filters to make your query unique.${sampleMsg}`);
|
|
167
179
|
}
|
|
168
180
|
if (count === 1)
|
|
169
181
|
return matchedRows.first();
|
|
170
|
-
if (
|
|
171
|
-
this.log(`Page ${
|
|
182
|
+
if (pagesScanned < effectiveMaxPages) {
|
|
183
|
+
this.log(`Page ${this.tableState.currentPageIndex}: Not found. Attempting pagination...`);
|
|
172
184
|
const context = {
|
|
173
185
|
root: this.rootLocator,
|
|
174
186
|
config: this.config,
|
|
175
187
|
resolve: this.resolve,
|
|
176
188
|
page: this.rootLocator.page()
|
|
177
189
|
};
|
|
178
|
-
|
|
190
|
+
let paginationResult;
|
|
191
|
+
if (typeof this.config.strategies.pagination === 'function') {
|
|
192
|
+
paginationResult = yield this.config.strategies.pagination(context);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
if (!this.config.strategies.pagination.goNext) {
|
|
196
|
+
this.log(`Page ${this.tableState.currentPageIndex}: Pagination failed (no goNext primitive).`);
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
paginationResult = yield this.config.strategies.pagination.goNext(context);
|
|
200
|
+
}
|
|
179
201
|
const didLoadMore = (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
|
|
180
202
|
if (didLoadMore) {
|
|
181
|
-
|
|
203
|
+
this.tableState.currentPageIndex++;
|
|
204
|
+
pagesScanned++;
|
|
182
205
|
continue;
|
|
183
206
|
}
|
|
184
207
|
else {
|
|
185
|
-
this.log(`Page ${
|
|
208
|
+
this.log(`Page ${this.tableState.currentPageIndex}: Pagination failed (end of data).`);
|
|
186
209
|
}
|
|
187
210
|
}
|
|
188
211
|
return null;
|
package/dist/filterEngine.js
CHANGED
|
@@ -25,10 +25,15 @@ class FilterEngine {
|
|
|
25
25
|
// But for now, we implement the default logic or use custom if we add it to config later
|
|
26
26
|
// Default Filter Logic
|
|
27
27
|
const cellTemplate = this.resolve(this.config.cellSelector, page);
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
28
|
+
// ⚠️ CRITICAL WARNING: DO NOT "FIX" OR REFACTOR THIS LOGIC. ⚠️
|
|
29
|
+
// At first glance, `cellTemplate.nth(colIndex)` looks like a global page selector
|
|
30
|
+
// that will return the Nth cell on the entire page, rather than the Nth cell in the row.
|
|
31
|
+
// THIS IS INTENTIONAL AND CORRECT.
|
|
32
|
+
// Playwright deeply understands nested locator scoping. When this global-looking locator
|
|
33
|
+
// is passed into `filtered.filter({ has: ... })` below, Playwright magically and
|
|
34
|
+
// automatically re-bases the `nth()` selector to be strictly relative to the ROW being evaluated.
|
|
35
|
+
// Attempting to manually force generic relative locators here will break complex function
|
|
36
|
+
// selectors and introduce regressions. Leave it as is.
|
|
32
37
|
const targetCell = cellTemplate.nth(colIndex);
|
|
33
38
|
if (typeof filterVal === 'function') {
|
|
34
39
|
// Locator-based filter: (cell) => cell.locator(...)
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🤖 AUTO-GENERATED FILE. DO NOT EDIT.
|
|
3
|
+
* This file is generated by scripts/embed-config-types.mjs
|
|
4
|
+
* It contains minimal type definitions for config generation prompts.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MINIMAL_CONFIG_CONTEXT = "\n/**\n * Flexible selector type - can be a CSS string or function returning a Locator.\n * @example\n * // String selector\n * rowSelector: 'tbody tr'\n * \n * // Function selector\n * rowSelector: (root) => root.locator('[role=\"row\"]')\n */\nexport type Selector = string | ((root: Locator | Page) => Locator);\n\n/**\n * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\n/**\n * Configuration options for useTable - focus on selectors and basic setup\n */\nexport interface TableConfig<T = any> {\n /** CSS selector or function for table headers */\n headerSelector?: string | ((root: Locator) => Locator);\n \n /** CSS selector or function for table rows */\n rowSelector?: string | ((root: Locator) => Locator);\n \n /** CSS selector or function for cells within a row */\n cellSelector?: string | ((row: Locator) => Locator);\n \n /** Transform header text (e.g., normalize, deduplicate) */\n headerTransformer?: (args: { \n text: string; \n index: number; \n locator: Locator;\n seenHeaders: Set<string>;\n }) => string | Promise<string>;\n \n /** Automatically scroll to table on init (default: true) */\n autoScroll?: boolean;\n \n /** Debug options for development and troubleshooting */\n debug?: DebugConfig;\n \n /** Advanced: Custom strategies for pagination, sorting, navigation, etc. */\n strategies?: TableStrategies;\n \n /** Custom data mappers for extracting complex types (boolean, number) */\n dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;\n}\n\n/**\n * Example usage:\n */\n// const table = useTable(page.locator('table'), {\n// headerSelector: 'thead th',\n// rowSelector: 'tbody tr',\n// cellSelector: 'td',\n// headerTransformer: ({ text }) => text.trim()\n// });\n\n";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MINIMAL_CONFIG_CONTEXT = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 🤖 AUTO-GENERATED FILE. DO NOT EDIT.
|
|
6
|
+
* This file is generated by scripts/embed-config-types.mjs
|
|
7
|
+
* It contains minimal type definitions for config generation prompts.
|
|
8
|
+
*/
|
|
9
|
+
exports.MINIMAL_CONFIG_CONTEXT = `
|
|
10
|
+
/**
|
|
11
|
+
* Flexible selector type - can be a CSS string or function returning a Locator.
|
|
12
|
+
* @example
|
|
13
|
+
* // String selector
|
|
14
|
+
* rowSelector: 'tbody tr'
|
|
15
|
+
*
|
|
16
|
+
* // Function selector
|
|
17
|
+
* rowSelector: (root) => root.locator('[role="row"]')
|
|
18
|
+
*/
|
|
19
|
+
export type Selector = string | ((root: Locator | Page) => Locator);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Debug configuration for development and troubleshooting
|
|
23
|
+
*/
|
|
24
|
+
export type DebugConfig = {
|
|
25
|
+
slow?: number | {
|
|
26
|
+
pagination?: number;
|
|
27
|
+
getCell?: number;
|
|
28
|
+
findRow?: number;
|
|
29
|
+
default?: number;
|
|
30
|
+
};
|
|
31
|
+
logLevel?: 'verbose' | 'info' | 'error' | 'none';
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Configuration options for useTable - focus on selectors and basic setup
|
|
36
|
+
*/
|
|
37
|
+
export interface TableConfig<T = any> {
|
|
38
|
+
/** CSS selector or function for table headers */
|
|
39
|
+
headerSelector?: string | ((root: Locator) => Locator);
|
|
40
|
+
|
|
41
|
+
/** CSS selector or function for table rows */
|
|
42
|
+
rowSelector?: string | ((root: Locator) => Locator);
|
|
43
|
+
|
|
44
|
+
/** CSS selector or function for cells within a row */
|
|
45
|
+
cellSelector?: string | ((row: Locator) => Locator);
|
|
46
|
+
|
|
47
|
+
/** Transform header text (e.g., normalize, deduplicate) */
|
|
48
|
+
headerTransformer?: (args: {
|
|
49
|
+
text: string;
|
|
50
|
+
index: number;
|
|
51
|
+
locator: Locator;
|
|
52
|
+
seenHeaders: Set<string>;
|
|
53
|
+
}) => string | Promise<string>;
|
|
54
|
+
|
|
55
|
+
/** Automatically scroll to table on init (default: true) */
|
|
56
|
+
autoScroll?: boolean;
|
|
57
|
+
|
|
58
|
+
/** Debug options for development and troubleshooting */
|
|
59
|
+
debug?: DebugConfig;
|
|
60
|
+
|
|
61
|
+
/** Advanced: Custom strategies for pagination, sorting, navigation, etc. */
|
|
62
|
+
strategies?: TableStrategies;
|
|
63
|
+
|
|
64
|
+
/** Custom data mappers for extracting complex types (boolean, number) */
|
|
65
|
+
dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Example usage:
|
|
70
|
+
*/
|
|
71
|
+
// const table = useTable(page.locator('table'), {
|
|
72
|
+
// headerSelector: 'thead th',
|
|
73
|
+
// rowSelector: 'tbody tr',
|
|
74
|
+
// cellSelector: 'td',
|
|
75
|
+
// headerTransformer: ({ text }) => text.trim()
|
|
76
|
+
// });
|
|
77
|
+
|
|
78
|
+
`;
|
package/dist/plugins.d.ts
CHANGED
|
@@ -4,6 +4,13 @@ export declare const Plugins: {
|
|
|
4
4
|
header: (context: import("./types").TableContext) => Promise<string[]>;
|
|
5
5
|
getCellLocator: ({ row, columnIndex }: any) => any;
|
|
6
6
|
cellNavigation: ({ root, page, index }: any) => Promise<void>;
|
|
7
|
+
navigation: {
|
|
8
|
+
goRight: ({ root, page }: any) => Promise<void>;
|
|
9
|
+
goLeft: ({ root, page }: any) => Promise<void>;
|
|
10
|
+
goDown: ({ root, page }: any) => Promise<void>;
|
|
11
|
+
goUp: ({ root, page }: any) => Promise<void>;
|
|
12
|
+
goHome: ({ root, page }: any) => Promise<void>;
|
|
13
|
+
};
|
|
7
14
|
pagination: import("./types").PaginationStrategy;
|
|
8
15
|
};
|
|
9
16
|
};
|
package/dist/smartRow.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ import { SmartRow as SmartRowType, FinalTableConfig, TableResult } from './types
|
|
|
4
4
|
* Factory to create a SmartRow by extending a Playwright Locator.
|
|
5
5
|
* We avoid Class/Proxy to ensure full compatibility with Playwright's expect(locator) matchers.
|
|
6
6
|
*/
|
|
7
|
-
export declare const createSmartRow: <T = any>(rowLocator: Locator, map: Map<string, number>, rowIndex: number | undefined, config: FinalTableConfig<T>, rootLocator: Locator, resolve: (item: any, parent: Locator | Page) => Locator, table: TableResult<T> | null) => SmartRowType<T>;
|
|
7
|
+
export declare const createSmartRow: <T = any>(rowLocator: Locator, map: Map<string, number>, rowIndex: number | undefined, config: FinalTableConfig<T>, rootLocator: Locator, resolve: (item: any, parent: Locator | Page) => Locator, table: TableResult<T> | null, tablePageIndex?: number) => SmartRowType<T>;
|
package/dist/smartRow.js
CHANGED
|
@@ -77,43 +77,33 @@ const _navigateToCell = (params) => __awaiter(void 0, void 0, void 0, function*
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
yield page.waitForTimeout(50);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
rowIndex,
|
|
92
|
-
activeCell
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
// Get the active cell locator after navigation (for virtualized tables)
|
|
96
|
-
if (config.strategies.getActiveCell) {
|
|
97
|
-
const updatedActiveCell = yield config.strategies.getActiveCell({
|
|
98
|
-
config,
|
|
99
|
-
root: rootLocator,
|
|
100
|
-
page,
|
|
101
|
-
resolve
|
|
102
|
-
});
|
|
103
|
-
if (updatedActiveCell) {
|
|
104
|
-
return updatedActiveCell.locator;
|
|
80
|
+
// Get the active cell locator after navigation (for virtualized tables)
|
|
81
|
+
if (config.strategies.getActiveCell) {
|
|
82
|
+
const updatedActiveCell = yield config.strategies.getActiveCell({
|
|
83
|
+
config,
|
|
84
|
+
root: rootLocator,
|
|
85
|
+
page,
|
|
86
|
+
resolve
|
|
87
|
+
});
|
|
88
|
+
if (updatedActiveCell) {
|
|
89
|
+
return updatedActiveCell.locator;
|
|
90
|
+
}
|
|
105
91
|
}
|
|
92
|
+
return null;
|
|
106
93
|
}
|
|
94
|
+
;
|
|
107
95
|
return null;
|
|
108
96
|
});
|
|
109
97
|
/**
|
|
110
98
|
* Factory to create a SmartRow by extending a Playwright Locator.
|
|
111
99
|
* We avoid Class/Proxy to ensure full compatibility with Playwright's expect(locator) matchers.
|
|
112
100
|
*/
|
|
113
|
-
const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve, table) => {
|
|
101
|
+
const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve, table, tablePageIndex) => {
|
|
114
102
|
const smart = rowLocator;
|
|
115
103
|
// Attach State
|
|
116
104
|
smart.rowIndex = rowIndex;
|
|
105
|
+
smart.tablePageIndex = tablePageIndex;
|
|
106
|
+
smart.table = table;
|
|
117
107
|
// Attach Methods
|
|
118
108
|
smart.getCell = (colName) => {
|
|
119
109
|
const idx = map.get(colName);
|
|
@@ -132,15 +122,16 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
132
122
|
return resolve(config.cellSelector, rowLocator).nth(idx);
|
|
133
123
|
};
|
|
134
124
|
smart.toJSON = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
-
var _a;
|
|
125
|
+
var _a, _b;
|
|
136
126
|
const result = {};
|
|
137
127
|
const page = rootLocator.page();
|
|
138
128
|
for (const [col, idx] of map.entries()) {
|
|
139
129
|
if ((options === null || options === void 0 ? void 0 : options.columns) && !options.columns.includes(col)) {
|
|
140
130
|
continue;
|
|
141
131
|
}
|
|
142
|
-
// Check if we have a data mapper for this column
|
|
143
|
-
const
|
|
132
|
+
// Check if we have a column override or data mapper for this column
|
|
133
|
+
const columnOverride = (_a = config.columnOverrides) === null || _a === void 0 ? void 0 : _a[col];
|
|
134
|
+
const mapper = (columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.read) || ((_b = config.dataMapper) === null || _b === void 0 ? void 0 : _b[col]);
|
|
144
135
|
if (mapper) {
|
|
145
136
|
// Use custom mapper
|
|
146
137
|
// Ensure we have the cell first (same navigation logic)
|
|
@@ -218,6 +209,7 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
218
209
|
index: rowIndex !== null && rowIndex !== void 0 ? rowIndex : -1,
|
|
219
210
|
page: rowLocator.page(),
|
|
220
211
|
rootLocator,
|
|
212
|
+
config,
|
|
221
213
|
table: table,
|
|
222
214
|
fillOptions
|
|
223
215
|
});
|
|
@@ -230,6 +222,47 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
230
222
|
if (rowIndex === undefined) {
|
|
231
223
|
throw new Error('Cannot bring row into view - row index is unknown. Use getRowByIndex() instead of getRow().');
|
|
232
224
|
}
|
|
225
|
+
const parentTable = smart.table;
|
|
226
|
+
// Cross-page Navigation using PaginationPrimitives
|
|
227
|
+
if (tablePageIndex !== undefined && config.strategies.pagination) {
|
|
228
|
+
const primitives = config.strategies.pagination;
|
|
229
|
+
// Only orchestrate if it's an object of primitives, not a single function
|
|
230
|
+
if (typeof config.strategies.pagination !== 'function') {
|
|
231
|
+
const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
|
|
232
|
+
if (primitives.goToPage) {
|
|
233
|
+
(0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: Jumping to page ${tablePageIndex} using goToPage primitive`);
|
|
234
|
+
yield primitives.goToPage(tablePageIndex, context);
|
|
235
|
+
}
|
|
236
|
+
else if (primitives.goPrevious) {
|
|
237
|
+
(0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: Looping goPrevious until we reach page ${tablePageIndex}`);
|
|
238
|
+
const diff = parentTable.currentPageIndex - tablePageIndex;
|
|
239
|
+
for (let i = 0; i < diff; i++) {
|
|
240
|
+
const success = yield primitives.goPrevious(context);
|
|
241
|
+
if (!success) {
|
|
242
|
+
throw new Error(`bringIntoView: Failed to paginate backwards. Strategy aborted before reaching page ${tablePageIndex}.`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else if (primitives.goToFirst && primitives.goNext) {
|
|
247
|
+
(0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: going to first page and looping goNext until we reach page ${tablePageIndex}`);
|
|
248
|
+
yield primitives.goToFirst(context);
|
|
249
|
+
for (let i = 0; i < tablePageIndex; i++) {
|
|
250
|
+
yield primitives.goNext(context);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
(0, debugUtils_1.logDebug)(config, 'error', `Cannot bring row on page ${tablePageIndex} into view. No backwards pagination strategies (goToPage, goPrevious, or goToFirst) provided.`);
|
|
255
|
+
throw new Error(`Cannot bring row on page ${tablePageIndex} into view: Row is on a different page and no backward pagination primitive found.`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
throw new Error(`Cannot bring row on page ${tablePageIndex} into view: Pagination is a single function. Provide an object with 'goPrevious', 'goToPage', or 'goToFirst' primitives.`);
|
|
260
|
+
}
|
|
261
|
+
// Successfully orchestrated backwards navigation, now update the state pointer
|
|
262
|
+
parentTable.currentPageIndex = tablePageIndex;
|
|
263
|
+
}
|
|
264
|
+
// Delay after pagination/finding before scrolling
|
|
265
|
+
yield (0, debugUtils_1.debugDelay)(config, 'findRow');
|
|
233
266
|
// Scroll row into view using Playwright's built-in method
|
|
234
267
|
yield rowLocator.scrollIntoViewIfNeeded();
|
|
235
268
|
});
|
|
@@ -3,5 +3,5 @@ export declare const FillStrategies: {
|
|
|
3
3
|
/**
|
|
4
4
|
* Default strategy: Detects input type and fills accordingly (Text, Select, Checkbox, ContentEditable).
|
|
5
5
|
*/
|
|
6
|
-
default: ({ row, columnName, value, fillOptions }: Parameters<FillStrategy>[0]) => Promise<void>;
|
|
6
|
+
default: ({ row, columnName, value, fillOptions, config, table }: Parameters<FillStrategy>[0]) => Promise<void>;
|
|
7
7
|
};
|
package/dist/strategies/fill.js
CHANGED
|
@@ -14,12 +14,28 @@ exports.FillStrategies = {
|
|
|
14
14
|
/**
|
|
15
15
|
* Default strategy: Detects input type and fills accordingly (Text, Select, Checkbox, ContentEditable).
|
|
16
16
|
*/
|
|
17
|
-
default: (_a) => __awaiter(void 0, [_a], void 0, function* ({ row, columnName, value, fillOptions }) {
|
|
18
|
-
var _b;
|
|
17
|
+
default: (_a) => __awaiter(void 0, [_a], void 0, function* ({ row, columnName, value, fillOptions, config, table }) {
|
|
18
|
+
var _b, _c;
|
|
19
19
|
const cell = row.getCell(columnName);
|
|
20
|
+
// 1. Check for Unified Column Override
|
|
21
|
+
const columnOverride = (_b = config === null || config === void 0 ? void 0 : config.columnOverrides) === null || _b === void 0 ? void 0 : _b[columnName];
|
|
22
|
+
if (columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.write) {
|
|
23
|
+
let currentValue;
|
|
24
|
+
// Auto-sync: If read exists, fetch current state first
|
|
25
|
+
if (columnOverride.read) {
|
|
26
|
+
currentValue = yield columnOverride.read(cell);
|
|
27
|
+
}
|
|
28
|
+
yield columnOverride.write({
|
|
29
|
+
cell,
|
|
30
|
+
targetValue: value,
|
|
31
|
+
currentValue,
|
|
32
|
+
row
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
20
36
|
// Use custom input mapper for this column if provided, otherwise auto-detect
|
|
21
37
|
let inputLocator;
|
|
22
|
-
if ((
|
|
38
|
+
if ((_c = fillOptions === null || fillOptions === void 0 ? void 0 : fillOptions.inputMappers) === null || _c === void 0 ? void 0 : _c[columnName]) {
|
|
23
39
|
inputLocator = fillOptions.inputMappers[columnName](cell);
|
|
24
40
|
}
|
|
25
41
|
else {
|
|
@@ -12,6 +12,14 @@ export declare const Strategies: {
|
|
|
12
12
|
stabilization?: import("./stabilization").StabilizationStrategy;
|
|
13
13
|
timeout?: number;
|
|
14
14
|
}) => import("..").PaginationStrategy;
|
|
15
|
+
click: (selectors: {
|
|
16
|
+
next?: import("..").Selector;
|
|
17
|
+
previous?: import("..").Selector;
|
|
18
|
+
first?: import("..").Selector;
|
|
19
|
+
}, options?: {
|
|
20
|
+
stabilization?: import("./stabilization").StabilizationStrategy;
|
|
21
|
+
timeout?: number;
|
|
22
|
+
}) => import("..").PaginationStrategy;
|
|
15
23
|
infiniteScroll: (options?: {
|
|
16
24
|
action?: "scroll" | "js-scroll";
|
|
17
25
|
scrollTarget?: import("..").Selector;
|
|
@@ -30,7 +38,7 @@ export declare const Strategies: {
|
|
|
30
38
|
visible: ({ config, resolve, root }: import("..").StrategyContext) => Promise<string[]>;
|
|
31
39
|
};
|
|
32
40
|
Fill: {
|
|
33
|
-
default: ({ row, columnName, value, fillOptions }: Parameters<import("..").FillStrategy>[0]) => Promise<void>;
|
|
41
|
+
default: ({ row, columnName, value, fillOptions, config, table }: Parameters<import("..").FillStrategy>[0]) => Promise<void>;
|
|
34
42
|
};
|
|
35
43
|
Resolution: {
|
|
36
44
|
default: import("./resolution").ColumnResolutionStrategy;
|
|
@@ -3,12 +3,27 @@ import { StabilizationStrategy } from './stabilization';
|
|
|
3
3
|
export declare const PaginationStrategies: {
|
|
4
4
|
/**
|
|
5
5
|
* Strategy: Clicks a "Next" button and waits for stabilization.
|
|
6
|
-
*
|
|
6
|
+
* Backward compatibility for when only a single 'next' selector was needed.
|
|
7
|
+
* @deprecated Use `click` with `{ next: selector }` instead.
|
|
8
|
+
*/
|
|
9
|
+
clickNext: (nextButtonSelector: Selector, options?: {
|
|
10
|
+
stabilization?: StabilizationStrategy;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
}) => PaginationStrategy;
|
|
13
|
+
/**
|
|
14
|
+
* Strategy: Classic Pagination Buttons.
|
|
15
|
+
* Clicks 'Next', 'Previous', or 'First' buttons and waits for stabilization.
|
|
16
|
+
*
|
|
17
|
+
* @param selectors Selectors for pagination buttons.
|
|
7
18
|
* @param options.stabilization Strategy to determine when the page has updated.
|
|
8
19
|
* Defaults to `contentChanged({ scope: 'first' })`.
|
|
9
20
|
* @param options.timeout Timeout for the click action.
|
|
10
21
|
*/
|
|
11
|
-
|
|
22
|
+
click: (selectors: {
|
|
23
|
+
next?: Selector;
|
|
24
|
+
previous?: Selector;
|
|
25
|
+
first?: Selector;
|
|
26
|
+
}, options?: {
|
|
12
27
|
stabilization?: StabilizationStrategy;
|
|
13
28
|
timeout?: number;
|
|
14
29
|
}) => PaginationStrategy;
|