Clarify workflow text conditions

Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
This commit is contained in:
Taylor Ho
2026-08-13 23:18:36 -07:00
parent 4f6ccb2890
commit 4a5bff2614
4 changed files with 41 additions and 5 deletions
@@ -35,6 +35,19 @@ const OPERATOR_LABELS: Record<ConditionOperator, string> = {
is_empty: "is empty",
};
function operatorLabel(
field: string,
operator: ConditionOperator,
usesExactMatchOperators: boolean,
): string {
if (usesExactMatchOperators && operator === "equals") return "is";
if (field === "trigger_text") {
if (operator === "is_not_empty") return "has text";
if (operator === "is_empty") return "has no text";
}
return OPERATOR_LABELS[operator];
}
type ConditionEditorState = {
custom: boolean;
editors: ParsedConditionExpression[];
@@ -141,9 +154,7 @@ function ConditionEditorControls({
>
{operatorOptions.map((operator) => (
<option key={operator} value={operator}>
{usesExactMatchOperators && operator === "equals"
? "is"
: OPERATOR_LABELS[operator]}
{operatorLabel(editor.field, operator, usesExactMatchOperators)}
</option>
))}
</FormSelect>
@@ -23,6 +23,22 @@ test("describes selected trigger conditions on the workflow canvas", () => {
"Message posted containing “deploy”",
);
assert.equal(
workflowTriggerDescription({
on: "message_posted",
filter: "str_len(trigger_text) == 0",
}),
"Message posted without text",
);
assert.equal(
workflowTriggerDescription({
on: "message_posted",
filter: "str_len(trigger_text) > 0",
}),
"Text message posted",
);
assert.equal(
workflowTriggerDescription({
on: "reaction_added",
@@ -49,9 +49,11 @@ function textConditionDescription(
case "not_equals":
return `${eventPhrase} not matching ${value}`;
case "is_not_empty":
return `Non-empty ${eventPhrase.toLowerCase()}`;
return eventPhrase === "Message posted"
? "Text message posted"
: `${eventPhrase} containing text`;
case "is_empty":
return `Empty ${eventPhrase.toLowerCase()}`;
return `${eventPhrase} without text`;
}
}
+7
View File
@@ -297,6 +297,13 @@ test("builds a valid trigger condition from plain-language choices", async ({
await conditionFields.getByRole("button", { name: "Message text" }).click();
await expect(allMessages).toHaveAttribute("aria-pressed", "false");
const matchSelect = inspector.getByLabel("Match");
await expect(matchSelect.locator('option[value="is_not_empty"]')).toHaveText(
"has text",
);
await expect(matchSelect.locator('option[value="is_empty"]')).toHaveText(
"has no text",
);
await inspector.getByLabel("Text to match").fill('deploy "buzz"');
await dialog.getByRole("tab", { name: "YAML" }).click();
await expect(dialog.getByLabel("Workflow YAML")).toHaveValue(