forked from springwolf/springwolf-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test coverage for UI components (springwolf#692)
* chore: build website preview when asyncapi.json changes * chore: build website preview when asyncapi.json changes * chore: build website preview when asyncapi.json changes * chore: build website preview when asyncapi.json changes * refactor(schema): correct margin and padding values Warnings are present Refs springwolf#378 * test(ui): cover schema-range component 0 coverage Refs springwolf#378 * refactor(ui): simplify schema range rendering Is difficult to maintain Refs springwolf#378 * test(ui): cover info component Refs springwolf#378 * test(ui): cover all components Are absent Refs springwolf#378 * test(ui): fix invalid declaration error Material components are mentioned in the wrong section Refs springwolf#378 --------- Co-authored-by: Timon Back <timonback@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
springwolf-ui/src/app/components/channels/channel-main/channel-main.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* 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<ChannelMainComponent>; | ||
|
||
let mockedAsyncApiService = { | ||
getAsyncApi: jest.fn(), | ||
}; | ||
let mockedPublisherService = { | ||
getAsyncApi: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
MatDivider, | ||
MatTabGroup, | ||
MatTab, | ||
MatTabHeader, | ||
MarkdownModule.forRoot(), | ||
], | ||
declarations: [ChannelMainComponent, JsonComponent], | ||
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(); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
springwolf-ui/src/app/components/channels/channels.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* 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<ChannelsComponent>; | ||
|
||
let mockedAsyncApiService = { | ||
getAsyncApi: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MatAccordion], | ||
declarations: [ChannelsComponent], | ||
providers: [ | ||
{ provide: AsyncApiService, useValue: mockedAsyncApiService }, | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ChannelsComponent as any); | ||
component = fixture.debugElement.componentInstance; | ||
}); | ||
|
||
it("should create the component", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
springwolf-ui/src/app/components/header/header.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HeaderComponent>; | ||
|
||
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(); | ||
}); | ||
}); |
74 changes: 74 additions & 0 deletions
74
springwolf-ui/src/app/components/info/info.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* 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"; | ||
|
||
describe("InfoComponent", function () { | ||
let component: InfoComponent; | ||
let fixture: ComponentFixture<InfoComponent>; | ||
|
||
let mockedAsyncApiService!: { getAsyncApi: jest.Mock }; | ||
|
||
let info = { | ||
title: "title", | ||
version: "1.0.0", | ||
description: "example", | ||
contact: { | ||
url: "https://test.com", | ||
email: { | ||
name: "springwolf", | ||
href: "link", | ||
}, | ||
}, | ||
license: { | ||
name: "Apache License 2.0", | ||
}, | ||
asyncApiJson: null, | ||
}; | ||
|
||
beforeEach(() => { | ||
mockedAsyncApiService = { | ||
getAsyncApi: jest.fn(), | ||
}; | ||
|
||
TestBed.configureTestingModule({ | ||
declarations: [InfoComponent], | ||
imports: [MatChipsModule, MarkdownModule.forRoot()], | ||
providers: [ | ||
{ provide: AsyncApiService, useValue: mockedAsyncApiService }, | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(InfoComponent as any); | ||
component = fixture.debugElement.componentInstance; | ||
component.info = info; | ||
}); | ||
|
||
it("should create the component", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it("should render the title", async () => { | ||
mockedAsyncApiService.getAsyncApi.mockReturnValue(of()); | ||
|
||
fixture.detectChanges(); | ||
const compiled = fixture.debugElement.nativeElement; | ||
expect(compiled.querySelector("h1").textContent).toContain("title"); | ||
expect(compiled.querySelector("h5").textContent).toContain( | ||
" API version 1.0.0 - Download AsyncAPI file" | ||
); | ||
}); | ||
|
||
it("should render the license information", async () => { | ||
mockedAsyncApiService.getAsyncApi.mockReturnValue(of()); | ||
|
||
fixture.detectChanges(); | ||
const compiled = fixture.debugElement.nativeElement; | ||
expect(compiled.querySelector("p").textContent).toContain( | ||
"License: Apache License 2.0 https://test.com springwolf " | ||
); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
springwolf-ui/src/app/components/schemas/schema/schema.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* 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"; | ||
import { JsonComponent } from "../../json/json.component"; | ||
|
||
describe("SchemaComponent", () => { | ||
let component: SchemaComponent; | ||
let fixture: ComponentFixture<SchemaComponent>; | ||
|
||
let mockedSchemaRangeComponent = jest.mock("../range/schema-range.component"); | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [SchemaComponent, SchemaRangeComponent, JsonComponent], | ||
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" | ||
); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
springwolf-ui/src/app/components/schemas/schemas.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* 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<SchemasComponent>; | ||
|
||
let mockedAsyncApiService = { | ||
getAsyncApi: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MatAccordion], | ||
declarations: [SchemasComponent], | ||
providers: [ | ||
{ provide: AsyncApiService, useValue: mockedAsyncApiService }, | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(SchemasComponent as any); | ||
component = fixture.debugElement.componentInstance; | ||
}); | ||
|
||
it("should create the component", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
springwolf-ui/src/app/components/servers/servers.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ServersComponent>; | ||
|
||
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(); | ||
}); | ||
}); |