Skip to content

Commit

Permalink
N21-2293 Full sync warning bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mrikallab authored Jan 13, 2025
1 parent 74ff042 commit eb6da01
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 6 deletions.
113 changes: 109 additions & 4 deletions src/modules/feature/course-sync/StartExistingCourseSyncDialog.unit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vCustomDialog from "@/components/organisms/vCustomDialog.vue";
import { RoleName } from "@/serverApi/v3";
import { MeResponse, RoleName } from "@/serverApi/v3";
import AuthModule from "@/store/auth";
import NotifierModule from "@/store/notifier";
import { AUTH_MODULE_KEY, NOTIFIER_MODULE_KEY } from "@/utils/inject";
Expand Down Expand Up @@ -28,13 +28,14 @@ describe("StartExistingCourseSyncDialog", () => {
isOpen: true,
courseId: "courseId",
courseName: "courseName",
}
courseTeachers: ["firstName lastName"],
},
admin?: MeResponse
) => {
const me = meResponseFactory.build();

const notifierModule = createModuleMocks(NotifierModule);
const authModule = createModuleMocks(AuthModule, {
getMe: me,
getMe: admin ?? me,
});

const wrapper = mount(StartExistingCourseSyncDialog, {
Expand Down Expand Up @@ -334,4 +335,108 @@ describe("StartExistingCourseSyncDialog", () => {
);
});
});

describe("when the user is not part of the selected group and course teacher are part of group", () => {
const setup = async () => {
const { wrapper, notifierModule } = getWrapper(
{
isOpen: true,
courseId: "courseId",
courseName: "courseName",
courseTeachers: ["firstname lastname"],
},
meResponseFactory.build({
roles: [{ id: "0", name: RoleName.Administrator }],
})
);

const group = groupResponseFactory.build({
users: [
{
id: "otherUserId",
firstName: "firstname",
lastName: "lastname",
role: RoleName.Teacher,
},
{
id: "otherUserId1",
firstName: "firstname1",
lastName: "lastname1",
role: RoleName.Teacher,
},
{
id: "otherUserId2",
firstName: "firstname2",
lastName: "lastname2",
role: RoleName.Teacher,
},
],
});

wrapper.getComponent(GroupSelectionDialog).vm.$emit("confirm", group);
await nextTick();

return {
wrapper,
notifierModule,
group,
};
};

it("should display the correct warning in the confirmation dialog", async () => {
const { wrapper } = await setup();

const text = wrapper.find("[data-testid=no-teacher-warning-text]");

expect(text.text()).toEqual(
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userInGroupWarning"
);
});
});

describe("when the user is not part of the selected group and course teacher are not part of group", () => {
const setup = async () => {
const { wrapper, notifierModule } = getWrapper(
{
isOpen: true,
courseId: "courseId",
courseName: "courseName",
courseTeachers: ["Firstname Lastname", "another teacher"],
},
meResponseFactory.build({
roles: [{ id: "0", name: RoleName.Administrator }],
})
);

const group = groupResponseFactory.build({
users: [
{
id: "otherUserId",
firstName: "Firstname",
lastName: "Lastname",
role: RoleName.Teacher,
},
],
});

wrapper.getComponent(GroupSelectionDialog).vm.$emit("confirm", group);
await nextTick();

return {
wrapper,
notifierModule,
group,
};
};

it("should display the correct warning in the confirmation dialog", async () => {
const { wrapper } = await setup();

const text = wrapper.find("[data-testid=no-teacher-warning-text]");

expect(text.text()).toEqual(
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userNotInGroupWarning"
);
});
});
});
30 changes: 28 additions & 2 deletions src/modules/feature/course-sync/StartExistingCourseSyncDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@

<script setup lang="ts">
import VCustomDialog from "@/components/organisms/vCustomDialog.vue";
import { GroupResponse, GroupUserResponse, MeResponse } from "@/serverApi/v3";
import {
GroupResponse,
GroupUserResponse,
MeResponse,
RoleName,
} from "@/serverApi/v3";
import type AuthModule from "@/store/auth";
import {
AUTH_MODULE_KEY,
Expand All @@ -69,6 +74,9 @@ const props = defineProps({
courseId: {
type: String,
},
courseTeachers: {
type: Array,
},
});
const isOpen: ModelRef<boolean> = defineModel("isOpen", {
Expand Down Expand Up @@ -98,9 +106,27 @@ const isUserInGroup = computed(() => {
return false;
}
return selectedGroup.value.users.some(
const isPartOfGroup: boolean = selectedGroup.value.users.some(
(user: GroupUserResponse) => user.id === me.user.id
);
const isAdmin: boolean = me.roles.some(
(role) => role.name === RoleName.Administrator
);
if (isAdmin && !isPartOfGroup) {
const allCourseTeacherPartOfGroup = props.courseTeachers?.every(
(teacher) => {
return selectedGroup.value?.users.some(
(user) => user.firstName + " " + user.lastName === teacher
);
}
);
return allCourseTeacherPartOfGroup;
} else {
return isPartOfGroup;
}
});
const onConfirmWarning = async () => {
Expand Down
1 change: 1 addition & 0 deletions src/pages/administration/RoomsOverview.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
v-model:is-open="isCourseSyncDialogOpen"
:course-id="selectedItem?.id"
:course-name="selectedItem?.name"
:course-teachers="selectedItem?.teacherNames"
@success="onConfirmSynchronizeCourse"
data-testid="start-sync-dialog"
/>
Expand Down

0 comments on commit eb6da01

Please sign in to comment.