2024-10-15 13:17:11 +03:00
|
|
|
import type { Locator, Page } from '@playwright/test';
|
2024-03-25 06:55:32 +03:00
|
|
|
import { expect } from '@playwright/test';
|
2024-02-22 12:37:55 +03:00
|
|
|
|
|
|
|
export const getPropertyValueLocator = (page: Page, property: string) => {
|
|
|
|
return page.locator(
|
2024-10-15 13:17:11 +03:00
|
|
|
`[data-testid="doc-property-name"]:has-text("${property}") + *`
|
2024-02-22 12:37:55 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-02-26 17:11:24 +03:00
|
|
|
export const ensurePagePropertiesVisible = async (page: Page) => {
|
|
|
|
if (
|
|
|
|
await page
|
|
|
|
.getByRole('button', {
|
|
|
|
name: 'Add property',
|
|
|
|
})
|
|
|
|
.isVisible()
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await page.getByTestId('page-info-collapse').click();
|
|
|
|
};
|
|
|
|
|
2024-02-22 12:37:55 +03:00
|
|
|
export const clickPropertyValue = async (page: Page, property: string) => {
|
|
|
|
await getPropertyValueLocator(page, property).click();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const openTagsEditor = async (page: Page) => {
|
|
|
|
await clickPropertyValue(page, 'tags');
|
|
|
|
await expect(page.getByTestId('tags-editor-popup')).toBeVisible();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const closeTagsEditor = async (page: Page) => {
|
|
|
|
await page.keyboard.press('Escape');
|
|
|
|
await expect(page.getByTestId('tags-editor-popup')).not.toBeVisible();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const clickTagFromSelector = async (page: Page, name: string) => {
|
|
|
|
// assume that the tags editor is already open
|
|
|
|
await page
|
|
|
|
.locator(`[data-testid="tag-selector-item"][data-tag-value="${name}"]`)
|
|
|
|
.click();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const removeSelectedTag = async (page: Page, name: string) => {
|
|
|
|
await page
|
|
|
|
.locator(
|
|
|
|
`[data-testid="tags-editor-popup"] [data-testid="inline-tags-list"] [data-tag-value="${name}"] [data-testid="remove-tag-button"]`
|
|
|
|
)
|
|
|
|
.click();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const filterTags = async (page: Page, filter: string) => {
|
|
|
|
await page
|
|
|
|
.locator(
|
|
|
|
'[data-testid="tags-editor-popup"] [data-testid="inline-tags-list"] input'
|
|
|
|
)
|
|
|
|
.fill(filter);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const searchAndCreateTag = async (page: Page, name: string) => {
|
|
|
|
await filterTags(page, name);
|
|
|
|
await page
|
|
|
|
.locator(
|
|
|
|
'[data-testid="tags-editor-popup"] [data-testid="tag-selector-item"]:has-text("Create ")'
|
|
|
|
)
|
|
|
|
.click();
|
|
|
|
};
|
|
|
|
|
2024-10-15 13:17:11 +03:00
|
|
|
export const expectTagsVisible = async (
|
|
|
|
root: Locator | Page,
|
|
|
|
tags: string[]
|
|
|
|
) => {
|
|
|
|
const tagListPanel = root
|
|
|
|
.getByTestId('property-tags-value')
|
2024-02-22 12:37:55 +03:00
|
|
|
.getByTestId('inline-tags-list');
|
|
|
|
|
|
|
|
expect(await tagListPanel.locator('[data-tag-value]').count()).toBe(
|
|
|
|
tags.length
|
|
|
|
);
|
|
|
|
|
|
|
|
for (const tag of tags) {
|
|
|
|
await expect(
|
|
|
|
tagListPanel.locator(`[data-tag-value="${tag}"]`)
|
|
|
|
).toBeVisible();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-10-15 13:17:11 +03:00
|
|
|
export const clickAddPropertyButton = async (root: Locator | Page) => {
|
|
|
|
await root
|
2024-02-22 12:37:55 +03:00
|
|
|
.getByRole('button', {
|
|
|
|
name: 'Add property',
|
|
|
|
})
|
|
|
|
.click();
|
|
|
|
};
|
|
|
|
|
2024-10-17 16:48:45 +03:00
|
|
|
export const ensureAddPropertyButtonVisible = async (
|
|
|
|
page: Page,
|
|
|
|
root: Locator | Page
|
|
|
|
) => {
|
|
|
|
if (
|
|
|
|
await root
|
|
|
|
.getByRole('button', {
|
|
|
|
name: 'Add property',
|
|
|
|
})
|
|
|
|
.isVisible()
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await togglePropertyListVisibility(page);
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
await expect(
|
|
|
|
root.getByRole('button', { name: 'Add property' })
|
|
|
|
).toBeVisible();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const togglePropertyListVisibility = async (page: Page) => {
|
|
|
|
await page.getByTestId('property-collapsible-button').click();
|
|
|
|
};
|
|
|
|
|
2024-02-22 12:37:55 +03:00
|
|
|
export const addCustomProperty = async (
|
|
|
|
page: Page,
|
2024-10-15 13:17:11 +03:00
|
|
|
root: Locator | Page,
|
|
|
|
type: string
|
2024-02-22 12:37:55 +03:00
|
|
|
) => {
|
2024-10-17 16:48:45 +03:00
|
|
|
ensureAddPropertyButtonVisible(page, root);
|
2024-10-15 13:17:11 +03:00
|
|
|
await clickAddPropertyButton(root);
|
2024-02-22 12:37:55 +03:00
|
|
|
await page
|
2024-10-15 13:17:11 +03:00
|
|
|
.locator(
|
|
|
|
`[data-testid="${'create-property-menu-item'}"][data-property-type="${type}"]`
|
|
|
|
)
|
2024-02-22 12:37:55 +03:00
|
|
|
.click();
|
2024-10-15 13:17:11 +03:00
|
|
|
if (await page.getByTestId('edit-property-menu-item').isVisible()) {
|
|
|
|
// is edit property menu opened, close it
|
2024-09-03 15:00:00 +03:00
|
|
|
await page.keyboard.press('Escape');
|
2024-02-22 12:37:55 +03:00
|
|
|
}
|
2024-09-03 15:00:00 +03:00
|
|
|
await page.waitForTimeout(500);
|
2024-02-22 12:37:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export const expectPropertyOrdering = async (
|
|
|
|
page: Page,
|
|
|
|
properties: string[]
|
|
|
|
) => {
|
|
|
|
for (let i = 0; i < properties.length; i++) {
|
|
|
|
await expect(
|
|
|
|
page.locator(`[data-testid="page-property-row-name"])`).nth(i)
|
|
|
|
).toHaveText(properties[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const openWorkspaceProperties = async (page: Page) => {
|
|
|
|
await page.getByTestId('slider-bar-workspace-setting-button').click();
|
|
|
|
await page
|
|
|
|
.locator('[data-testid="workspace-list-item"] .setting-name')
|
|
|
|
.click();
|
|
|
|
await page.getByTestId('workspace-list-item-properties').click();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const selectVisibilitySelector = async (
|
|
|
|
page: Page,
|
|
|
|
name: string,
|
|
|
|
option: string
|
|
|
|
) => {
|
|
|
|
await page
|
|
|
|
.getByRole('menu')
|
|
|
|
.locator(
|
|
|
|
`[data-testid="page-properties-settings-menu-item"]:has-text("${name}")`
|
|
|
|
)
|
|
|
|
.getByRole('button')
|
|
|
|
.click();
|
|
|
|
|
|
|
|
await page
|
|
|
|
.getByRole('menu')
|
|
|
|
.last()
|
|
|
|
.getByRole('menuitem', {
|
|
|
|
name: option,
|
|
|
|
exact: true,
|
|
|
|
})
|
|
|
|
.click();
|
|
|
|
|
2024-08-29 07:01:35 +03:00
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
2024-02-22 12:37:55 +03:00
|
|
|
await page.keyboard.press('Escape');
|
2024-08-29 07:01:35 +03:00
|
|
|
|
|
|
|
await page.waitForTimeout(500);
|
2024-02-22 12:37:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export const changePropertyVisibility = async (
|
|
|
|
page: Page,
|
|
|
|
name: string,
|
|
|
|
option: string
|
|
|
|
) => {
|
2024-10-15 13:17:11 +03:00
|
|
|
await page
|
|
|
|
.locator(`[data-testid="doc-property-name"]:has-text("${name}")`)
|
|
|
|
.click();
|
|
|
|
await page.locator(`[data-property-visibility="${option}"]`).click();
|
|
|
|
await page.keyboard.press('Escape');
|
|
|
|
await page.waitForTimeout(500);
|
2024-02-22 12:37:55 +03:00
|
|
|
};
|