mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Clarify workflow text conditions
Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
This commit is contained in:
@@ -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`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user