diff --git a/src/Components/CoreTest/Application/UseCases/Adaptivity/DisplayLearningElementUseCase/DisplayLearningElementUseCase.test.ts b/src/Components/CoreTest/Application/UseCases/Adaptivity/DisplayLearningElementUseCase/DisplayLearningElementUseCase.test.ts index 0fecf9f89..48780ceac 100644 --- a/src/Components/CoreTest/Application/UseCases/Adaptivity/DisplayLearningElementUseCase/DisplayLearningElementUseCase.test.ts +++ b/src/Components/CoreTest/Application/UseCases/Adaptivity/DisplayLearningElementUseCase/DisplayLearningElementUseCase.test.ts @@ -1,5 +1,5 @@ import { async } from "q"; -import DisplayLearningElementUseCase from "../../../../../Core/Application/UseCases/Adaptivity/DisplayLearningElementUseCase/DisplayLearningElementUseCase"; +import DisplayLearningElementUseCase from "../../../../../Core/Application/UseCases/Adaptivity/DisplayAdaptivityHintLearningElement/DisplayAdaptivityHintLearningElementUseCase"; import CoreDIContainer from "../../../../../Core/DependencyInjection/CoreDIContainer"; import mock from "jest-mock-extended/lib/Mock"; import CORE_TYPES from "../../../../../Core/DependencyInjection/CoreTypes"; @@ -16,6 +16,7 @@ import { AdaptivityElementActionTypes } from "../../../../../Core/Domain/Types/A import ICalculateLearningSpaceAvailabilityUseCase from "../../../../../Core/Application/UseCases/CalculateLearningSpaceAvailability/ICalculateLearningSpaceAvailabilityUseCase"; import LearningSpaceAvailabilityTO from "../../../../../Core/Application/DataTransferObjects/LearningSpaceAvailabilityTO"; import ILoadLearningElementUseCase from "../../../../../Core/Application/UseCases/LoadLearningElement/ILoadLearningElementUseCase"; +import { LearningElementModelTypeEnums } from "../../../../../Core/Domain/LearningElementModels/LearningElementModelTypes"; const entityContainer = mock(); const getUserLocationUseCaseMock = mock(); @@ -59,67 +60,95 @@ describe("DisplayLearningElementUseCase", () => { systemUnderTest = CoreDIContainer.resolve(DisplayLearningElementUseCase); }); - test("should throw, if no space space is found", async () => { - entityContainer.getEntitiesOfType.mockReturnValue([]); + test("should throw, if user is not in space", async () => { + getUserLocationUseCaseMock.execute.mockReturnValue({ + worldID: undefined, + spaceID: undefined, + } as UserLocationTO); await expect(systemUnderTest.executeAsync(1)).rejects.toThrow( - `Could not find space in which external learning element is.` + `User not in a space!` ); - }); - test("should throw, if no element is found", async () => { - entityContainer.getEntitiesOfType.mockReturnValue([ - { id: 0, elements: [{ id: 1 }] } as LearningSpaceEntity, - ]); - entityContainer.filterEntitiesOfType.mockReturnValue([]); + getUserLocationUseCaseMock.execute.mockReturnValue({ + worldID: 1, + spaceID: undefined, + } as UserLocationTO); await expect(systemUnderTest.executeAsync(1)).rejects.toThrow( - "Could not find external element." + `User not in a space!` ); - }); - - test("should throw, if user is not in space", async () => { - entityContainer.getEntitiesOfType.mockReturnValue([ - { id: 0, elements: [{ id: 1 }] } as LearningSpaceEntity, - ]); - - entityContainer.filterEntitiesOfType.mockReturnValue([ - { id: 3 } as LearningElementEntity, - ]); getUserLocationUseCaseMock.execute.mockReturnValue({ worldID: undefined, - spaceID: undefined, + spaceID: 1, } as UserLocationTO); await expect(systemUnderTest.executeAsync(1)).rejects.toThrow( `User not in a space!` ); + }); + test("should throw, if no space space is found", async () => { getUserLocationUseCaseMock.execute.mockReturnValue({ worldID: 1, - spaceID: undefined, + spaceID: 1, } as UserLocationTO); + entityContainer.filterEntitiesOfType.mockReturnValue([]); + await expect(systemUnderTest.executeAsync(1)).rejects.toThrow( - `User not in a space!` + `Could not find space for currently active learning world.` ); }); - test("learning element in same space calls onAdaptivityElementUserHintInformed", async () => { - entityContainer.getEntitiesOfType.mockReturnValue([ - { id: 1, elements: [{ id: 1 }] } as LearningSpaceEntity, - ]); + test("should throw, if no element is found", async () => { + getUserLocationUseCaseMock.execute.mockReturnValue({ + worldID: 1, + spaceID: 1, + } as UserLocationTO); - entityContainer.filterEntitiesOfType.mockReturnValue([ - { id: 1, name: "test" } as LearningElementEntity, + entityContainer.filterEntitiesOfType.mockReturnValueOnce([ + { id: 0, elements: [{ id: 1 }] } as LearningSpaceEntity, ]); + entityContainer.filterEntitiesOfType.mockReturnValueOnce([]); + + await expect(systemUnderTest.executeAsync(1)).rejects.toThrow( + "Could not find referenced learning element." + ); + }); + + test("learning element in same space calls onAdaptivityElementUserHintInformed", async () => { getUserLocationUseCaseMock.execute.mockReturnValue({ worldID: 1, spaceID: 1, } as UserLocationTO); + entityContainer.filterEntitiesOfType.mockReturnValueOnce([ + { + id: 1, + elements: [ + { + id: 1, + value: 3, + hasScored: false, + name: "", + description: "", + goals: [], + type: "text", + model: + LearningElementModelTypeEnums.TextElementModelTypes.Bookshelf1, + parentWorldID: 1, + }, + ] as LearningElementEntity[], + } as LearningSpaceEntity, + ]); + + entityContainer.filterEntitiesOfType.mockReturnValueOnce([ + { id: 1, name: "test" } as LearningElementEntity, + ]); + await systemUnderTest.executeAsync(1); expect( diff --git a/src/Components/CoreTest/Presentation/Adaptivity/AdaptivityElement/AdaptivityElementController.test.ts b/src/Components/CoreTest/Presentation/Adaptivity/AdaptivityElement/AdaptivityElementController.test.ts index 287a0bf81..3489b1146 100644 --- a/src/Components/CoreTest/Presentation/Adaptivity/AdaptivityElement/AdaptivityElementController.test.ts +++ b/src/Components/CoreTest/Presentation/Adaptivity/AdaptivityElement/AdaptivityElementController.test.ts @@ -11,7 +11,7 @@ import ISubmitAdaptivityElementSelectionUseCase from "../../../../Core/Applicati import ILearningWorldPort from "../../../../Core/Application/Ports/Interfaces/ILearningWorldPort"; import PORT_TYPES from "../../../../Core/DependencyInjection/Ports/PORT_TYPES"; import { AdaptivityElementActionTypes } from "../../../../Core/Domain/Types/Adaptivity/AdaptivityElementActionTypes"; -import IDisplayLearningElementUseCase from "../../../../Core/Application/UseCases/Adaptivity/DisplayLearningElementUseCase/IDisplayLearningElementUseCase"; +import IDisplayLearningElementUseCase from "../../../../Core/Application/UseCases/Adaptivity/DisplayAdaptivityHintLearningElement/IDisplayAdaptivityHintLearningElementUseCase"; import PRESENTATION_TYPES from "../../../../Core/DependencyInjection/Presentation/PRESENTATION_TYPES"; const submitSelectionUseCaseMock = @@ -73,7 +73,7 @@ describe("AdaptivityElementController", () => { worldPortMock ); CoreDIContainer.rebind( - USECASE_TYPES.IDisplayLearningElementUseCase + USECASE_TYPES.IDisplayAdaptivityHintLearningElementUseCase ).toConstantValue(displayLearningElmentUseCaseMock); CoreDIContainer.bind( PRESENTATION_TYPES.IBottomTooltipPresenter