test: cover favorite picker states
This commit is contained in:
@@ -106,6 +106,7 @@ describe("favorite-row-picker", () => {
|
|||||||
);
|
);
|
||||||
expect(button.type).toBe("button");
|
expect(button.type).toBe("button");
|
||||||
expect(button.title).toBe("加入收藏夹");
|
expect(button.title).toBe("加入收藏夹");
|
||||||
|
expect(button.getAttribute("aria-label")).toBe("加入收藏夹");
|
||||||
expect(button.dataset.scesFavoriteCount).toBe("0");
|
expect(button.dataset.scesFavoriteCount).toBe("0");
|
||||||
expect(button.dataset.scesFavoriteIcon).toBe("bookmark-outline");
|
expect(button.dataset.scesFavoriteIcon).toBe("bookmark-outline");
|
||||||
});
|
});
|
||||||
@@ -117,6 +118,7 @@ describe("favorite-row-picker", () => {
|
|||||||
|
|
||||||
const button = readFavoriteButton(actionCell);
|
const button = readFavoriteButton(actionCell);
|
||||||
expect(button.title).toBe("已收藏至 2 个收藏夹");
|
expect(button.title).toBe("已收藏至 2 个收藏夹");
|
||||||
|
expect(button.getAttribute("aria-label")).toBe("已收藏至 2 个收藏夹");
|
||||||
expect(button.dataset.scesFavoriteCount).toBe("2");
|
expect(button.dataset.scesFavoriteCount).toBe("2");
|
||||||
expect(button.dataset.scesFavoriteIcon).toBe("bookmark-filled");
|
expect(button.dataset.scesFavoriteIcon).toBe("bookmark-filled");
|
||||||
});
|
});
|
||||||
@@ -146,6 +148,13 @@ describe("favorite-row-picker", () => {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(readFavoriteButton(firstCell).getAttribute("aria-label")).toBe(
|
||||||
|
"加入收藏夹"
|
||||||
|
);
|
||||||
|
expect(readFavoriteButton(secondCell).getAttribute("aria-label")).toBe(
|
||||||
|
"加入收藏夹"
|
||||||
|
);
|
||||||
|
|
||||||
readFavoriteButton(firstCell).click();
|
readFavoriteButton(firstCell).click();
|
||||||
expect(readPopover()).not.toBeNull();
|
expect(readPopover()).not.toBeNull();
|
||||||
readFavoriteButton(secondCell).click();
|
readFavoriteButton(secondCell).click();
|
||||||
@@ -153,11 +162,37 @@ describe("favorite-row-picker", () => {
|
|||||||
expect(readPopover()?.textContent).toContain("合作");
|
expect(readPopover()?.textContent).toContain("合作");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("shows existing folder membership in the picker", () => {
|
||||||
|
const actionCell = createActionCell();
|
||||||
|
|
||||||
|
sync({ actionCell, folderIds: [firstFolder.id] });
|
||||||
|
readFavoriteButton(actionCell).click();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
document.querySelector(
|
||||||
|
`input[data-sces-favorite-folder-id="${firstFolder.id}"]`
|
||||||
|
) as HTMLInputElement
|
||||||
|
).checked
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
document.querySelector(
|
||||||
|
`input[data-sces-favorite-folder-id="${secondFolder.id}"]`
|
||||||
|
) as HTMLInputElement
|
||||||
|
).checked
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
test("saves the complete checked folder selection for the matching creator", async () => {
|
test("saves the complete checked folder selection for the matching creator", async () => {
|
||||||
const actionCell = createActionCell();
|
const actionCell = createActionCell();
|
||||||
const onSetCreatorFolderIds = vi.fn(async () => {});
|
const onSetCreatorFolderIds = vi.fn(async () => {});
|
||||||
|
|
||||||
sync({ actionCell, onSetCreatorFolderIds });
|
sync({
|
||||||
|
actionCell,
|
||||||
|
folderIds: [firstFolder.id],
|
||||||
|
onSetCreatorFolderIds
|
||||||
|
});
|
||||||
readFavoriteButton(actionCell).click();
|
readFavoriteButton(actionCell).click();
|
||||||
const folderCheckbox = document.querySelector(
|
const folderCheckbox = document.querySelector(
|
||||||
`input[data-sces-favorite-folder-id="${secondFolder.id}"]`
|
`input[data-sces-favorite-folder-id="${secondFolder.id}"]`
|
||||||
@@ -166,8 +201,11 @@ describe("favorite-row-picker", () => {
|
|||||||
folderCheckbox.dispatchEvent(new Event("change", { bubbles: true }));
|
folderCheckbox.dispatchEvent(new Event("change", { bubbles: true }));
|
||||||
await flushAsyncEvents();
|
await flushAsyncEvents();
|
||||||
|
|
||||||
expect(onSetCreatorFolderIds).toHaveBeenCalledWith(createCreator(), [secondFolder.id]);
|
expect(onSetCreatorFolderIds).toHaveBeenCalledWith(createCreator(), [
|
||||||
expect(readFavoriteButton(actionCell).dataset.scesFavoriteCount).toBe("1");
|
firstFolder.id,
|
||||||
|
secondFolder.id
|
||||||
|
]);
|
||||||
|
expect(readFavoriteButton(actionCell).dataset.scesFavoriteCount).toBe("2");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("adds a newly created folder to the creator selection", async () => {
|
test("adds a newly created folder to the creator selection", async () => {
|
||||||
@@ -186,6 +224,13 @@ describe("favorite-row-picker", () => {
|
|||||||
|
|
||||||
expect(onCreateFolder).toHaveBeenCalledTimes(1);
|
expect(onCreateFolder).toHaveBeenCalledTimes(1);
|
||||||
expect(onSetCreatorFolderIds).toHaveBeenCalledWith(createCreator(), [createdFolder.id]);
|
expect(onSetCreatorFolderIds).toHaveBeenCalledWith(createCreator(), [createdFolder.id]);
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
document.querySelector(
|
||||||
|
`input[data-sces-favorite-folder-id="${createdFolder.id}"]`
|
||||||
|
) as HTMLInputElement
|
||||||
|
).checked
|
||||||
|
).toBe(true);
|
||||||
expect(readFavoriteButton(actionCell).dataset.scesFavoriteCount).toBe("1");
|
expect(readFavoriteButton(actionCell).dataset.scesFavoriteCount).toBe("1");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user