From 54b799e58d8210c59a3656e9157ce95865750656 Mon Sep 17 00:00:00 2001 From: Nikita Marunko Date: Wed, 27 Mar 2024 22:52:37 +0900 Subject: [PATCH] test(ui): cover all components Are absent Refs #378 --- .../channel-main.component.spec.ts | 46 ++++++++++++++++++ .../channels/channels.component.spec.ts | 30 ++++++++++++ .../header/header.component.spec.ts | 23 +++++++++ .../components/info/info.component.spec.ts | 28 +++++------ .../schemas/schema/schema.component.spec.ts | 47 +++++++++++++++++++ .../schemas/schemas.component.spec.ts | 30 ++++++++++++ .../servers/servers.component.spec.ts | 27 +++++++++++ 7 files changed, 215 insertions(+), 16 deletions(-) create mode 100644 springwolf-ui/src/app/components/channels/channel-main/channel-main.component.spec.ts create mode 100644 springwolf-ui/src/app/components/channels/channels.component.spec.ts create mode 100644 springwolf-ui/src/app/components/header/header.component.spec.ts create mode 100644 springwolf-ui/src/app/components/schemas/schema/schema.component.spec.ts create mode 100644 springwolf-ui/src/app/components/schemas/schemas.component.spec.ts create mode 100644 springwolf-ui/src/app/components/servers/servers.component.spec.ts diff --git a/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.spec.ts b/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.spec.ts new file mode 100644 index 000000000..45ddb6fd0 --- /dev/null +++ b/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.spec.ts @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +import { AsyncApiService } from "../../../service/asyncapi/asyncapi.service"; +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { ChannelMainComponent } from "./channel-main.component"; +import { PublisherService } from "../../../service/publisher.service"; +import { MatDivider } from "@angular/material/divider"; +import { MatTab, MatTabGroup, MatTabHeader } from "@angular/material/tabs"; +import { JsonComponent } from "../../json/json.component"; +import { MarkdownModule } from "ngx-markdown"; + +describe("ChannelMainComponent", () => { + let component: ChannelMainComponent; + let fixture: ComponentFixture; + + let mockedAsyncApiService = { + getAsyncApi: jest.fn(), + }; + let mockedPublisherService = { + getAsyncApi: jest.fn(), + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + ChannelMainComponent, + JsonComponent, + MatDivider, + MatTabGroup, + MatTab, + MatTabHeader, + ], + imports: [MarkdownModule.forRoot()], + providers: [ + { provide: AsyncApiService, useValue: mockedAsyncApiService }, + { provide: PublisherService, useValue: mockedPublisherService }, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(ChannelMainComponent as any); + component = fixture.debugElement.componentInstance; + }); + + it("should create the component", () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/springwolf-ui/src/app/components/channels/channels.component.spec.ts b/springwolf-ui/src/app/components/channels/channels.component.spec.ts new file mode 100644 index 000000000..0f6e97dd3 --- /dev/null +++ b/springwolf-ui/src/app/components/channels/channels.component.spec.ts @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +import { AsyncApiService } from "../../service/asyncapi/asyncapi.service"; +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { ChannelsComponent } from "./channels.component"; +import { MatAccordion } from "@angular/material/expansion"; + +describe("ChannelsComponent", () => { + let component: ChannelsComponent; + let fixture: ComponentFixture; + + let mockedAsyncApiService = { + getAsyncApi: jest.fn(), + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ChannelsComponent, MatAccordion], + providers: [ + { provide: AsyncApiService, useValue: mockedAsyncApiService }, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(ChannelsComponent as any); + component = fixture.debugElement.componentInstance; + }); + + it("should create the component", () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/springwolf-ui/src/app/components/header/header.component.spec.ts b/springwolf-ui/src/app/components/header/header.component.spec.ts new file mode 100644 index 000000000..a75b85ebb --- /dev/null +++ b/springwolf-ui/src/app/components/header/header.component.spec.ts @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +import { MatToolbarModule } from "@angular/material/toolbar"; +import { HeaderComponent } from "./header.component"; +import { ComponentFixture, TestBed } from "@angular/core/testing"; + +describe("HeaderComponent", () => { + let component: HeaderComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [HeaderComponent], + imports: [MatToolbarModule], + }).compileComponents(); + + fixture = TestBed.createComponent(HeaderComponent as any); + component = fixture.debugElement.componentInstance; + }); + + it("should create the component", () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/springwolf-ui/src/app/components/info/info.component.spec.ts b/springwolf-ui/src/app/components/info/info.component.spec.ts index f3f6ac1e5..7a50dd59e 100644 --- a/springwolf-ui/src/app/components/info/info.component.spec.ts +++ b/springwolf-ui/src/app/components/info/info.component.spec.ts @@ -1,10 +1,10 @@ /* SPDX-License-Identifier: Apache-2.0 */ -import {ComponentFixture, TestBed} from "@angular/core/testing"; -import {InfoComponent} from "./info.component"; -import {AsyncApiService} from "../../service/asyncapi/asyncapi.service"; -import {of} from "rxjs/internal/observable/of"; -import {MatChipsModule} from "@angular/material/chips"; -import {MarkdownModule} from "ngx-markdown"; +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { InfoComponent } from "./info.component"; +import { AsyncApiService } from "../../service/asyncapi/asyncapi.service"; +import { of } from "rxjs/internal/observable/of"; +import { MatChipsModule } from "@angular/material/chips"; +import { MarkdownModule } from "ngx-markdown"; describe("InfoComponent", function () { let component: InfoComponent; @@ -20,14 +20,14 @@ describe("InfoComponent", function () { url: "https://test.com", email: { name: "springwolf", - href: "link" - } + href: "link", + }, }, license: { - name: "Apache License 2.0" + name: "Apache License 2.0", }, asyncApiJson: null, - } + }; beforeEach(() => { mockedAsyncApiService = { @@ -38,7 +38,7 @@ describe("InfoComponent", function () { declarations: [InfoComponent], imports: [MatChipsModule, MarkdownModule.forRoot()], providers: [ - {provide: AsyncApiService, useValue: mockedAsyncApiService}, + { provide: AsyncApiService, useValue: mockedAsyncApiService }, ], }).compileComponents(); @@ -56,9 +56,7 @@ describe("InfoComponent", function () { fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; - expect(compiled.querySelector("h1").textContent).toContain( - "title" - ); + expect(compiled.querySelector("h1").textContent).toContain("title"); expect(compiled.querySelector("h5").textContent).toContain( " API version 1.0.0 - Download AsyncAPI file" ); @@ -73,6 +71,4 @@ describe("InfoComponent", function () { "License: Apache License 2.0 https://test.com springwolf " ); }); - }); - diff --git a/springwolf-ui/src/app/components/schemas/schema/schema.component.spec.ts b/springwolf-ui/src/app/components/schemas/schema/schema.component.spec.ts new file mode 100644 index 000000000..b1ec7572b --- /dev/null +++ b/springwolf-ui/src/app/components/schemas/schema/schema.component.spec.ts @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +import { ComponentFixture, TestBed } from "@angular/core/testing"; + +import { SchemaComponent } from "./schema.component"; +import { SchemaRangeComponent } from "../range/schema-range.component"; +import { MatChipsModule } from "@angular/material/chips"; +import { MarkdownModule } from "ngx-markdown"; +import { Example } from "../../../models/example.model"; + +describe("SchemaComponent", () => { + let component: SchemaComponent; + let fixture: ComponentFixture; + + let mockedSchemaRangeComponent = jest.mock("../range/schema-range.component"); + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [SchemaComponent, SchemaRangeComponent], + imports: [MatChipsModule, MarkdownModule.forRoot()], + providers: [ + { provide: SchemaRangeComponent, useValue: mockedSchemaRangeComponent }, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(SchemaComponent as any); + component = fixture.debugElement.componentInstance; + }); + + it("should create the component", () => { + expect(component).toBeTruthy(); + }); + + it("should render primitive string", async () => { + component.schema = { + title: "String", + type: "string", + example: new Example("string"), + }; + + fixture.detectChanges(); + const compiled = fixture.debugElement.nativeElement; + expect(compiled.querySelector(".type").textContent).toContain("string"); + expect(compiled.querySelector(".example").textContent).toContain( + "example: string" + ); + }); +}); diff --git a/springwolf-ui/src/app/components/schemas/schemas.component.spec.ts b/springwolf-ui/src/app/components/schemas/schemas.component.spec.ts new file mode 100644 index 000000000..c54c42d7e --- /dev/null +++ b/springwolf-ui/src/app/components/schemas/schemas.component.spec.ts @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { SchemasComponent } from "./schemas.component"; +import { AsyncApiService } from "../../service/asyncapi/asyncapi.service"; +import { MatAccordion } from "@angular/material/expansion"; + +describe("SchemasComponent", () => { + let component: SchemasComponent; + let fixture: ComponentFixture; + + let mockedAsyncApiService = { + getAsyncApi: jest.fn(), + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [SchemasComponent, MatAccordion], + providers: [ + { provide: AsyncApiService, useValue: mockedAsyncApiService }, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(SchemasComponent as any); + component = fixture.debugElement.componentInstance; + }); + + it("should create the component", () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/springwolf-ui/src/app/components/servers/servers.component.spec.ts b/springwolf-ui/src/app/components/servers/servers.component.spec.ts new file mode 100644 index 000000000..e40a5eb36 --- /dev/null +++ b/springwolf-ui/src/app/components/servers/servers.component.spec.ts @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { ServersComponent } from "./servers.component"; +import { AsyncApiService } from "../../service/asyncapi/asyncapi.service"; + +describe("ServerComponent", () => { + let component: ServersComponent; + let fixture: ComponentFixture; + + let mockedAsyncApiService!: { getAsyncApi: jest.Mock }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ServersComponent], + providers: [ + { provide: AsyncApiService, useValue: mockedAsyncApiService }, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(ServersComponent as any); + component = fixture.debugElement.componentInstance; + }); + + it("should create the component", () => { + expect(component).toBeTruthy(); + }); +});