Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { ComponentFixture, TestBed, fakeAsync, tick } from "@angular/core/testing";
import { GoabDataGrid } from "./data-grid";
import { Component, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import { By } from "@angular/platform-browser";

@Component({
template: `
<goab-data-grid [keyboardIcon]="keyboardIcon" [keyboardNav]="keyboardNav">
<div>Test content</div>
</goab-data-grid>
`
})
class TestDataGridComponent {
keyboardIcon = true;
keyboardNav: "layout" | "table" = "table";
}

describe("GoabDataGrid", () => {
let fixture: ComponentFixture<TestDataGridComponent>;
let component: TestDataGridComponent;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [GoabDataGrid],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [TestDataGridComponent]
}).compileComponents();

fixture = TestBed.createComponent(TestDataGridComponent);
component = fixture.componentInstance;
});

it("should create component and render goa-data-grid with projected content", fakeAsync(() => {
fixture.detectChanges();
tick();
fixture.detectChanges();

expect(component).toBeTruthy();

const dataGridElement = fixture.debugElement.query(By.css("goa-data-grid"))?.nativeElement;
expect(dataGridElement).toBeTruthy();
expect(dataGridElement.textContent).toContain("Test content");
expect(dataGridElement.hasAttribute("keyboard-icon")).toBe(true);
expect(dataGridElement.getAttribute("keyboard-icon")).toBe("");
}));

it("should remove keyboard-icon attribute when set to false", fakeAsync(() => {
component.keyboardIcon = false;
fixture.detectChanges();
tick();
fixture.detectChanges();

const dataGridElement = fixture.debugElement.query(By.css("goa-data-grid"))?.nativeElement;
expect(dataGridElement).toBeTruthy();
expect(dataGridElement.hasAttribute("keyboard-icon")).toBe(false);
expect(dataGridElement.getAttribute("keyboard-icon")).toBeNull();
}));

it("should set keyboardNav to table mode", fakeAsync(() => {
component.keyboardNav = "table";
fixture.detectChanges();
tick();
fixture.detectChanges();

const dataGridElement = fixture.debugElement.query(By.css("goa-data-grid"))?.nativeElement;
expect(dataGridElement).toBeTruthy();
expect(dataGridElement.getAttribute("keyboard-nav")).toBe("table");
}));

it("should set keyboardNav to layout mode", fakeAsync(() => {
component.keyboardNav = "layout";
fixture.detectChanges();
tick();
fixture.detectChanges();

const dataGridElement = fixture.debugElement.query(By.css("goa-data-grid"))?.nativeElement;
expect(dataGridElement).toBeTruthy();
expect(dataGridElement.getAttribute("keyboard-nav")).toBe("layout");
}));
});
35 changes: 35 additions & 0 deletions libs/angular-components/src/lib/components/data-grid/data-grid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { CUSTOM_ELEMENTS_SCHEMA, Component, Input, booleanAttribute, ChangeDetectorRef, OnInit } from "@angular/core";
import { CommonModule } from "@angular/common";

@Component({
standalone: true,
selector: "goab-data-grid",
imports: [CommonModule],
template: `
<goa-data-grid
*ngIf="isReady"
[attr.keyboard-icon]="keyboardIcon ? '' : null"
[attr.keyboard-nav]="keyboardNav"
>
<ng-content></ng-content>
</goa-data-grid>
`,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class GoabDataGrid implements OnInit {
@Input({ transform: booleanAttribute }) keyboardIcon = true;
@Input({ required: true }) keyboardNav!: "layout" | "table";

isReady = false;

constructor(private cdr: ChangeDetectorRef) {}

ngOnInit(): void {
// For Angular, we need to delay rendering the web component
// to ensure all attributes are properly bound before the component initializes
setTimeout(() => {
this.isReady = true;
this.cdr.detectChanges();
}, 0);
}
}
1 change: 1 addition & 0 deletions libs/angular-components/src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from "./chip/chip";
export * from "./circular-progress/circular-progress";
export * from "./column-layout/column-layout";
export * from "./container/container";
export * from "./data-grid/data-grid";
export * from "./date-picker/date-picker";
export * from "./details/details";
export * from "./divider/divider";
Expand Down
Loading