Skip to content

Commit bf32970

Browse files
committed
test(ui): connect channel settings fixture for label checks
1 parent b37ee01 commit bf32970

1 file changed

Lines changed: 51 additions & 45 deletions

File tree

‎ui/src/pages/config/view.browser.test.ts‎

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -930,52 +930,58 @@ describe("config view", () => {
930930
},
931931
},
932932
});
933-
const picker = queryRequired(container, "select", HTMLSelectElement);
934-
expect(picker.labels?.[0]?.textContent).toContain("Channel settings");
935-
expect(Array.from(picker.options, (option) => option.textContent?.trim())).toEqual([
936-
"Custom Chat",
937-
"Telegram",
938-
"Other",
939-
]);
940-
expect(picker.selectedOptions[0]?.textContent?.trim()).toBe("Other");
941-
const content = () => normalizedText(queryRequired(container, ".settings-page", HTMLElement));
942-
expect(content()).toContain("Group policy");
943-
expect(content()).toContain("Channel Model Overrides");
944-
expect(content()).not.toContain("Bot username");
945-
props.onSubsectionChange = (key) => {
946-
props.activeSubsection = key;
933+
document.body.append(container);
934+
try {
935+
const picker = queryRequired(container, "select", HTMLSelectElement);
936+
expect(picker.labels?.[0]?.textContent).toContain("Channel settings");
937+
expect(Array.from(picker.options, (option) => option.textContent?.trim())).toEqual([
938+
"Custom Chat",
939+
"Telegram",
940+
"Other",
941+
]);
942+
expect(picker.selectedOptions[0]?.textContent?.trim()).toBe("Other");
943+
const content = () =>
944+
normalizedText(queryRequired(container, ".settings-page", HTMLElement));
945+
expect(content()).toContain("Group policy");
946+
expect(content()).toContain("Channel Model Overrides");
947+
expect(content()).not.toContain("Bot username");
948+
props.onSubsectionChange = (key) => {
949+
props.activeSubsection = key;
950+
render(renderConfig(props), container);
951+
};
947952
render(renderConfig(props), container);
948-
};
949-
render(renderConfig(props), container);
950-
const choose = (key: string) => {
951-
picker.value = key;
952-
picker.dispatchEvent(new Event("change", { bubbles: true }));
953-
};
954-
choose("telegram");
955-
expect(content()).toContain("Bot username");
956-
expect(content()).not.toContain("Group policy");
957-
expect(content()).not.toContain("Room");
958-
const username = queryRequired(container, 'input[type="text"]', HTMLInputElement);
959-
expect(username.value).toBe("test_bot");
960-
username.value = "updated_bot";
961-
username.dispatchEvent(new Event("input", { bubbles: true }));
962-
expect(props.onFormPatch).toHaveBeenCalledWith(
963-
["channels", "telegram", "username"],
964-
"updated_bot",
965-
);
966-
choose("custom-chat");
967-
expect(content()).toContain("Room");
968-
expect(content()).not.toContain("Bot username");
969-
choose("");
970-
const policy = queryRequired(container, 'input[type="text"]', HTMLInputElement);
971-
policy.value = "open";
972-
policy.dispatchEvent(new Event("input", { bubbles: true }));
973-
expect(props.onFormPatch).toHaveBeenCalledWith(
974-
["channels", "defaults", "groupPolicy"],
975-
"open",
976-
);
977-
render(renderConfig({ ...props, formMode: "raw" }), container);
978-
expect(container.querySelector("select")).toBeNull();
953+
const choose = (key: string) => {
954+
picker.value = key;
955+
picker.dispatchEvent(new Event("change", { bubbles: true }));
956+
};
957+
choose("telegram");
958+
expect(content()).toContain("Bot username");
959+
expect(content()).not.toContain("Group policy");
960+
expect(content()).not.toContain("Room");
961+
const username = queryRequired(container, 'input[type="text"]', HTMLInputElement);
962+
expect(username.value).toBe("test_bot");
963+
username.value = "updated_bot";
964+
username.dispatchEvent(new Event("input", { bubbles: true }));
965+
expect(props.onFormPatch).toHaveBeenCalledWith(
966+
["channels", "telegram", "username"],
967+
"updated_bot",
968+
);
969+
choose("custom-chat");
970+
expect(content()).toContain("Room");
971+
expect(content()).not.toContain("Bot username");
972+
choose("");
973+
const policy = queryRequired(container, 'input[type="text"]', HTMLInputElement);
974+
policy.value = "open";
975+
policy.dispatchEvent(new Event("input", { bubbles: true }));
976+
expect(props.onFormPatch).toHaveBeenCalledWith(
977+
["channels", "defaults", "groupPolicy"],
978+
"open",
979+
);
980+
render(renderConfig({ ...props, formMode: "raw" }), container);
981+
expect(container.querySelector("select")).toBeNull();
982+
} finally {
983+
container.remove();
984+
}
979985
},
980986
);
981987

0 commit comments

Comments
 (0)