fix: bug in assignment vertalingen
This commit is contained in:
parent
f67e3f5a1a
commit
0abe9b1bce
4 changed files with 37 additions and 119 deletions
|
@ -1,6 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { deadlineRules } from "@/utils/assignment-rules.ts";
|
|
||||||
|
|
||||||
const emit = defineEmits<(e: "update:deadline", value: Date | null) => void>();
|
const emit = defineEmits<(e: "update:deadline", value: Date | null) => void>();
|
||||||
const props = defineProps<{ deadline: Date | null }>();
|
const props = defineProps<{ deadline: Date | null }>();
|
||||||
|
@ -19,6 +18,24 @@
|
||||||
emit("update:deadline", null);
|
emit("update:deadline", null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const deadlineRules = [
|
||||||
|
(value: string): string | boolean => {
|
||||||
|
|
||||||
|
const selectedDateTime = new Date(value);
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
if (isNaN(selectedDateTime.getTime())) {
|
||||||
|
return t("deadline-invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedDateTime <= now) {
|
||||||
|
return t("deadline-past");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -1,20 +1,9 @@
|
||||||
import {useI18n} from "vue-i18n";
|
|
||||||
|
|
||||||
const { t } = useI18n();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validation rule for the assignment title.
|
* Validation rule for the assignment title.
|
||||||
*
|
*
|
||||||
* Ensures that the title is not empty.
|
* Ensures that the title is not empty.
|
||||||
*/
|
*/
|
||||||
export const assignmentTitleRules = [
|
|
||||||
(value: string): string | boolean => {
|
|
||||||
if (value?.length >= 1) {
|
|
||||||
return true;
|
|
||||||
} // Title must not be empty
|
|
||||||
return t("title-required");
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,34 +11,10 @@ export const assignmentTitleRules = [
|
||||||
*
|
*
|
||||||
* Ensures that at least one class is selected.
|
* Ensures that at least one class is selected.
|
||||||
*/
|
*/
|
||||||
export const classRules = [
|
|
||||||
(value: string): string | boolean => {
|
|
||||||
if (value) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return t("class-required");
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validation rule for the deadline field.
|
* Validation rule for the deadline field.
|
||||||
*
|
*
|
||||||
* Ensures that a valid deadline is selected and is in the future.
|
* Ensures that a valid deadline is selected and is in the future.
|
||||||
*/
|
*/
|
||||||
export const deadlineRules = [
|
|
||||||
(value: string): string | boolean => {
|
|
||||||
|
|
||||||
const selectedDateTime = new Date(value);
|
|
||||||
const now = new Date();
|
|
||||||
|
|
||||||
if (isNaN(selectedDateTime.getTime())) {
|
|
||||||
return t("deadline-invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedDateTime <= now) {
|
|
||||||
return t("deadline-past");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { computed, onMounted, ref, watch } from "vue";
|
import { computed, onMounted, ref, watch } from "vue";
|
||||||
import { assignmentTitleRules, classRules } from "@/utils/assignment-rules.ts";
|
|
||||||
import auth from "@/services/auth/auth-service.ts";
|
import auth from "@/services/auth/auth-service.ts";
|
||||||
import { useTeacherClassesQuery } from "@/queries/teachers.ts";
|
import { useTeacherClassesQuery } from "@/queries/teachers.ts";
|
||||||
import { useRouter, useRoute } from "vue-router";
|
import { useRouter, useRoute } from "vue-router";
|
||||||
|
@ -96,6 +95,25 @@ const learningPathRules = [
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const assignmentTitleRules = [
|
||||||
|
(value: string): string | boolean => {
|
||||||
|
if (value?.length >= 1) {
|
||||||
|
return true;
|
||||||
|
} // Title must not be empty
|
||||||
|
return t("title-required");
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const classRules = [
|
||||||
|
(value: string): string | boolean => {
|
||||||
|
if (value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return t("class-required");
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import {
|
|
||||||
assignmentTitleRules,
|
|
||||||
classRules,
|
|
||||||
deadlineRules,
|
|
||||||
descriptionRules,
|
|
||||||
learningPathRules,
|
|
||||||
} from "../../src/utils/assignment-rules";
|
|
||||||
|
|
||||||
describe("Validation Rules", () => {
|
|
||||||
describe("assignmentTitleRules", () => {
|
|
||||||
it("should return true for a valid title", () => {
|
|
||||||
const result = assignmentTitleRules[0]("Valid Title");
|
|
||||||
expect(result).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return an error message for an empty title", () => {
|
|
||||||
const result = assignmentTitleRules[0]("");
|
|
||||||
expect(result).toBe("Title cannot be empty.");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("learningPathRules", () => {
|
|
||||||
it("should return true for a valid learning path", () => {
|
|
||||||
const result = learningPathRules[0]({ hruid: "123", title: "Path Title" });
|
|
||||||
expect(result).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return an error message for an invalid learning path", () => {
|
|
||||||
const result = learningPathRules[0]({ hruid: "", title: "" });
|
|
||||||
expect(result).toBe("You must select a learning path.");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("classRules", () => {
|
|
||||||
it("should return true for a valid class", () => {
|
|
||||||
const result = classRules[0]("Class 1");
|
|
||||||
expect(result).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return an error message for an empty class", () => {
|
|
||||||
const result = classRules[0]("");
|
|
||||||
expect(result).toBe("You must select at least one class.");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("deadlineRules", () => {
|
|
||||||
it("should return true for a valid future deadline", () => {
|
|
||||||
const futureDate = new Date(Date.now() + 1000 * 60 * 60).toISOString();
|
|
||||||
const result = deadlineRules[0](futureDate);
|
|
||||||
expect(result).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return an error message for a past deadline", () => {
|
|
||||||
const pastDate = new Date(Date.now() - 1000 * 60 * 60).toISOString();
|
|
||||||
const result = deadlineRules[0](pastDate);
|
|
||||||
expect(result).toBe("The deadline must be in the future.");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return an error message for an invalid date", () => {
|
|
||||||
const result = deadlineRules[0]("invalid-date");
|
|
||||||
expect(result).toBe("Invalid date or time.");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return an error message for an empty deadline", () => {
|
|
||||||
const result = deadlineRules[0]("");
|
|
||||||
expect(result).toBe("You must set a deadline.");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("descriptionRules", () => {
|
|
||||||
it("should return true for a valid description", () => {
|
|
||||||
const result = descriptionRules[0]("This is a valid description.");
|
|
||||||
expect(result).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return an error message for an empty description", () => {
|
|
||||||
const result = descriptionRules[0]("");
|
|
||||||
expect(result).toBe("Description cannot be empty.");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Add table
Add a link
Reference in a new issue