Files
Peter Evans 17c1af4cc4 feat: show formula data as a source badge and the data it points to (#6857)
* feat: show formula data as a source badge and the data it points to

* docs: add a changelog entry for the formula data redesign

* test: close the data explorer before saving a button field in e2e tests

* fix: keep long formula data inside the filter row and wrap its tooltip

* fix: show the link styling tabs for a column just changed to a link
2026-11-26 13:34:21 +00:00

145 lines
5.1 KiB
TypeScript

import { Page, expect } from "@playwright/test";
/**
* Driving a button field's action editor from the grid: opening it, adding and
* expanding actions, and picking values out of the data explorer.
*
* Shared by the button field suites so the two specs cannot drift apart on how
* the editor is reached.
*/
/** The header column of a non-primary field, by name. */
export function fieldHeader(page: Page, name: string) {
return page
.locator(".grid-view__right .grid-view__head .grid-view__column")
.filter({
has: page.locator(".grid-view__description-name", {
hasText: new RegExp(`^\\s*${name}\\s*$`),
}),
});
}
/** Matches a whole label, so one name cannot select another that contains it. */
export function exactly(name: string) {
return new RegExp(`^\\s*${name}\\s*$`);
}
/** Opens a field's "Edit field" form from its header dropdown. */
export async function openFieldEditor(page: Page, name: string) {
// The Context self-hides when it does not fit, and the first click can land
// before the header has settled, so open it until the menu is really there.
const editItem = page.locator(".context__menu-item", {
hasText: "Edit field",
});
await expect(async () => {
await fieldHeader(page, name)
.locator(".grid-view__description-icon-trigger")
.click();
await expect(editItem).toBeVisible({ timeout: 1000 });
}).toPass({ timeout: 15_000 });
await editItem.click();
await expect(page.locator(".button-field-action-list")).toBeVisible();
}
/**
* Saves the open editor and waits for it to close. The field update and each
* action call go out one after another, and the editor only closes once all
* of them are done, so navigating away any earlier can cancel part of the save.
* The data explorer stays open until the formula input loses focus, and it can
* cover Save, so the section heading is clicked first to close it, as in
* `addAction`.
*/
export async function saveField(page: Page) {
await page.locator(".button-field-action-list__title").click();
await expect(explorer(page)).toBeHidden();
await page.locator(".field-context button", { hasText: "Save" }).click();
await expect(page.locator(".button-field-action-list")).toBeHidden();
}
/** The data explorer that opens under a formula input. */
export function explorer(page: Page) {
return page.locator("[data-formula-input-context]:visible");
}
/** Walks the explorer, opening each node in turn and picking the last. */
export async function pickExplorerNode(page: Page, ...names: string[]) {
for (const name of names) {
await explorer(page)
.locator(".node-explorer-content__name", {
hasText: new RegExp(`^\\s*${name}\\s*$`),
})
.first()
.click();
}
}
/** One action's row in the editor's list. */
export function actionItem(page: Page, index: number) {
return page
.locator(".button-field-action-list .button-field-action-list__item")
.nth(index);
}
/**
* Opens an action's card. Saved actions load collapsed, so anything that
* reaches into a form has to open it first, the way a user would.
*/
export async function expandAction(page: Page, index: number) {
const item = actionItem(page, index);
const form = item.locator(".button-field-action-list__form");
if (!(await form.isVisible())) {
await item.locator("[data-action-toggle]").click();
await expect(form).toBeVisible();
}
}
/** Adds an action of `type` at the end of the list. */
export async function addAction(page: Page, type: string) {
const list = page.locator(".button-field-action-list");
const before = await list.locator(".button-field-action-list__item").count();
// The explorer hides when the formula input loses focus, and it stays open
// over the list until then. The section heading is above the cards, so
// clicking it blurs the editor without the popup in the way.
await list.locator(".button-field-action-list__title").click();
await list.getByText("Add action").click();
const added = actionItem(page, before);
await added.locator(".button-field-action-list__type").click();
await page
.locator(".dropdown__items:visible")
.locator(".select__item-link", { hasText: exactly(type) })
.click();
return added;
}
/** The action type shown on each row of the list, in order. */
export async function actionOrder(page: Page) {
return await page
.locator(".button-field-action-list .button-field-action-list__type")
.allTextContents();
}
/** Picks a row action table from its database group in the shared dropdown. */
export async function pickTableOn(
page: Page,
index: number,
database: string,
table: string,
) {
await expandAction(page, index);
await actionItem(page, index)
.locator(".button-field-action-list__form .dropdown")
.first()
.click();
// Match the database group as well as the whole table label: different
// databases can contain tables with the same name.
await page
.locator(".dropdown__items:visible .dropdown-section")
.filter({
has: page.locator(".dropdown-section__title", {
hasText: `${database} (`,
}),
})
.locator(".select__item-link", { hasText: exactly(table) })
.click();
}