-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathindex.ts
More file actions
113 lines (97 loc) · 2.95 KB
/
index.ts
File metadata and controls
113 lines (97 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { mergeExpects } from "@playwright/test";
import type { Table } from "../pages/Table";
import { tableAssertions, type TableMatchers } from "./TableMatchers";
import type { Pagination } from "../pages/Pagination";
import {
paginationAssertions,
type PaginationMatchers,
} from "./PaginationMatchers";
import type { Toolbar } from "../pages/Toolbar";
import type { TFilterValue } from "../pages/utils";
import { toolbarAssertions, type ToolbarMatchers } from "./ToolbarMatchers";
import type { DeletionConfirmDialog } from "../pages/ConfirmDialog";
import { dialogAssertions, type DialogMatchers } from "./DialogMatchers";
import type { FileUpload } from "../pages/FileUpload";
import {
fileUploadAssertions,
type FileUploadMatchers,
} from "./FileUploadMatchers";
import type { DetailsPage } from "../helpers/DetailsPage";
import {
detailsPageAssertions,
type DetailsPageMatchers,
} from "./DetailsPageMatchers";
const merged = mergeExpects(
tableAssertions,
paginationAssertions,
toolbarAssertions,
dialogAssertions,
fileUploadAssertions,
detailsPageAssertions,
// Add more custom assertions here
);
// Create overloaded expect that preserves types for all custom matchers
/**
* Overload from TableMatchers.ts
*/
function typedExpect<
const TColumns extends readonly string[],
const TActions extends readonly string[],
>(
value: Table<TColumns, TActions>,
): Omit<
ReturnType<typeof merged<Table<TColumns, TActions>>>,
keyof TableMatchers<TColumns, TActions>
> &
TableMatchers<TColumns, TActions>;
/**
* Overload from PaginationMatchers.ts
*/
function typedExpect(
value: Pagination,
): Omit<ReturnType<typeof merged<Pagination>>, keyof PaginationMatchers> &
PaginationMatchers;
/**
* Overload from ToolbarMatchers.ts
*/
function typedExpect<
TFilter extends Record<string, TFilterValue>,
TFilterName extends Extract<keyof TFilter, string>,
TKebabActions extends readonly string[],
>(
value: Toolbar<TFilter, TFilterName, TKebabActions>,
): Omit<
ReturnType<typeof merged<Toolbar<TFilter, TFilterName, TKebabActions>>>,
keyof ToolbarMatchers<TFilter, TFilterName, TKebabActions>
> &
ToolbarMatchers<TFilter, TFilterName, TKebabActions>;
/**
* Overload from DialogMatchers.ts
*/
function typedExpect(
value: DeletionConfirmDialog,
): Omit<
ReturnType<typeof merged<DeletionConfirmDialog>>,
keyof DialogMatchers
> &
DialogMatchers;
/**
* Overload from FileUploadMatchers.ts
*/
function typedExpect(
value: FileUpload,
): Omit<ReturnType<typeof merged<FileUpload>>, keyof FileUploadMatchers> &
FileUploadMatchers;
/**
* Overload from DetailsPageMatchers.ts
*/
function typedExpect(
value: DetailsPage,
): Omit<ReturnType<typeof merged<DetailsPage>>, keyof DetailsPageMatchers> &
DetailsPageMatchers;
// Default overload
function typedExpect<T>(value: T): ReturnType<typeof merged<T>>;
function typedExpect<T>(value: T): unknown {
return merged(value);
}
export const expect = Object.assign(typedExpect, merged);