mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 17:23:37 +00:00
[EC-512] Tree shakeable icons (#3427)
* [EC-512] feat: create new icon class * [EC-512] feat: implement protected svgIcon function * [EC-512] feat: use new icon class in component * [EC-512] feat: integrate new icons in application * [EC-512] fix: linting * [EC-512] chore: move report icons to where they are used * [EC-512] chore: add export type explanation
This commit is contained in:
38
libs/components/src/icon/icon.spec.ts
Normal file
38
libs/components/src/icon/icon.spec.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import * as IconExports from "./icon";
|
||||
import { DynamicContentNotAllowedError, isIcon, svgIcon } from "./icon";
|
||||
|
||||
describe("Icon", () => {
|
||||
it("exports should not expose Icon class", () => {
|
||||
expect(Object.keys(IconExports)).not.toContain("Icon");
|
||||
});
|
||||
|
||||
describe("isIcon", () => {
|
||||
it("should return true when input is icon", () => {
|
||||
const result = isIcon(svgIcon`icon`);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false when input is not an icon", () => {
|
||||
const result = isIcon({ svg: "not an icon" });
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("template literal", () => {
|
||||
it("should throw when attempting to create dynamic icons", () => {
|
||||
const dynamic = "some user input";
|
||||
|
||||
const f = () => svgIcon`static and ${dynamic}`;
|
||||
|
||||
expect(f).toThrow(DynamicContentNotAllowedError);
|
||||
});
|
||||
|
||||
it("should return svg content when supplying icon with svg string", () => {
|
||||
const icon = svgIcon`safe static content`;
|
||||
|
||||
expect(icon.svg).toBe("safe static content");
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user