-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- add configuration dialog for tools in boards
- Loading branch information
1 parent
da6e4be
commit 0341a18
Showing
41 changed files
with
1,593 additions
and
359 deletions.
There are no files selected for viewing
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
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
31 changes: 31 additions & 0 deletions
31
src/components/data-external-tool/ContextExternalToolApi.composable.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 @@ | ||
import { | ||
ToolApiFactory, | ||
ToolApiInterface, | ||
ToolReferenceResponse, | ||
} from "@/serverApi/v3"; | ||
import { ExternalToolDisplayData } from "@/store/external-tool"; | ||
import { ExternalToolMapper } from "@/store/external-tool/mapper"; | ||
import { $axios } from "@/utils/api"; | ||
import { AxiosResponse } from "axios"; | ||
|
||
export const useContextExternalToolApi = () => { | ||
const toolApi: ToolApiInterface = ToolApiFactory(undefined, "/v3", $axios); | ||
|
||
const fetchDisplayDataCall = async ( | ||
contextExternalToolId: string | ||
): Promise<ExternalToolDisplayData> => { | ||
const response: AxiosResponse<ToolReferenceResponse> = | ||
await toolApi.toolReferenceControllerGetToolReference( | ||
contextExternalToolId | ||
); | ||
|
||
const mapped: ExternalToolDisplayData = | ||
ExternalToolMapper.mapToExternalToolDisplayData(response.data); | ||
|
||
return mapped; | ||
}; | ||
|
||
return { | ||
fetchDisplayDataCall, | ||
}; | ||
}; |
70 changes: 70 additions & 0 deletions
70
src/components/data-external-tool/ContextExternalToolApi.composable.unit.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,70 @@ | ||
import * as serverApi from "@/serverApi/v3/api"; | ||
import { ToolReferenceResponse } from "@/serverApi/v3/api"; | ||
import { | ||
ExternalToolDisplayData, | ||
ToolConfigurationStatus, | ||
} from "@/store/external-tool"; | ||
import { | ||
mockApiResponse, | ||
toolReferenceResponseFactory, | ||
} from "@@/tests/test-utils"; | ||
import { createMock, DeepMocked } from "@golevelup/ts-jest"; | ||
import { useContextExternalToolApi } from "./ContextExternalToolApi.composable"; | ||
|
||
describe("ContextExternalToolApi.composable", () => { | ||
let toolApi: DeepMocked<serverApi.ToolApiInterface>; | ||
|
||
beforeEach(() => { | ||
toolApi = createMock<serverApi.ToolApiInterface>(); | ||
|
||
jest.spyOn(serverApi, "ToolApiFactory").mockReturnValue(toolApi); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe("fetchDisplayDataCall", () => { | ||
const setup = () => { | ||
const displayData: ToolReferenceResponse = | ||
toolReferenceResponseFactory.build({ logoUrl: "mockLogoUrl" }); | ||
|
||
toolApi.toolReferenceControllerGetToolReference.mockResolvedValue( | ||
mockApiResponse({ data: displayData }) | ||
); | ||
|
||
return { | ||
displayData, | ||
}; | ||
}; | ||
|
||
it("should call the api for tool references", async () => { | ||
setup(); | ||
|
||
await useContextExternalToolApi().fetchDisplayDataCall( | ||
"contextExternalToolId" | ||
); | ||
|
||
expect( | ||
toolApi.toolReferenceControllerGetToolReference | ||
).toHaveBeenCalledWith("contextExternalToolId"); | ||
}); | ||
|
||
it("should return an array of display data", async () => { | ||
const { displayData } = setup(); | ||
|
||
const result: ExternalToolDisplayData = | ||
await useContextExternalToolApi().fetchDisplayDataCall( | ||
"contextExternalToolId" | ||
); | ||
|
||
expect(result).toEqual<ExternalToolDisplayData>({ | ||
contextExternalToolId: displayData.contextToolId, | ||
name: displayData.displayName, | ||
logoUrl: displayData.logoUrl, | ||
status: ToolConfigurationStatus.Latest, | ||
openInNewTab: displayData.openInNewTab, | ||
}); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/components/data-external-tool/ExternalToolElementDisplayState.composable.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 @@ | ||
import { ref, Ref } from "vue"; | ||
import { ExternalToolDisplayData } from "../../store/external-tool"; | ||
import { useErrorHandler } from "../error-handling/ErrorHandler.composable"; | ||
import { useContextExternalToolApi } from "./index"; | ||
|
||
export const useExternalToolElementDisplayState = () => { | ||
const { handleError } = useErrorHandler(); | ||
const { fetchDisplayDataCall } = useContextExternalToolApi(); | ||
const displayData: Ref<ExternalToolDisplayData | undefined> = ref(); | ||
const isLoading: Ref<boolean> = ref(false); | ||
|
||
const fetchDisplayData = async ( | ||
contextExternalToolId: string | ||
): Promise<void> => { | ||
isLoading.value = true; | ||
|
||
try { | ||
displayData.value = await fetchDisplayDataCall(contextExternalToolId); | ||
} catch (error) { | ||
handleError(error); | ||
} | ||
|
||
isLoading.value = false; | ||
}; | ||
|
||
return { | ||
isLoading, | ||
displayData, | ||
fetchDisplayData, | ||
}; | ||
}; |
96 changes: 96 additions & 0 deletions
96
src/components/data-external-tool/ExternalToolElementDisplayState.composable.unit.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,96 @@ | ||
import { ExternalToolDisplayData } from "@/store/external-tool"; | ||
import { externalToolDisplayDataFactory } from "@@/tests/test-utils"; | ||
import { createMock, DeepMocked } from "@golevelup/ts-jest"; | ||
import { useErrorHandler } from "../error-handling/ErrorHandler.composable"; | ||
import { useExternalToolElementDisplayState } from "./ExternalToolElementDisplayState.composable"; | ||
import { useContextExternalToolApi } from "./index"; | ||
|
||
jest.mock("@data-external-tool"); | ||
jest.mock("@/components/error-handling/ErrorHandler.composable"); | ||
|
||
describe("ExternalToolElementDisplayState.composable", () => { | ||
let useContextExternalToolApiMock: DeepMocked< | ||
ReturnType<typeof useContextExternalToolApi> | ||
>; | ||
let useErrorHandlerMock: DeepMocked<ReturnType<typeof useErrorHandler>>; | ||
|
||
beforeEach(() => { | ||
useContextExternalToolApiMock = | ||
createMock<ReturnType<typeof useContextExternalToolApi>>(); | ||
useErrorHandlerMock = createMock<ReturnType<typeof useErrorHandler>>(); | ||
|
||
jest | ||
.mocked(useContextExternalToolApi) | ||
.mockReturnValue(useContextExternalToolApiMock); | ||
jest.mocked(useErrorHandler).mockReturnValue(useErrorHandlerMock); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe("when no data is loaded", () => { | ||
it("should not have data", async () => { | ||
const { displayData } = useExternalToolElementDisplayState(); | ||
|
||
expect(displayData.value).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe("when data is loaded", () => { | ||
const setup = () => { | ||
const displayDataMock: ExternalToolDisplayData = | ||
externalToolDisplayDataFactory.build(); | ||
|
||
useContextExternalToolApiMock.fetchDisplayDataCall.mockResolvedValue( | ||
displayDataMock | ||
); | ||
|
||
return { | ||
displayDataMock, | ||
...useExternalToolElementDisplayState(), | ||
}; | ||
}; | ||
|
||
it("should call the api for display data of the card", async () => { | ||
const { fetchDisplayData } = setup(); | ||
|
||
await fetchDisplayData("contextId"); | ||
|
||
expect( | ||
useContextExternalToolApiMock.fetchDisplayDataCall | ||
).toHaveBeenCalledWith("contextId"); | ||
}); | ||
|
||
it("should set the display data in the state", async () => { | ||
const { fetchDisplayData, displayData, displayDataMock } = setup(); | ||
|
||
await fetchDisplayData("contextId"); | ||
|
||
expect(displayData.value).toEqual(displayDataMock); | ||
}); | ||
}); | ||
|
||
describe("when an error occurs during loading", () => { | ||
const setup = () => { | ||
const error = new Error("unable to load"); | ||
|
||
useContextExternalToolApiMock.fetchDisplayDataCall.mockRejectedValue( | ||
error | ||
); | ||
|
||
return { | ||
error, | ||
...useExternalToolElementDisplayState(), | ||
}; | ||
}; | ||
|
||
it("should handle the error", async () => { | ||
const { fetchDisplayData, error } = setup(); | ||
|
||
await fetchDisplayData("contextId"); | ||
|
||
expect(useErrorHandlerMock.handleError).toHaveBeenCalledWith(error); | ||
}); | ||
}); | ||
}); |
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,2 @@ | ||
export * from "./ContextExternalToolApi.composable"; | ||
export * from "./ExternalToolElementDisplayState.composable"; |
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
Oops, something went wrong.