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

BC-8213 - validate room dates #3434

Merged
merged 38 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9f90a65
add max length validation for room title
odalys-dataport Oct 23, 2024
b6da67a
Merge branch 'main' of https://github.com/hpi-schul-cloud/nuxt-client…
odalys-dataport Oct 28, 2024
e40089f
add min date
odalys-dataport Oct 28, 2024
1770f85
Merge branch 'main' of https://github.com/hpi-schul-cloud/nuxt-client…
odalys-dataport Nov 1, 2024
98bbeb2
fix vuetify lang key missing warning
odalys-dataport Nov 1, 2024
27e3def
startBeforeEndDate validator
odalys-dataport Nov 3, 2024
ff8391a
adjust validator to work for both dates
odalys-dataport Nov 3, 2024
dab7e72
show prop error messages
odalys-dataport Nov 4, 2024
fa7b1a0
remove translations code
odalys-dataport Nov 7, 2024
ee8067c
fix es date format error message
odalys-dataport Nov 7, 2024
6113e73
combine error messages in date picker
odalys-dataport Nov 7, 2024
299f19f
german error message
odalys-dataport Nov 7, 2024
853c86b
translated error message
odalys-dataport Nov 7, 2024
103dd6a
solve merge conflicts in language files
odalys-dataport Nov 11, 2024
88dcc53
show notification on general error
odalys-dataport Nov 12, 2024
783fe38
only show startdate error on startdate field
odalys-dataport Nov 12, 2024
a0529e1
Merge branch 'main' of https://github.com/hpi-schul-cloud/nuxt-client…
odalys-dataport Nov 12, 2024
7b774d6
add notification on edit
odalys-dataport Nov 12, 2024
a27f8bb
Merge branch 'main' into BC-8213-validate-room-dates
odalys-dataport Nov 17, 2024
e7d1531
adjust roomform tests
odalys-dataport Nov 17, 2024
9cabbbc
add basic tests for small room components
odalys-dataport Nov 17, 2024
ccdd8c1
disable today's date for end date picker
odalys-dataport Nov 17, 2024
6d80bce
reduce validator complexity
odalys-dataport Nov 17, 2024
6d4434f
Merge branch 'main' into BC-8213-validate-room-dates
odalys-dataport Nov 18, 2024
372d29d
allow same day
odalys-dataport Nov 18, 2024
e9ed0b3
adjust BoardTile tests
odalys-dataport Nov 19, 2024
f7d27a3
BoardGrid Tests
odalys-dataport Nov 19, 2024
09c59e5
adjust RoomDetails tests
odalys-dataport Nov 19, 2024
e31eda8
handle error in component (create)
odalys-dataport Nov 19, 2024
c5f71ec
separate date compare function
odalys-dataport Nov 19, 2024
d7a5e38
test save event for correct values
odalys-dataport Nov 19, 2024
e43d8a8
handle bad requests in component
odalys-dataport Nov 22, 2024
2b99358
remove unnecessary error type
odalys-dataport Nov 24, 2024
86e730a
use flushPromises instead of nextTick
odalys-dataport Nov 24, 2024
937eaaa
add todos for complicated tests
odalys-dataport Nov 25, 2024
fabf5c5
translated error message for max length validation
odalys-dataport Nov 25, 2024
f8b521d
removed unused imports
odalys-dataport Nov 25, 2024
2cf9b0c
Merge branch 'main' into BC-8213-validate-room-dates
odalys-dataport Nov 27, 2024
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
4 changes: 4 additions & 0 deletions src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,10 @@ export default {
"components.roomForm.labels.timePeriod": "Zeitraum",
"components.roomForm.labels.timePeriod.from": "Zeitraum von",
"components.roomForm.labels.timePeriod.to": "Zeitraum bis",
"components.roomForm.validation.generalSaveError":
"Beim Speichern ist ein Fehler aufgetreten. Bitte überprüfe deine Eingaben und versuche es erneut.",
"components.roomForm.validation.timePeriod.startBeforeEnd":
"Das Startdatum muss vor dem Enddatum liegen.",
"components.timePicker.validation.format": "Bitte Format HH:MM verwenden.",
"components.timePicker.validation.required": "Bitte Uhrzeit angeben.",
"error.400": "400 – Fehlerhafte Anfrage",
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,10 @@ export default {
"components.roomForm.labels.timePeriod": "Time period",
"components.roomForm.labels.timePeriod.from": "Time period from",
"components.roomForm.labels.timePeriod.to": "Time period to",
"components.roomForm.validation.generalSaveError":
"An error occurred while saving. Please check your inputs and try again.",
"components.roomForm.validation.timePeriod.startBeforeEnd":
"The start date must be before the end date.",
"components.timePicker.validation.format": "Please use format HH:MM",
"components.timePicker.validation.required": "Please enter a time.",
"error.400": "401 – Bad Request",
Expand Down
6 changes: 5 additions & 1 deletion src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export default {
"components.cardElement.deletedElement.warning.externalToolElement":
"La herramienta {toolName} no está disponible. Por favor comuníquese con el administrador de la escuela.",
"components.datePicker.validation.format":
"Por favor utilice el formato DD.MM.YYYY",
"Por favor utilice el formato DD.MM.AAAA",
"components.datePicker.validation.required": "Por favor ingrese una fecha.",
"components.dateTimePicker.messages.dateInPast":
"La fecha y la hora están en el pasado.",
Expand Down Expand Up @@ -812,6 +812,10 @@ export default {
"components.roomForm.labels.timePeriod": "Periodo de tiempo",
"components.roomForm.labels.timePeriod.from": "Periodo de tiempo desde",
"components.roomForm.labels.timePeriod.to": "Periodo de tiempo hasta",
"components.roomForm.validation.generalSaveError":
"Se ha producido un error al guardar. Por favor, compruebe sus entradas e inténtelo de nuevo.",
"components.roomForm.validation.timePeriod.startBeforeEnd":
"La fecha de inicio debe ser anterior a la fecha de finalización.",
"components.timePicker.validation.format":
"Por favor utilice el formato HH:MM",
"components.timePicker.validation.required": "Por favor ingrese un tiempo.",
Expand Down
4 changes: 4 additions & 0 deletions src/locales/uk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ export default {
"components.roomForm.labels.timePeriod": "Період часу",
"components.roomForm.labels.timePeriod.from": "Період від",
"components.roomForm.labels.timePeriod.to": "Період до",
"components.roomForm.validation.generalSaveError":
"Виникла помилка при збереженні. Будь ласка, перевірте свої записи та спробуйте ще раз.",
"components.roomForm.validation.timePeriod.startBeforeEnd":
"Дата початку повинна передувати даті закінчення.",
"components.timePicker.validation.format": "Використовуйте формат ГГ:ХХ",
"components.timePicker.validation.required": "Будь ласка, введіть час.",
"error.400": "400 – Неприпустимий запит",
Expand Down
19 changes: 17 additions & 2 deletions src/modules/data/room/RoomCreate.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { RoomApiFactory, RoomColor } from "@/serverApi/v3";
import { RoomCreateParams, RoomItem } from "@/types/room/Room";
import { $axios, mapAxiosErrorToResponseError } from "@/utils/api";
import { createApplicationError } from "@/utils/create-application-error.factory";
import { injectStrict, NOTIFIER_MODULE_KEY } from "@/utils/inject";
import { ref } from "vue";
import { useI18n } from "vue-i18n";

export const useRoomCreateState = () => {
const notifierModule = injectStrict(NOTIFIER_MODULE_KEY);
const { t } = useI18n();

const roomApi = RoomApiFactory(undefined, "/v3", $axios);
const isLoading = ref(true);

Expand All @@ -15,15 +20,25 @@ export const useRoomCreateState = () => {
endDate: undefined,
});

const createRoom = async (params: RoomCreateParams): Promise<RoomItem> => {
const createRoom = async (
params: RoomCreateParams
): Promise<RoomItem | undefined> => {
isLoading.value = true;
try {
odalys-dataport marked this conversation as resolved.
Show resolved Hide resolved
const room = (await roomApi.roomControllerCreateRoom(params)).data;

return room;
} catch (error) {
const responseError = mapAxiosErrorToResponseError(error);

throw createApplicationError(responseError.code);
if (responseError.type === "API_VALIDATION_ERROR") {
notifierModule.show({
text: t("components.roomForm.validation.generalSaveError"),
status: "error",
});
} else {
throw createApplicationError(responseError.code);
}
odalys-dataport marked this conversation as resolved.
Show resolved Hide resolved
} finally {
isLoading.value = false;
}
Expand Down
20 changes: 17 additions & 3 deletions src/modules/data/room/RoomEdit.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { RoomApiFactory, RoomColor } from "@/serverApi/v3";
import { RoomDetails, RoomUpdateParams } from "@/types/room/Room";
import { $axios, mapAxiosErrorToResponseError } from "@/utils/api";
import { createApplicationError } from "@/utils/create-application-error.factory";
import { injectStrict, NOTIFIER_MODULE_KEY } from "@/utils/inject";
import { ref } from "vue";
import { useI18n } from "vue-i18n";

export const useRoomEditState = () => {
const notifierModule = injectStrict(NOTIFIER_MODULE_KEY);
const { t } = useI18n();

const roomApi = RoomApiFactory(undefined, "/v3", $axios);
const isLoading = ref(true);

Expand Down Expand Up @@ -40,14 +45,23 @@ export const useRoomEditState = () => {
const updateRoom = async (
id: string,
params: RoomUpdateParams
): Promise<void> => {
): Promise<RoomDetails | undefined> => {
isLoading.value = true;
try {
await roomApi.roomControllerUpdateRoom(id, params);
const room = (await roomApi.roomControllerUpdateRoom(id, params)).data;
odalys-dataport marked this conversation as resolved.
Show resolved Hide resolved

return room;
} catch (error) {
const responseError = mapAxiosErrorToResponseError(error);

throw createApplicationError(responseError.code);
if (responseError.type === "API_VALIDATION_ERROR") {
notifierModule.show({
text: t("components.roomForm.validation.generalSaveError"),
status: "error",
});
} else {
throw createApplicationError(responseError.code);
}
} finally {
isLoading.value = false;
}
Expand Down
39 changes: 39 additions & 0 deletions src/modules/feature/room/BoardGrid.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
createTestingVuetify,
createTestingI18n,
} from "@@/tests/test-utils/setup";
import { mount } from "@vue/test-utils";
import { ComponentProps } from "vue-component-type-helpers";
import BoardGrid from "./BoardGrid.vue";
import { BoardLayout } from "@/serverApi/v3";
import { RoomBoardItem } from "@/types/room/Room";

const mockBoard: RoomBoardItem = {
id: "59cce2c61113d1132c98dc06",
title: "A11Y for Beginners",
layout: BoardLayout.Columns,
isVisible: true,
createdAt: "2017-09-28T11:49:39.924Z",
updatedAt: "2017-09-28T11:49:39.924Z",
};

describe("@feature-room/BoardGrid", () => {
const setup = (props: ComponentProps<typeof BoardGrid>) => {
const wrapper = mount(BoardGrid, {
sync: false,
global: {
plugins: [createTestingVuetify(), createTestingI18n()],
},
props,
attachTo: document.body,
});

return { wrapper };
};

it("should render correctly", async () => {
const { wrapper } = setup({ boards: [mockBoard] });

expect(wrapper.exists()).toStrictEqual(true);
odalys-dataport marked this conversation as resolved.
Show resolved Hide resolved
});
});
39 changes: 39 additions & 0 deletions src/modules/feature/room/BoardTile.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
createTestingVuetify,
createTestingI18n,
} from "@@/tests/test-utils/setup";
import { mount } from "@vue/test-utils";
import { ComponentProps } from "vue-component-type-helpers";
import BoardTile from "./BoardTile.vue";
import { BoardLayout } from "@/serverApi/v3";
import { RoomBoardItem } from "@/types/room/Room";

const mockBoard: RoomBoardItem = {
id: "59cce2c61113d1132c98dc06",
title: "A11Y for Beginners",
layout: BoardLayout.Columns,
isVisible: true,
createdAt: "2017-09-28T11:49:39.924Z",
updatedAt: "2017-09-28T11:49:39.924Z",
};

describe("@feature-room/BoardTile", () => {
const setup = (props: ComponentProps<typeof BoardTile>) => {
const wrapper = mount(BoardTile, {
sync: false,
global: {
plugins: [createTestingVuetify(), createTestingI18n()],
},
props,
attachTo: document.body,
});

return { wrapper };
};

it("should render correctly", async () => {
const { wrapper } = setup({ board: mockBoard, index: 0 });

expect(wrapper.exists()).toStrictEqual(true);
});
});
40 changes: 40 additions & 0 deletions src/modules/feature/room/RoomDetails.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
createTestingVuetify,
createTestingI18n,
} from "@@/tests/test-utils/setup";
import { mount } from "@vue/test-utils";
import { ComponentProps } from "vue-component-type-helpers";
import RoomDetails from "./RoomDetails.vue";
import { RoomDetails as RoomDetailsType } from "@/types/room/Room";
import { RoomColor } from "@/serverApi/v3";

const mockRoom: RoomDetailsType = {
id: "59cce2c61113d1132c98dc06",
name: "A11Y for Beginners",
color: RoomColor.Magenta,
startDate: "",
endDate: "",
createdAt: "2017-09-28T11:49:39.924Z",
updatedAt: "2017-09-28T11:49:39.924Z",
};

describe("@feature-room/RoomDetails", () => {
const setup = (props: ComponentProps<typeof RoomDetails>) => {
const wrapper = mount(RoomDetails, {
sync: false,
global: {
plugins: [createTestingVuetify(), createTestingI18n()],
},
props,
attachTo: document.body,
});

return { wrapper };
};

it("should render correctly", async () => {
const { wrapper } = setup({ room: mockRoom });

expect(wrapper.exists()).toStrictEqual(true);
});
odalys-dataport marked this conversation as resolved.
Show resolved Hide resolved
});
Loading
Loading