Skip to content

Commit

Permalink
remarks + tsc fix
Browse files Browse the repository at this point in the history
  • Loading branch information
matborowczyk committed Nov 7, 2024
1 parent ce03415 commit ab9be97
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ test("if the fetched instance has inter-service relation(s) in the model, and th
);
const { result } = renderHook(
() =>
useGetInstanceWithRelations("child_id", "env", childModel).useOneTime(),
useGetInstanceWithRelations(
"child_id",
"env",
false,
childModel,
).useOneTime(),
{
wrapper: createWrapper(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { defineObjectsForJointJS } from "../testSetup";
import { ComposerEditorProvider } from "./ComposerEditorProvider";

const setup = (editable: boolean = false, instanceId: string) => {
const setup = (instanceId: string, editable: boolean = true) => {
const queryClient = new QueryClient({
defaultOptions: {
queries: {
Expand Down Expand Up @@ -126,7 +126,7 @@ describe("ComposerEditorProvider", () => {
}),
);

render(setup(true, "13920268-cce0-4491-93b5-11316aa2fc37"));
render(setup("13920268-cce0-4491-93b5-11316aa2fc37"));

expect(
await screen.findByRole("region", {
Expand All @@ -146,7 +146,7 @@ describe("ComposerEditorProvider", () => {
});

it("if there is error when fetching related inventories the error view is shown", async () => {
render(setup(true, "13920268-cce0-4491-93b5-11316aa2fc37"));
render(setup("13920268-cce0-4491-93b5-11316aa2fc37"));

server.use(
http.get("/lsm/v1/service_inventory/parent-service", async () => {
Expand Down Expand Up @@ -175,7 +175,7 @@ describe("ComposerEditorProvider", () => {
});

it("if there is error when fetching instance with relations the error view is shown", async () => {
render(setup(true, "13920268-cce0-4491-93b5-11316aa2fc37"));
render(setup("13920268-cce0-4491-93b5-11316aa2fc37"));

server.use(
http.get("/lsm/v1/service_inventory", async () => {
Expand Down Expand Up @@ -212,7 +212,7 @@ describe("ComposerEditorProvider", () => {
}),
);

render(setup(true, "13920268-cce0-4491-93b5-11316aa2fc37"));
render(setup("13920268-cce0-4491-93b5-11316aa2fc37"));

expect(
await screen.findByRole("region", {
Expand All @@ -236,22 +236,22 @@ describe("ComposerEditorProvider", () => {
});

it("if provider is editable show Instance Composer Editor title ", async () => {
render(setup(true, "13920268-cce0-4491-93b5-11316aa2fc37"));
render(setup("13920268-cce0-4491-93b5-11316aa2fc37"));

const title = await screen.findByText("Instance Composer Editor");

expect(title).toBeInTheDocument();
});
it("if provider is editable show Instance Composer Editor title ", async () => {
render(setup(false, "13920268-cce0-4491-93b5-11316aa2fc37"));
render(setup("13920268-cce0-4491-93b5-11316aa2fc37", false));

const title = await screen.findByText("Instance Composer Viewer");

expect(title).toBeInTheDocument();
});

it("navigating out of the View works correctly", async () => {
render(setup(true, "13920268-cce0-4491-93b5-11316aa2fc37"));
render(setup("13920268-cce0-4491-93b5-11316aa2fc37"));

expect(window.location.pathname).toEqual("/");

Expand Down
10 changes: 7 additions & 3 deletions src/UI/Components/Diagram/Context/ComposerEditorProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useContext, useEffect, useMemo, useState } from "react";
import { Flex, FlexItem } from "@patternfly/react-core";
import { ServiceModel } from "@/Core";
import { useGetAllServiceModels } from "@/Data/Managers/V2/GETTERS/GetAllServiceModels";
import { useGetInstanceWithRelations } from "@/Data/Managers/V2/GETTERS/GetInstanceWithRelations";
import { useGetInventoryList } from "@/Data/Managers/V2/GETTERS/GetInventoryList";
Expand Down Expand Up @@ -136,11 +135,16 @@ export const ComposerEditorProvider: React.FC<Props> = ({
return renderErrorView(message, ariaLabel, retry);
}

if (serviceModelsQuery.isSuccess && instanceWithRelationsQuery.isSuccess) {
if (
serviceModelsQuery.isSuccess &&
instanceWithRelationsQuery.isSuccess &&
mainService
) {
// there is no possibility to instanceWithRelationsQuery be in success state without mainService, and there is assertion above the if services are fetch but there is no mainService to display errorView
return (
<InstanceComposerContext.Provider
value={{
mainService: mainService as ServiceModel, // there is no possibility to instanceWithRelationsQuery be in success state without mainService, and there is assertion above the if services are fetch but there is no mainService to display errorView
mainService: mainService,
serviceModels: serviceModelsQuery.data,
instance: instanceWithRelationsQuery.data,
relatedInventoriesQuery: relatedInventoriesQuery,
Expand Down

0 comments on commit ab9be97

Please sign in to comment.