Skip to content

Commit 4eb996f

Browse files
vanessatran-ddiArakTaiRoth
authored andcommitted
fix(#2372): rename prefix GoA for FilterChip to goab
1 parent 240a3b1 commit 4eb996f

File tree

5 files changed

+139
-18
lines changed

5 files changed

+139
-18
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { ComponentFixture, TestBed } from "@angular/core/testing";
2+
import { Component, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
3+
import { GoabChipTheme, Spacing } from "@abgov/ui-components-common";
4+
import { By } from "@angular/platform-browser";
5+
import { fireEvent } from "@testing-library/dom";
6+
import { GoabFilterChip } from "./filter-chip";
7+
8+
@Component({
9+
template: `
10+
<goab-filter-chip
11+
[error]="error"
12+
[iconTheme]="iconTheme"
13+
[content]="content"
14+
[testId]="testId"
15+
[mt]="mt"
16+
[mb]="mb"
17+
[ml]="ml"
18+
[mr]="mr"
19+
(onClick)="onClick()"
20+
>
21+
</goab-filter-chip>
22+
`,
23+
})
24+
class TestFilterChipComponent {
25+
error?: boolean;
26+
content?: string;
27+
iconTheme?: GoabChipTheme;
28+
testId?: string;
29+
mt?: Spacing;
30+
mb?: Spacing;
31+
ml?: Spacing;
32+
mr?: Spacing;
33+
34+
onClick() {
35+
/* do nothing */
36+
}
37+
}
38+
39+
describe("GoabFilterChip", () => {
40+
let fixture: ComponentFixture<TestFilterChipComponent>;
41+
let component: TestFilterChipComponent;
42+
beforeEach(async () => {
43+
await TestBed.configureTestingModule({
44+
imports: [GoabFilterChip],
45+
declarations: [TestFilterChipComponent],
46+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
47+
}).compileComponents();
48+
49+
fixture = TestBed.createComponent(TestFilterChipComponent);
50+
component = fixture.componentInstance;
51+
52+
component.error = true;
53+
component.content = "some chip";
54+
component.testId = "chip-test";
55+
component.iconTheme = "filled";
56+
component.mt = "s";
57+
component.mr = "m";
58+
component.mb = "l";
59+
component.ml = "xl";
60+
fixture.detectChanges();
61+
});
62+
63+
it("should render properties", () => {
64+
const chipElement = fixture.debugElement.query(By.css("goa-filter-chip")).nativeElement;
65+
expect(chipElement.getAttribute("error")).toBe(`${component.error}`);
66+
expect(chipElement.getAttribute("content")).toBe(component.content);
67+
expect(chipElement.getAttribute("icontheme")).toBe(`${component.iconTheme}`);
68+
expect(chipElement.getAttribute("testid")).toBe(component.testId);
69+
expect(chipElement.getAttribute("mt")).toBe(component.mt);
70+
expect(chipElement.getAttribute("mr")).toBe(component.mr);
71+
expect(chipElement.getAttribute("mb")).toBe(component.mb);
72+
expect(chipElement.getAttribute("ml")).toBe(component.ml);
73+
});
74+
75+
it("should allow to handle delete event", async () => {
76+
const onClick = jest.spyOn(component, "onClick");
77+
const chipElement = fixture.debugElement.query(By.css("goa-filter-chip")).nativeElement;
78+
fireEvent(chipElement, new CustomEvent("_click"));
79+
80+
expect(onClick).toHaveBeenCalled();
81+
});
82+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { GoabChipTheme, Spacing } from "@abgov/ui-components-common";
2+
import { CUSTOM_ELEMENTS_SCHEMA, Component, Input, Output, EventEmitter } from "@angular/core";
3+
4+
@Component({
5+
standalone: true,
6+
selector: "goab-filter-chip",
7+
template: `<goa-filter-chip
8+
[attr.error]="error"
9+
[attr.icontheme]="iconTheme"
10+
[attr.content]="content"
11+
[attr.testid]="testId"
12+
[attr.mt]="mt"
13+
[attr.mb]="mb"
14+
[attr.ml]="ml"
15+
[attr.mr]="mr"
16+
(_click)="_onClick()"
17+
>
18+
<ng-content />
19+
</goa-filter-chip>`,
20+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
21+
})
22+
export class GoabFilterChip {
23+
@Input() error?: boolean;
24+
@Input() deletable?: boolean;
25+
@Input() content?: string = "";
26+
@Input() testId?: string;
27+
@Input() iconTheme?: GoabChipTheme;
28+
@Input() mt?: Spacing;
29+
@Input() mb?: Spacing;
30+
@Input() ml?: Spacing;
31+
@Input() mr?: Spacing;
32+
33+
@Output() onClick = new EventEmitter();
34+
35+
_onClick() {
36+
this.onClick.emit();
37+
}
38+
}

libs/angular-components/src/lib/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export * from "./dropdown/dropdown";
2020
export * from "./dropdown-item/dropdown-item";
2121
export * from "./file-upload-card/file-upload-card";
2222
export * from "./file-upload-input/file-upload-input";
23-
export * from "./footer/footer";
23+
export * from "./filter-chip/filter-chip";
2424
export * from "./footer/footer";
2525
export * from "./footer-meta-section/footer-meta-section";
2626
export * from "./footer-meta-section/footer-meta-section";

libs/react-components/src/lib/filter-chip/filter-chip.spec.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { fireEvent, render, screen } from "@testing-library/react";
1+
import { fireEvent, render } from "@testing-library/react";
22
import "@testing-library/jest-dom";
3-
import { GoAFilterChip } from "./filter-chip";
3+
import { GoabFilterChip } from "./filter-chip";
44
import { describe, it, expect, vi } from "vitest";
55

66
describe("GoA FilterChip", () => {
77
it("should render", () => {
8-
const { container } = render(<GoAFilterChip content="some filter chip" />);
8+
const { container } = render(<GoabFilterChip content="some filter chip" />);
99
expect(container.innerHTML).toContain("some filter chip");
1010
});
1111

1212
it("should render with basic props", () => {
13-
const { container } = render(<GoAFilterChip content="Some Badge" />);
13+
const { container } = render(<GoabFilterChip content="Some Badge" />);
1414
expect(container.innerHTML).toContain("Some Badge");
1515
const el = container.querySelector("goa-filter-chip");
1616
expect(el).not.toBeNull();
@@ -19,7 +19,7 @@ describe("GoA FilterChip", () => {
1919

2020
it("should bind all properties correctly", async () => {
2121
const { container } = render(
22-
<GoAFilterChip
22+
<GoabFilterChip
2323
content="some filter chip"
2424
mt="s"
2525
mr="m"
@@ -40,19 +40,19 @@ describe("GoA FilterChip", () => {
4040
expect(el?.getAttribute("ml")).toBe("xl");
4141
expect(el?.getAttribute("error")).toBe("true");
4242
expect(el?.getAttribute("icontheme")).toBe("filled");
43-
expect(el?.getAttribute("data-testid")).toBe("test-chip");
43+
expect(el?.getAttribute("testid")).toBe("test-chip");
4444
});
4545

4646
it("should show the chip in the error state", () => {
47-
const { container } = render(<GoAFilterChip content="Some Badge" error={true} />);
47+
const { container } = render(<GoabFilterChip content="Some Badge" error={true} />);
4848
const el = container.querySelector("goa-filter-chip");
4949
expect(el?.getAttribute("error")).toBe("true");
5050
});
5151

5252
it("should handle the click event", async () => {
5353
const onClick = vi.fn();
5454
const { container } = render(
55-
<GoAFilterChip content="Some Badge" onClick={onClick} testId="chip" />,
55+
<GoabFilterChip content="Some Badge" onClick={onClick} testId="chip" />,
5656
);
5757
const el = container.querySelector("goa-filter-chip");
5858

@@ -61,15 +61,15 @@ describe("GoA FilterChip", () => {
6161
});
6262

6363
it("should have an unfilled close icon by default", () => {
64-
const { container } = render(<GoAFilterChip content="Test" />);
64+
const { container } = render(<GoabFilterChip content="Test" />);
6565
const el = container.querySelector("goa-filter-chip");
6666
expect(el?.getAttribute("icontheme")).toBe("outline");
6767
});
6868

6969
it("should not apply background fill on hover", async () => {
70-
render(<GoAFilterChip content="Test" testId="chip" />);
71-
const chip = await screen.findByTestId("chip");
72-
fireEvent.mouseOver(chip);
70+
const { container } = render(<GoabFilterChip content="Test" testId="chip" />);
71+
const chip = container.querySelector("goa-filter-chip");
72+
fireEvent.mouseOver(chip!);
7373
expect(chip).not.toHaveStyle("background-color: var(--goa-color-greyscale-200)");
7474
});
7575
});

libs/react-components/src/lib/filter-chip/filter-chip.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface WCProps extends Margins {
66
icontheme: GoabFilterChipTheme;
77
error: boolean;
88
content: string;
9+
testid?: string;
910
}
1011

1112
declare global {
@@ -17,15 +18,15 @@ declare global {
1718
}
1819
}
1920

20-
export interface GoAFilterChipProps extends Margins {
21+
export interface GoabFilterChipProps extends Margins {
2122
onClick?: () => void;
2223
iconTheme?: GoabFilterChipTheme;
2324
error?: boolean;
2425
content: string;
2526
testId?: string;
2627
}
2728

28-
export const GoAFilterChip = ({
29+
export const GoabFilterChip = ({
2930
iconTheme = "outline",
3031
error = false,
3132
content,
@@ -35,7 +36,7 @@ export const GoAFilterChip = ({
3536
mb,
3637
ml,
3738
testId,
38-
}: GoAFilterChipProps) => {
39+
}: GoabFilterChipProps) => {
3940
const el = useRef<HTMLElement>(null);
4041
useEffect(() => {
4142
if (!el.current) return;
@@ -59,9 +60,9 @@ export const GoAFilterChip = ({
5960
mr={mr}
6061
mb={mb}
6162
ml={ml}
62-
data-testid={testId}
63+
testid={testId}
6364
/>
6465
);
6566
};
6667

67-
export default GoAFilterChip;
68+
export default GoabFilterChip;

0 commit comments

Comments
 (0)