mirror of
https://github.com/bitwarden/clients.git
synced 2026-07-07 21:10:55 +08:00
[pm-32250] fix: default to "No Folder" in cipher save prompt (#19342)
* [pm-32250] fix: default to "No Folder" in cipher save prompt * [pm-32250] add tests for button-row.ts --------- Signed-off-by: Ben Brooks <bbrooks@bitwarden.com>
This commit is contained in:
parent
1cece8123d
commit
c3c067865e
@ -0,0 +1,77 @@
|
||||
import { ThemeTypes } from "@bitwarden/common/platform/enums";
|
||||
|
||||
import { mockI18n } from "../lit-stories/mock-data";
|
||||
import { ButtonRow } from "../rows/button-row";
|
||||
|
||||
import { NotificationButtonRow } from "./button-row";
|
||||
|
||||
jest.mock("lit", () => ({
|
||||
html: jest.fn((_strings: TemplateStringsArray, ...values: any[]) => values),
|
||||
}));
|
||||
jest.mock("../icons", () => ({
|
||||
Business: jest.fn(),
|
||||
Family: jest.fn(),
|
||||
Folder: jest.fn(),
|
||||
User: jest.fn(),
|
||||
CollectionShared: jest.fn(),
|
||||
}));
|
||||
jest.mock("../rows/button-row", () => ({ ButtonRow: jest.fn() }));
|
||||
jest.mock("../signals/selected-folder", () => ({
|
||||
selectedFolder: { get: jest.fn(() => "0"), set: jest.fn() },
|
||||
}));
|
||||
jest.mock("../signals/selected-vault", () => ({
|
||||
selectedVault: { get: jest.fn(() => "0"), set: jest.fn() },
|
||||
}));
|
||||
jest.mock("../signals/selected-collection", () => ({
|
||||
selectedCollection: { get: jest.fn(() => "0"), set: jest.fn() },
|
||||
}));
|
||||
|
||||
describe("NotificationButtonRow", () => {
|
||||
const defaultProps = {
|
||||
i18n: mockI18n,
|
||||
primaryButton: {
|
||||
text: "Save",
|
||||
handlePrimaryButtonClick: jest.fn(),
|
||||
},
|
||||
personalVaultIsAllowed: true,
|
||||
theme: ThemeTypes.Light,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("folder options", () => {
|
||||
it("marks the No Folder option as default when its id is an empty string", () => {
|
||||
const folders = [
|
||||
{ id: "folder-uuid", name: "Alpha" },
|
||||
{ id: "", name: "No Folder" },
|
||||
];
|
||||
|
||||
NotificationButtonRow({ ...defaultProps, folders });
|
||||
|
||||
const { selectButtons } = (ButtonRow as jest.Mock).mock.calls[0][0];
|
||||
const folderSelectButton = selectButtons.find((b: any) => b.id === "folder");
|
||||
const noFolderOption = folderSelectButton.options.find((o: any) => o.text === "No Folder");
|
||||
|
||||
expect(noFolderOption.default).toBe(true);
|
||||
expect(noFolderOption.value).toBe("0");
|
||||
});
|
||||
|
||||
it("does not mark real folders as default", () => {
|
||||
const folders = [
|
||||
{ id: "folder-uuid", name: "Alpha" },
|
||||
{ id: "", name: "No Folder" },
|
||||
];
|
||||
|
||||
NotificationButtonRow({ ...defaultProps, folders });
|
||||
|
||||
const { selectButtons } = (ButtonRow as jest.Mock).mock.calls[0][0];
|
||||
const folderSelectButton = selectButtons.find((b: any) => b.id === "folder");
|
||||
const alphaOption = folderSelectButton.options.find((o: any) => o.text === "Alpha");
|
||||
|
||||
expect(alphaOption.default).toBe(false);
|
||||
expect(alphaOption.value).toBe("folder-uuid");
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -83,8 +83,8 @@ export function NotificationButtonRow({
|
||||
{
|
||||
icon: Folder,
|
||||
text: name,
|
||||
value: id === null ? defaultNoneSelectValue : id,
|
||||
default: id === null,
|
||||
value: !id ? defaultNoneSelectValue : id,
|
||||
default: !id,
|
||||
},
|
||||
],
|
||||
[],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user