portfolio/src/app/social/social.component.spec.ts
Naomi b909f4666c feat: modularise and expand job information, set up testing (#9)
Closes #6
Closes #7
Closes #8

Reviewed-on: https://codeberg.org/nhcarrigan/portfolio/pulls/9
Co-authored-by: Naomi <commits@nhcarrigan.com>
Co-committed-by: Naomi <commits@nhcarrigan.com>
2024-05-19 05:17:17 +00:00

50 lines
1.6 KiB
TypeScript

import { ComponentFixture, TestBed } from "@angular/core/testing";
import { Socials } from "../config/Socials";
import { SocialComponent } from "./social.component";
describe("SocialComponent", () => {
let component: SocialComponent;
let fixture: ComponentFixture<SocialComponent>;
let compiled: HTMLElement;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SocialComponent]
}).compileComponents();
fixture = TestBed.createComponent(SocialComponent);
component = fixture.componentInstance;
});
for (const expected of Socials) {
it(`should parse ${expected.label} properties correctly`, () => {
component.social = expected;
fixture.detectChanges();
expect(component.social).toBe(expected);
expect(component.link).toBe(expected.link);
expect(component.alt).toBe(expected.alt);
expect(component.icon).toEqual(expected.icon);
expect(component.label).toBe(expected.label);
});
it("should render an icon correctly", () => {
component.social = expected;
fixture.detectChanges();
compiled = fixture.nativeElement;
const link = compiled.querySelector("a");
expect(link?.href).toContain(expected.link);
expect(link?.rel).toBe("noopener noreferrer");
expect(link?.target).toBe("_blank");
expect(link?.ariaLabel).toBe(expected.label);
const icon = compiled.querySelector("fa-icon");
const svg = icon?.querySelector("svg");
const path = svg?.querySelector("path");
expect(path?.getAttribute("d")).toBe(expected.icon.icon[4] as string);
});
}
});