-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles.ts
More file actions
120 lines (94 loc) · 3.43 KB
/
Copy pathfiles.ts
File metadata and controls
120 lines (94 loc) · 3.43 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
114
115
116
117
118
119
120
import { AssertionError } from 'node:assert/strict'
import { BasePage } from './base.ts'
import { Anchor } from './support/anchor.ts'
import { getSortingDirection } from './support/locator.ts'
import { repr } from '../../common/support/strings.ts'
import { type Infer, Schema, validateSchema } from '../../common/validation.ts'
export const DIR_ENTRY_ROW_SCHEMA = Schema.object({
name: Schema.string,
type: Schema.string,
size: Schema.string,
})
export type IDirEntryRow = Infer<typeof DIR_ENTRY_ROW_SCHEMA>
export class FilesPage extends BasePage {
async getDirPath() {
const title = await this.getTitle()
const match = title.match(/Index of \/files(?<dir>.*) ⋅ File navigator ⋅ Ianis Vasilev's website/)
if (match === null || match.groups === undefined) {
throw new AssertionError({
message: `Cannot infer directory path from title ${repr(title)}`,
})
}
return match.groups['dir'] || '/' // Replace the empty string with '/'
}
async getBreadcrumbAnchors() {
const navigation = this._pwPage.locator('.breadcrumb-navigation').first()
const locators = await navigation.getByRole('link').all()
return Object.fromEntries(
await Promise.all(
locators.map(async l => [await l.innerText(), new Anchor(this, l)] as [string, Anchor]),
),
)
}
getReadmeLocator() {
return this._pwPage.locator('.files-page-readme').first()
}
getLanguageNotice() {
return this._pwPage.locator('.notice-warning').getByText("This directory's description")
}
getTableLocator() {
return this._pwPage.getByRole('table').first()
}
async hasTable() {
return this.getTableLocator().isVisible()
}
#getTableHeader(id: string) {
return this.getTableLocator().locator('th#' + id)
}
async getTableHeaderAnchor(id: string) {
const locator = this.#getTableHeader(id).getByRole('link').first()
return new Anchor(this, locator)
}
async getTableHeaderSortDirection(id: string) {
const header = this.#getTableHeader(id)
return await getSortingDirection(header)
}
#getShownDirLocator() {
return this.getTableLocator().locator('tbody').first().getByRole('row')
}
getDirEntryAnchor(name: string) {
const locator = this.#getShownDirLocator().getByText(name).first()
return new Anchor(this, locator)
}
async getShownDirEntries(): Promise<IDirEntryRow[]> {
const rows = await this.#getShownDirLocator().all()
const promises = rows.map(async row => {
const cells = await row.getByRole('cell').all()
const entry: Record<string, string> = {}
for (const cell of cells) {
const headerId = await cell.getAttribute('headers')
if (headerId) {
entry[headerId] = await cell.innerText()
}
}
return validateSchema(DIR_ENTRY_ROW_SCHEMA, entry)
})
return Promise.all(promises)
}
getPaginatorLocator() {
return this._pwPage.locator('.paginator').first()
}
async hasPaginator() {
return this.getPaginatorLocator().isVisible()
}
getPaginatorPrevAnchor() {
return new Anchor(this, this.getPaginatorLocator().locator('.paginator-anchor-prev').first())
}
getPaginatorNextAnchor() {
return new Anchor(this, this.getPaginatorLocator().locator('.paginator-anchor-next').first())
}
async getPaginatorNumberAnchors() {
const locators = await this.getPaginatorLocator().locator('.paginator-anchor-direct').all()
return locators.map(l => new Anchor(this, l))
}
}