-
-
Notifications
You must be signed in to change notification settings - Fork 284
/
expandTopic.ts
38 lines (33 loc) · 1.2 KB
/
expandTopic.ts
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
import { clickOn } from './'
import { Page } from 'playwright'
export async function expandTopic(path: string, browser: Page) {
const originalTopics = path.split('/')
console.log('expandTopic', path)
let topics = path.split('/')
while (topics.length > 0 && !(await topicMatches(topics, browser))) {
topics = topics.slice(0, topics.length - 1)
}
if (topics.length === 0) {
throw Error('could not expand topics, no match found')
}
console.log('found topics', topics, originalTopics)
for (const topic of topics) {
const match = await browser.locator(topicSelector([topic]))
await clickOn(match.first())
}
// while (topics.length <= originalTopics.length) {
// const match = await browser.locator(topicSelector(topics))
// console.log('click', match)
// await clickOn(match)
// topics.push(originalTopics[topics.length])
// }
}
async function topicMatches(topics: Array<string>, browser: Page) {
const result = await browser.locator(topicSelector(topics))
console.log('topic matches', topics, result)
return true
}
function topicSelector(topics: Array<string>) {
const selectors = topics.map(v => `span[data-test-topic='${v}']`)
return selectors.join(' ')
}