Files
buzz/desktop/src/features/agents/ui/teamDialogSelection.test.mjs
Fizz 8ef3d2d88f test(desktop): repair the share tests and simplify the comments
The change to `TeamsSection.tsx` made 3 tests fail in
`desktop/tests/e2e/team-snapshot.spec.ts`. CI found the failures. This
commit corrects them.

The 3 tests share a team. Before, they used the default mock team
"Engineering", which has no members (`e2eBridge.ts`). The earlier gate
used `hasMissingPersonas`, which is false for a team that has no
members, and thus the Share item was enabled. The new gate uses
`isUsable`, which is correctly false. The Share item is now disabled,
and each test stopped at a disabled menu item.

The new gate is correct. The `build_team_export_snapshot` function makes
one member for each entry in `team.persona_ids`. A team that has no
members thus gives a snapshot that has no members, and
`validate_team_snapshot` refuses it. The mock replaces the encode
command, and therefore the tests did not show this. The 3 tests now seed
their own team, and that team has one member.

This commit also writes all the comments of this change again in
Simplified Technical English (ASD-STE100): short sentences, active
voice, no idioms. The text of the delete dialog is simpler too.

No production behavior changes in this commit.

Co-authored-by: Storme Briscoe <storme@squareup.com>
Signed-off-by: Storme Briscoe <storme@squareup.com>
2026-08-24 14:23:23 -06:00

113 lines
3.3 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import {
canSubmitTeamDialog,
copySelectedPersonaIds,
countMissingPersonaIds,
filterAvailablePersonaIds,
orderPersonasByInitiallySelected,
} from "./teamDialogSelection.ts";
function createPersona(id) {
return {
id,
displayName: id,
avatarUrl: null,
systemPrompt: "Prompt",
runtime: null,
model: null,
namePool: [],
isBuiltIn: false,
isActive: true,
createdAt: "2026-01-01T00:00:00Z",
updatedAt: "2026-01-01T00:00:00Z",
};
}
test("copySelectedPersonaIds keeps initial team members until submit filtering", () => {
const selectedPersonaIds = copySelectedPersonaIds([
"persona:available",
"persona:late",
]);
const initiallyAvailable = [createPersona("persona:available")];
const laterAvailable = [
createPersona("persona:available"),
createPersona("persona:late"),
];
assert.deepEqual(selectedPersonaIds, ["persona:available", "persona:late"]);
assert.deepEqual(
filterAvailablePersonaIds(selectedPersonaIds, initiallyAvailable),
["persona:available"],
);
assert.deepEqual(
filterAvailablePersonaIds(selectedPersonaIds, laterAvailable),
["persona:available", "persona:late"],
);
});
test("countMissingPersonaIds reports unresolved team personas", () => {
assert.equal(
countMissingPersonaIds(
["persona:available", "persona:missing-a", "persona:missing-b"],
[createPersona("persona:available")],
),
2,
);
});
test("filterAvailablePersonaIds drops missing personas at submit time", () => {
assert.deepEqual(
filterAvailablePersonaIds(
["persona:missing", "persona:available"],
[createPersona("persona:available")],
),
["persona:available"],
);
});
test("orderPersonasByInitiallySelected keeps initially selected personas at top", () => {
const personas = [
createPersona("persona:michelangelo"),
createPersona("persona:milhouse"),
createPersona("persona:ned"),
createPersona("persona:raphael"),
];
const ordered = orderPersonasByInitiallySelected(personas, [
"persona:milhouse",
"persona:ned",
"persona:missing",
]);
assert.deepEqual(
ordered.map((persona) => persona.id),
[
"persona:milhouse",
"persona:ned",
"persona:michelangelo",
"persona:raphael",
],
);
});
// ── canSubmitTeamDialog ───────────────────────────────────────────────────
//
// These tests show the correction of a defect. Before, the submit button also
// needed `selectedPersonaIds.length > 0`. Thus you could not save a team after
// you removed all the members, and you could not delete the team.
test("canSubmitTeamDialog allows saving a team with an empty roster", () => {
assert.equal(canSubmitTeamDialog({ name: "Hive", isPending: false }), true);
});
test("canSubmitTeamDialog still requires a non-blank name", () => {
assert.equal(canSubmitTeamDialog({ name: "", isPending: false }), false);
assert.equal(canSubmitTeamDialog({ name: " ", isPending: false }), false);
});
test("canSubmitTeamDialog blocks while a save is in flight", () => {
assert.equal(canSubmitTeamDialog({ name: "Hive", isPending: true }), false);
});