Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N21-1494 Generate Info outdated ctl tools #2931

Merged
merged 23 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/components/administration/ExternalToolSection.unit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import AuthModule from "@/store/auth";
import { ToolConfigurationStatus } from "@/store/external-tool";
import NotifierModule from "@/store/notifier";
import SchoolExternalToolsModule from "@/store/school-external-tools";
import { User } from "@/store/types/auth";
Expand All @@ -21,6 +20,7 @@ import { useSchoolExternalToolUsage } from "@data-external-tool";
import {
schoolExternalToolFactory,
schoolExternalToolMetadataFactory,
toolConfigurationStatusFactory,
} from "@@/tests/test-utils/factory";

jest.mock("@data-external-tool");
Expand Down Expand Up @@ -119,7 +119,7 @@ describe("ExternalToolSection", () => {
schoolId: "schoolId",
parameters: [],
name: firstToolName,
status: ToolConfigurationStatus.Latest,
status: toolConfigurationStatusFactory.build(),
version: 1,
},
{
Expand All @@ -128,7 +128,9 @@ describe("ExternalToolSection", () => {
schoolId: "schoolId",
parameters: [],
name: secondToolName,
status: ToolConfigurationStatus.Outdated,
status: toolConfigurationStatusFactory.build({
isOutdatedOnScopeSchool: true,
}),
version: 1,
},
],
Expand Down Expand Up @@ -246,7 +248,7 @@ describe("ExternalToolSection", () => {
schoolId: "schoolId",
parameters: [],
name: "firstToolName",
status: ToolConfigurationStatus.Latest,
status: toolConfigurationStatusFactory.build(),
version: 1,
},
],
Expand Down Expand Up @@ -278,7 +280,7 @@ describe("ExternalToolSection", () => {
schoolId: "schoolId",
parameters: [],
name: "firstToolName",
status: ToolConfigurationStatus.Latest,
status: toolConfigurationStatusFactory.build(),
version: 1,
},
],
Expand Down Expand Up @@ -313,7 +315,7 @@ describe("ExternalToolSection", () => {
//@ts-ignore
wrapper.vm.itemToDelete = {
name: expectedName,
status: ToolConfigurationStatus.Latest,
status: toolConfigurationStatusFactory.build(),
outdated: false,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { DataTableHeader } from "vuetify";
import { SchoolExternalToolItem } from "./school-external-tool-item";
import {
SchoolExternalTool,
ToolConfigurationStatus,
} from "@/store/external-tool";
import { SchoolExternalTool } from "@/store/external-tool";
import { ToolConfigurationStatusTranslationMapping } from "@/composables/external-tool-mappings.composable";
import SchoolExternalToolsModule from "@/store/school-external-tools";

Expand Down Expand Up @@ -35,10 +32,9 @@ export function useExternalToolsSectionUtils(
const schoolExternalTools: SchoolExternalTool[] =
schoolExternalToolsModule.getSchoolExternalTools;
return schoolExternalTools.map((tool: SchoolExternalTool) => {
const outdated: boolean =
tool.status === ToolConfigurationStatus.Outdated;
const outdated: boolean = tool.status.isOutdatedOnScopeSchool;
const statusTranslationKey: string =
ToolConfigurationStatusTranslationMapping[tool.status];
ToolConfigurationStatusTranslationMapping(tool.status);
mrikallab marked this conversation as resolved.
Show resolved Hide resolved

return {
id: tool.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { DataTableHeader } from "vuetify";
import { schoolExternalToolsModule } from "@/store";
import {
SchoolExternalToolResponse,
SchoolExternalToolResponseStatusEnum,
SchoolExternalToolSearchListResponse,
} from "@/serverApi/v3";
import { SchoolExternalToolItem } from "./school-external-tool-item";
import { ToolConfigurationStatus } from "@/store/external-tool";
import { toolConfigurationStatusFactory } from "@@/tests/test-utils";

const schoolExternalToolsModuleMock = () => {
return {
Expand All @@ -16,7 +15,10 @@ const schoolExternalToolsModuleMock = () => {
id: "id",
name: "toolName",
version: 1,
status: "Latest",
status: {
isOutdatedOnScopeSchool: false,
isOutdatedOnScopeContext: false,
},
},
],
};
Expand Down Expand Up @@ -45,7 +47,10 @@ describe("useSchoolExternalToolUtils", () => {
value: "value",
},
],
status: SchoolExternalToolResponseStatusEnum.Latest,
status: toolConfigurationStatusFactory.build({
isOutdatedOnScopeSchool: false,
isOutdatedOnScopeContext: false,
}),
};
const listResponse: SchoolExternalToolSearchListResponse = {
data: [toolResponse],
Expand All @@ -54,7 +59,7 @@ describe("useSchoolExternalToolUtils", () => {
const schoolExternaToolItem: SchoolExternalToolItem = {
name: toolResponse.name,
id: toolResponse.id,
status: ToolConfigurationStatus.Latest,
status: "translationKey",
outdated: false,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import * as serverApi from "@/serverApi/v3/api";
import { ToolReferenceResponse } from "@/serverApi/v3/api";
import {
ExternalToolDisplayData,
ToolConfigurationStatus,
} from "@/store/external-tool";
import { ExternalToolDisplayData } from "@/store/external-tool";
import {
mockApiResponse,
toolReferenceResponseFactory,
} from "@@/tests/test-utils";
import { createMock, DeepMocked } from "@golevelup/ts-jest";
import { useContextExternalToolApi } from "./ContextExternalToolApi.composable";
import { toolConfigurationStatusFactory } from "../../../tests/test-utils/factory/toolConfigurationSatusFactory";
mrikallab marked this conversation as resolved.
Show resolved Hide resolved

describe("ContextExternalToolApi.composable", () => {
let toolApi: DeepMocked<serverApi.ToolApiInterface>;
Expand Down Expand Up @@ -62,7 +60,7 @@ describe("ContextExternalToolApi.composable", () => {
contextExternalToolId: displayData.contextToolId,
name: displayData.displayName,
logoUrl: displayData.logoUrl,
status: ToolConfigurationStatus.Latest,
status: toolConfigurationStatusFactory.build(),
openInNewTab: displayData.openInNewTab,
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ToolConfigurationStatus } from "@/store/external-tool";
mrikallab marked this conversation as resolved.
Show resolved Hide resolved
import AuthModule from "@/store/auth";
import { AUTH_MODULE_KEY, injectStrict } from "@/utils/inject";

export const useToolConfigurationStatus = () => {
const authModule: AuthModule = injectStrict(AUTH_MODULE_KEY);

const determineOutdatedTranslationKey = (
toolConfigStatus: ToolConfigurationStatus | undefined
): string => {
const userRoles = authModule.getUserRoles;

if (userRoles.includes("teacher")) {
if (
toolConfigStatus?.isOutdatedOnScopeContext &&
toolConfigStatus.isOutdatedOnScopeSchool
) {
return "common.information.outdatedOnSchoolAndContext.teacher";
} else if (toolConfigStatus?.isOutdatedOnScopeSchool) {
mrikallab marked this conversation as resolved.
Show resolved Hide resolved
return "common.information.outdatedOnSchool.teacher";
} else {
return "common.information.outdatedOnContext.teacher";
}
} else {
return "common.information.outdated.student";
}
};

return {
determineOutdatedTranslationKey,
};
};
1 change: 1 addition & 0 deletions src/components/data-external-tool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./ExternalToolElementDisplayState.composable";
export * from "./ExternalToolLaunchState.composable";
export * from "./SchoolExternalToolApi.composable";
export * from "./SchoolExternalToolUsage.composable";
export * from "./ToolConfigurationStatus.composable";
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import {
ContentElementType,
ExternalToolElementResponse,
} from "@/serverApi/v3";
import {
ExternalToolDisplayData,
ToolConfigurationStatus,
} from "@/store/external-tool";
import { ExternalToolDisplayData } from "@/store/external-tool";
import { ContextExternalTool } from "@/store/external-tool/context-external-tool";
import { BusinessError } from "@/store/types/commons";
import { I18N_KEY } from "@/utils/inject";
Expand All @@ -14,12 +11,14 @@ import {
externalToolDisplayDataFactory,
i18nMock,
timestampsResponseFactory,
toolConfigurationStatusFactory,
} from "@@/tests/test-utils";
import createComponentMocks from "@@/tests/test-utils/componentMocks";
import { useBoardFocusHandler, useContentElementState } from "@data-board";
import {
useExternalToolElementDisplayState,
useExternalToolLaunchState,
useToolConfigurationStatus,
} from "@data-external-tool";
import { createMock, DeepMocked } from "@golevelup/ts-jest";
import { mdiPuzzleOutline } from "@mdi/js";
Expand Down Expand Up @@ -58,6 +57,10 @@ describe("ExternalToolElement", () => {
ReturnType<typeof useSharedLastCreatedElement>
>;

let useToolConfigurationStatusMock: DeepMocked<
ReturnType<typeof useToolConfigurationStatus>
>;

beforeEach(() => {
useContentElementStateMock =
createMock<ReturnType<typeof useContentElementState>>();
Expand All @@ -69,6 +72,8 @@ describe("ExternalToolElement", () => {
createMock<ReturnType<typeof useExternalToolLaunchState>>();
useSharedLastCreatedElementMock =
createMock<ReturnType<typeof useSharedLastCreatedElement>>();
useToolConfigurationStatusMock =
createMock<ReturnType<typeof useToolConfigurationStatus>>();

jest
.mocked(useContentElementState)
Expand All @@ -83,6 +88,9 @@ describe("ExternalToolElement", () => {
jest
.mocked(useSharedLastCreatedElement)
.mockReturnValue(useSharedLastCreatedElementMock);
jest
.mocked(useToolConfigurationStatus)
.mockReturnValue(useToolConfigurationStatusMock);
});

afterEach(() => {
Expand Down Expand Up @@ -143,7 +151,7 @@ describe("ExternalToolElement", () => {
isEditMode: false,
},
externalToolDisplayDataFactory.build({
status: ToolConfigurationStatus.Latest,
status: toolConfigurationStatusFactory.build(),
})
);

Expand All @@ -164,7 +172,7 @@ describe("ExternalToolElement", () => {
isEditMode: false,
},
externalToolDisplayDataFactory.build({
status: ToolConfigurationStatus.Latest,
status: toolConfigurationStatusFactory.build(),
})
);

Expand All @@ -187,7 +195,10 @@ describe("ExternalToolElement", () => {
isEditMode: false,
},
externalToolDisplayDataFactory.build({
status: ToolConfigurationStatus.Outdated,
status: toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
}),
})
);

Expand Down Expand Up @@ -677,13 +688,18 @@ describe("ExternalToolElement", () => {
message: "Loading error",
};

const toolOautdatedStatus = toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
});

const { wrapper } = getWrapper(
{
element: EMPTY_TEST_ELEMENT,
isEditMode: true,
},
externalToolDisplayDataFactory.build({
status: ToolConfigurationStatus.Outdated,
status: toolOautdatedStatus,
})
);

Expand All @@ -692,17 +708,18 @@ describe("ExternalToolElement", () => {
return {
wrapper,
error,
toolOautdatedStatus,
};
};

it("should display an outdated alert", async () => {
const { wrapper } = setup();
const { wrapper, toolOautdatedStatus } = setup();

const alert = wrapper.find(
'[data-testid="board-external-tool-element-alert"]'
);

expect(alert.props("isToolOutdated")).toEqual(true);
expect(alert.props("toolOutdatedStatus")).toEqual(toolOautdatedStatus);
});

it("should display an error alert", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<ExternalToolElementAlert
:error="error"
:is-tool-outdated="isToolOutdated"
mrikallab marked this conversation as resolved.
Show resolved Hide resolved
:tool-outdated-status="toolOutdatedStatus"
data-testid="board-external-tool-element-alert"
/>
<ExternalToolElementConfigurationDialog
Expand All @@ -61,7 +62,6 @@
<script lang="ts">
import { useI18n } from "@/composables/i18n.composable";
import { ExternalToolElementResponse } from "@/serverApi/v3";
import { ToolConfigurationStatus } from "@/store/external-tool";
import { ContextExternalTool } from "@/store/external-tool/context-external-tool";
import { useBoardFocusHandler, useContentElementState } from "@data-board";
import {
Expand All @@ -84,6 +84,7 @@ import {
import ExternalToolElementAlert from "./ExternalToolElementAlert.vue";
import ExternalToolElementConfigurationDialog from "./ExternalToolElementConfigurationDialog.vue";
import ExternalToolElementMenu from "./ExternalToolElementMenu.vue";
import { ToolConfigurationStatus } from "@/store/external-tool";

export default defineComponent({
components: {
Expand Down Expand Up @@ -115,6 +116,7 @@ export default defineComponent({
isLoading: isDisplayDataLoading,
error,
} = useExternalToolElementDisplayState();

const { launchTool, fetchLaunchRequest } = useExternalToolLaunchState();

const autofocus: Ref<boolean> = ref(false);
Expand Down Expand Up @@ -142,9 +144,17 @@ export default defineComponent({
);

const isToolOutdated: ComputedRef<boolean> = computed(
() => displayData.value?.status === ToolConfigurationStatus.Outdated
() =>
(displayData.value?.status.isOutdatedOnScopeSchool ||
displayData.value?.status.isOutdatedOnScopeContext) ??
false
mrikallab marked this conversation as resolved.
Show resolved Hide resolved
);

const toolOutdatedStatus: ComputedRef<ToolConfigurationStatus | undefined> =
MarvinOehlerkingCap marked this conversation as resolved.
Show resolved Hide resolved
computed(() => {
return displayData.value?.status;
});

const isLoading = computed(
() =>
hasLinkedTool.value && !displayData.value && isDisplayDataLoading.value
Expand Down Expand Up @@ -214,6 +224,7 @@ export default defineComponent({
isLoading,
isToolOutdated,
isConfigurationDialogOpen,
toolOutdatedStatus,
mdiPuzzleOutline,
onMoveElementDown,
onMoveElementUp,
Expand Down
Loading
Loading