Skip to content

Commit

Permalink
test: add basic tests on the data displayed in the component
Browse files Browse the repository at this point in the history
  • Loading branch information
timonback committed May 3, 2024
1 parent 4a1c3ea commit 4699705
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,16 @@ import { ChannelMainComponent } from "./channel-main.component";
import { AsyncApiService } from "../../../service/asyncapi/asyncapi.service";
import { PublisherService } from "../../../service/publisher.service";
import { MaterialModule } from "../../../material.module";
import { of } from "rxjs";
import { exampleSchemas } from "../../../service/mock/example-data";
import { AsyncApiMapperService } from "../../../service/asyncapi/asyncapi-mapper.service";
import { MarkdownModule } from "ngx-markdown";
import {
mockedAsyncApiService,
mockedExampleSchemaMapped,
} from "../../../service/mock/mock-asyncapi.service";
import { Component, Input } from "@angular/core";
import { Schema } from "../../../models/schema.model";

@Component({ selector: "app-json", template: "" })
export class MockAppJson {
@Input() data: any;
}

@Component({ selector: "app-schema", template: "" })
export class MockAppSchema {
@Input() schema: Schema;
}
import { MockAppJson, MockAppSchema } from "../../mock-components.spec";

describe("ChannelMainComponent", () => {
const mockData = mockedExampleSchemaMapped.channelOperations[0];

beforeEach(async () => {
mockedAsyncApiService.getAsyncApi.mockClear();

Expand All @@ -37,13 +25,15 @@ describe("ChannelMainComponent", () => {
{ provide: PublisherService, useValue: {} },
],
componentProperties: {
channelName: mockedExampleSchemaMapped.channelOperations[0].name,
operation: mockedExampleSchemaMapped.channelOperations[0].operation,
channelName: mockData.name,
operation: mockData.operation,
},
});
});

it("should create the component", () => {
expect(screen.getByText("Another payload model")).toBeTruthy();
it("should render the component and data", () => {
expect(
screen.getByText(mockData.operation.message.description)
).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
import { render, screen } from "@testing-library/angular";
import { ChannelsComponent } from "./channels.component";
import { AsyncApiService } from "../../service/asyncapi/asyncapi.service";
import { MatAccordion } from "@angular/material/expansion";
import { mockedAsyncApiService } from "../../service/mock/mock-asyncapi.service";
import {
mockedAsyncApiService,
mockedExampleSchemaMapped,
} from "../../service/mock/mock-asyncapi.service";
import { MaterialModule } from "../../material.module";
import { Operation } from "../../models/operation.model";
import { Component, Input } from "@angular/core";

@Component({
selector: "app-channel-main",
template: "",
})
export class MockChannelMainComponent {
@Input() channelName: string;
@Input() operation: Operation;
}
import { MockChannelMainComponent } from "../mock-components.spec";

describe("ChannelsComponent", () => {
beforeEach(async () => {
Expand All @@ -30,7 +22,14 @@ describe("ChannelsComponent", () => {
});
});

it("should create the component", () => {
it("should render the component and data", () => {
expect(screen.getByText("Channels")).toBeTruthy();

mockedExampleSchemaMapped.channelOperations.forEach((channelOperation) => {
expect(screen.getAllByText(channelOperation.name)[0]).toBeTruthy();
expect(
screen.getAllByText(channelOperation.operation.message.title)[0]
).toBeTruthy();
});
});
});
29 changes: 29 additions & 0 deletions springwolf-ui/src/app/components/mock-components.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: Apache-2.0 */
import { Component, Input } from "@angular/core";
import { Schema } from "../models/schema.model";
import { Operation } from "../models/operation.model";

/*
* This file contains all mock components for usage in tests.
*/
describe("MockTest", () => {
it("basic test, since at least one test is required 1 + 1 = 2", () => {
expect(1 + 1).toBe(2);
});
});

@Component({ selector: "app-json", template: "" })
export class MockAppJson {
@Input() data: any;
}

@Component({ selector: "app-schema", template: "" })
export class MockAppSchema {
@Input() schema: Schema;
}

@Component({ selector: "app-channel-main", template: "" })
export class MockChannelMainComponent {
@Input() channelName: string;
@Input() operation: Operation;
}
13 changes: 11 additions & 2 deletions springwolf-ui/src/app/components/servers/servers.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import { render, screen } from "@testing-library/angular";
import { ServersComponent } from "./servers.component";
import { AsyncApiService } from "../../service/asyncapi/asyncapi.service";
import { mockedAsyncApiService } from "../../service/mock/mock-asyncapi.service";
import {
mockedAsyncApiService,
mockedExampleSchemaMapped,
} from "../../service/mock/mock-asyncapi.service";
import { MaterialModule } from "../../material.module";

describe("ServerComponent", () => {
Expand All @@ -17,7 +20,13 @@ describe("ServerComponent", () => {
});
});

it("should create the component", () => {
it("should render the component and data", () => {
expect(screen.getByText("Servers")).toBeTruthy();

mockedExampleSchemaMapped.servers.forEach((server, key) => {
expect(screen.getAllByText(key)[0]).toBeTruthy();
expect(screen.getAllByText(server.protocol)[0]).toBeTruthy();
expect(screen.getAllByText(server.host)[0]).toBeTruthy();
});
});
});

0 comments on commit 4699705

Please sign in to comment.