-
Notifications
You must be signed in to change notification settings - Fork 159
/
sidebar.ts
77 lines (67 loc) · 2.35 KB
/
sidebar.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
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
import { Page } from '@playwright/test'
import util from 'util'
import { locatorUtils } from '../../../utils'
const contextMenuSelector =
'//span[@data-test-resource-name="%s"]/ancestor::tr[contains(@class, "oc-tbody-tr")]//button[contains(@class, "resource-table-btn-action-dropdown")]'
const closeSidebarRootPanelBtn = `#app-sidebar .is-active-root-panel .header__close`
const closeSidebarSubPanelBtn = `#app-sidebar .is-active-sub-panel .header__close`
const openForResource = async ({
page,
resource
}: {
page: Page
resource: string
}): Promise<void> => {
await page.locator(util.format(contextMenuSelector, resource)).click()
await page.locator('.oc-files-actions-show-details-trigger').click()
}
export const openPanelForResource = async ({
page,
resource,
panel
}: {
page: Page
resource: string
panel: string
}): Promise<void> => {
await page.locator(util.format(contextMenuSelector, resource)).click()
await page.locator(`.oc-files-actions-show-${panel}-trigger`).click()
}
const openGlobal = async ({ page }: { page: Page }): Promise<void> => {
await page.locator('#files-toggle-sidebar').click()
}
export const open = async ({
page,
resource
}: {
page: Page
resource?: string
}): Promise<void> => {
if (await page.locator('#app-sidebar').count()) {
await close({ page })
}
resource ? await openForResource({ page, resource }) : await openGlobal({ page })
}
export const close = async ({ page }: { page: Page }): Promise<void> => {
// await sidebar transitions
await new Promise((resolve) => setTimeout(resolve, 250))
const isSubPanelActive = await page.locator(closeSidebarSubPanelBtn).isVisible()
if (isSubPanelActive) {
await page.locator(closeSidebarSubPanelBtn).click()
} else {
await page.locator(closeSidebarRootPanelBtn).click()
}
}
export const openPanel = async ({ page, name }: { page: Page; name: string }): Promise<void> => {
const currentPanel = page.locator('.sidebar-panel.is-active')
const backButton = currentPanel.locator('.header__back')
if (await backButton.count()) {
await Promise.all([
locatorUtils.waitForEvent(currentPanel, 'transitionend'),
backButton.click()
])
}
const panelSelector = page.locator(`#sidebar-panel-${name}-select`)
const nextPanel = page.locator(`#sidebar-panel-${name}`)
await Promise.all([nextPanel.waitFor(), panelSelector.click()])
}