Skip to content

Commit

Permalink
BC-8008 - Fix any type linter warning (#3549)
Browse files Browse the repository at this point in the history
* adjusting types
* restructure imports
* fixing general any type warnings

---------

Co-authored-by: wolfganggreschus <[email protected]>
Co-authored-by: Martin Schuhmacher <[email protected]>
  • Loading branch information
3 people authored Feb 26, 2025
1 parent 49d80c2 commit f11895c
Show file tree
Hide file tree
Showing 60 changed files with 1,100 additions and 952 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = [
"error",
{ allowInterfaces: "with-single-extends" },
],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-require-imports": "warn",
"@typescript-eslint/no-restricted-imports": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function useExternalToolsSectionUtils(
t: (key: string) => string = () => "",
mediaLicenseEnabled = false
) {
const getHeaders: DataTableHeader[] = [
const getHeaders: DataTableHeader<SchoolExternalToolMediumResponse>[] = [
{
title: t("common.labels.name"),
value: "name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ describe("useSchoolExternalToolUtils", () => {
const { tool } = setupTool();
const { getHeaders } = setup(tool);

const headers: DataTableHeader[] = getHeaders;

expect(Array.isArray(headers)).toBeTruthy();
expect(Array.isArray(getHeaders)).toBeTruthy();
});

describe("when translate the headers", () => {
Expand Down Expand Up @@ -97,24 +95,22 @@ describe("useSchoolExternalToolUtils", () => {
const { tool } = setupTool();
const { getHeaders, expectedTranslation } = setup(tool);

const headers: DataTableHeader[] = getHeaders;

expect(headers[0].title).toEqual(expectedTranslation);
expect(headers[0].value).toEqual("name");
expect(getHeaders[0].title).toEqual(expectedTranslation);
expect(getHeaders[0].value).toEqual("name");

expect(headers[1].title).toEqual(expectedTranslation);
expect(headers[1].value).toEqual("statusText");
expect(getHeaders[1].title).toEqual(expectedTranslation);
expect(getHeaders[1].value).toEqual("statusText");

expect(headers[2].title).toEqual(expectedTranslation);
expect(headers[2].value).toEqual("medium");
expect(getHeaders[2].title).toEqual(expectedTranslation);
expect(getHeaders[2].value).toEqual("medium");

expect(headers[3].title).toEqual(expectedTranslation);
expect(headers[3].value).toEqual("restrictToContexts");
expect(getHeaders[3].title).toEqual(expectedTranslation);
expect(getHeaders[3].value).toEqual("restrictToContexts");

expect(headers[4].title).toEqual("");
expect(headers[4].value).toEqual("actions");
expect(headers[4].sortable).toBe(false);
expect(headers[4].align).toEqual("end");
expect(getHeaders[4].title).toEqual("");
expect(getHeaders[4].value).toEqual("actions");
expect(getHeaders[4].sortable).toBe(false);
expect(getHeaders[4].align).toEqual("end");
});
});

Expand Down
11 changes: 8 additions & 3 deletions src/components/error-handling/ErrorHandler.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export type ErrorType =
| "notCreated"
| "notLoaded"
| "notUpdated"
| "notDeleted";
| "notDeleted"
| "notMoved";

export type BoardObjectType =
| "board"
Expand All @@ -22,8 +23,12 @@ export type ApiErrorHandler = (
error?: ApiResponseError | ApiValidationError
) => Promise<void> | void;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ApiErrorHandlerFactory = (...args: any[]) => ApiErrorHandler;
export type ApiErrorHandlerFactory = (
errorType: ErrorType,
boardObjectType?: BoardObjectType,
status?: ErrorStatus,
timeout?: number
) => ApiErrorHandler;

export type ErrorMap = Record<number, ApiErrorHandler>;

Expand Down
22 changes: 14 additions & 8 deletions src/components/molecules/CommonCartridgeExportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@
</template>

<script setup lang="ts">
import { BoardElementResponseTypeEnum } from "@/serverApi/v3/api";
import {
BoardColumnBoard,
BoardElement,
BoardElementType,
BoardLesson,
BoardTask,
} from "@/types/course-room/CourseRoom";
import {
COMMON_CARTRIDGE_EXPORT_MODULE_KEY,
injectStrict,
Expand Down Expand Up @@ -223,27 +229,27 @@ watch(
allTasks.value = [];
allColumnBoards.value = [];
newValue.forEach((element: any) => {
if (element.type === BoardElementResponseTypeEnum.Lesson) {
newValue.forEach((element: BoardElement) => {
if (element.type === BoardElementType.Lesson) {
allTopics.value.push({
isSelected: true,
title: element.content.name,
title: (element.content as BoardLesson).name,
id: element.content.id,
});
}
if (element.type === BoardElementResponseTypeEnum.Task) {
if (element.type === BoardElementType.Task) {
allTasks.value.push({
isSelected: true,
title: element.content.name,
title: (element.content as BoardTask).name,
id: element.content.id,
});
}
if (element.type === BoardElementResponseTypeEnum.ColumnBoard) {
if (element.type === BoardElementType.ColumnBoard) {
allColumnBoards.value.push({
isSelected: true,
title: element.content.title,
title: (element.content as BoardColumnBoard).title,
id: element.content.id,
});
}
Expand Down
14 changes: 7 additions & 7 deletions src/components/molecules/CommonCartridgeImportModal.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,29 @@ describe("@/components/molecules/CommonCartridgeImportModal", () => {

const confirmBtn = wrapper.findComponent(
"[data-testId='dialog-confirm-btn']"
) as any;
);

expect(confirmBtn.exists()).toBe(true);
expect(confirmBtn.isDisabled()).toBe(true);
expect(confirmBtn.classes()).toContain("v-btn--disabled");
});

it("should contain enabled cancel button", async () => {
const { wrapper } = setup();

const cancelBtn = wrapper.findComponent(
"[data-testid='dialog-cancel-btn']"
) as any;
);

expect(cancelBtn.exists()).toBe(true);
expect(cancelBtn.isDisabled()).toBe(false);
expect(cancelBtn.classes()).not.toContain("v-btn--disabled");
});

it("should contain file input", () => {
const { wrapper } = setup();

const fileInput = wrapper.findComponent(
"[data-testid='dialog-file-input']"
) as any;
);

expect(fileInput.exists()).toBe(true);
});
Expand All @@ -99,9 +99,9 @@ describe("@/components/molecules/CommonCartridgeImportModal", () => {

const confirmBtn = wrapper.findComponent(
"[data-testId='dialog-confirm-btn']"
) as any;
);

expect(confirmBtn.isDisabled()).toBe(false);
expect(confirmBtn.classes()).not.toContain("v-btn--disabled");
});
});

Expand Down
7 changes: 5 additions & 2 deletions src/components/molecules/InfoBox.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import {
} from "@@/tests/test-utils/setup";
import { mount } from "@vue/test-utils";
import InfoBox from "./InfoBox.vue";
import { VNode } from "vue";

type MountingSlots = Record<string, string | (() => VNode[])>;

describe("@/components/molecules/InfoBox", () => {
describe("when active is true", () => {
const setup = (slots: any) => {
const setup = (slots: MountingSlots) => {
const wrapper = mount(InfoBox, {
global: { plugins: [createTestingVuetify(), createTestingI18n()] },
props: {
Expand Down Expand Up @@ -44,7 +47,7 @@ describe("@/components/molecules/InfoBox", () => {
});

describe("when active is false", () => {
const setup = (slots: any) => {
const setup = (slots: MountingSlots) => {
const wrapper = mount(InfoBox, {
global: { plugins: [createTestingVuetify(), createTestingI18n()] },
props: {
Expand Down
13 changes: 7 additions & 6 deletions src/components/molecules/TaskItemStudent.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
import { createMock } from "@golevelup/ts-jest";
import { mount } from "@vue/test-utils";
import TaskItemStudent from "./TaskItemStudent.vue";
import { ComponentProps } from "vue-component-type-helpers";

const { tasks, openTasksWithoutDueDate, openTasksWithDueDate, invalidTasks } =
mocks;

Expand All @@ -26,7 +28,7 @@ const mockRouter = {
push: jest.fn(),
};

const getWrapper = (props: object, options?: object) => {
const getWrapper = (props: ComponentProps<typeof TaskItemStudent>) => {
return mount(TaskItemStudent, {
global: {
plugins: [createTestingVuetify(), createTestingI18n()],
Expand All @@ -37,7 +39,6 @@ const getWrapper = (props: object, options?: object) => {
},
},
props,
...options,
mocks: {
$router: mockRouter,
},
Expand All @@ -51,7 +52,7 @@ describe("@/components/molecules/TaskItemStudent", () => {
notifierModuleMock = createModuleMocks(NotifierModule);
});

it("Should direct user to legacy task details page", () => {
it("Should direct user to legacy task details page", async () => {
Object.defineProperty(window, "location", {
set: jest.fn(),
get: () => createMock<Location>(),
Expand All @@ -60,7 +61,7 @@ describe("@/components/molecules/TaskItemStudent", () => {

const wrapper = getWrapper({ task: tasks[0] });
const taskCard = wrapper.findComponent({ name: "v-list-item" });
taskCard.trigger("click");
await taskCard.trigger("click");

expect(locationSpy).toHaveBeenCalledWith(`/homework/${tasks[0].id}`);
});
Expand All @@ -75,7 +76,7 @@ describe("@/components/molecules/TaskItemStudent", () => {
it("Should display due date label if task has dueDate", () => {
const wrapper = getWrapper({ task: tasks[0] });

const convertedDueDate = dateTimeFromUTC((tasks[0] as any).dueDate);
const convertedDueDate = dateTimeFromUTC(tasks[0].dueDate);
const expectedDueDateLabel = `pages.tasks.labels.due ${convertedDueDate}`;

const dueDateLabel = wrapper.find("[data-test-id='dueDateLabel']");
Expand Down Expand Up @@ -145,7 +146,7 @@ describe("@/components/molecules/TaskItemStudent", () => {

wrapper.vm.$vuetify.display.xs = true;

const convertedDueDate = dateFromUTC((tasks[0] as any).dueDate);
const convertedDueDate = dateFromUTC(tasks[0].dueDate);
const expectedDueDateLabel = `pages.tasks.labels.due ${convertedDueDate}`;

expect(wrapper.vm.dueDateLabel).toBe(expectedDueDateLabel);
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/TaskItemStudent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</template>

<script>
import VCustomChipTimeRemaining from "@/components/atoms/VCustomChipTimeRemaining";
import VCustomChipTimeRemaining from "@/components/atoms/VCustomChipTimeRemaining.vue";
import {
printDateFromStringUTC as dateFromUTC,
printDateTimeFromStringUTC as dateTimeFromUTC,
Expand Down
Loading

0 comments on commit f11895c

Please sign in to comment.