Add cypress test

This commit is contained in:
Daniel Egger 2024-09-27 18:11:40 +02:00
parent 804551b14b
commit 0aa7e74b7c
3 changed files with 153 additions and 2 deletions

View File

@ -301,11 +301,12 @@ const showPassed = computed(() => {
></ItSuccessAlert> ></ItSuccessAlert>
</div> </div>
<section class="mt-4"> <section class="mt-4" data-cy="assignment-history">
<div <div
v-for="historyEntry in props.assignmentCompletion.additional_json_data v-for="historyEntry in props.assignmentCompletion.additional_json_data
?.submission_history ?? []" ?.submission_history ?? []"
:key="historyEntry.timestamp" :key="historyEntry.timestamp"
data-cy="assignment-history-entry"
> >
{{ dayjs(historyEntry.timestamp).format("DD.MM.YYYY HH.mm") }}: {{ dayjs(historyEntry.timestamp).format("DD.MM.YYYY HH.mm") }}:
{{ $t(historyEntry.translation_key) }} {{ $t(historyEntry.translation_key) }}

View File

@ -0,0 +1,145 @@
import { TEST_STUDENT1_USER_ID, TEST_TRAINER1_USER_ID } from "../../consts";
import { EXPERT_COCKPIT_URL, login } from "../helpers";
describe("assignmentTrainer.cy.js", () => {
beforeEach(() => {
cy.manageCommand(
"cypress_reset --create-assignment-completion --create-assignment-evaluation",
);
login("test-trainer1@example.com", "test");
});
describe("Can reevaluation assignment", () => {
it("can start evaluation and store evaluation results", () => {
cy.visit(EXPERT_COCKPIT_URL);
cy.get(
'[data-cy="show-details-btn-test-lehrgang-lp-circle-fahrzeug-lc-überprüfen-einer-motorfahrzeug-versicherungspolice"]',
).click();
cy.get('[data-cy="Student1"]').find('[data-cy="show-results"]').click();
// on EvaluationSummary page
cy.get(
'[data-cy="assignment-history"] [data-cy="assignment-history-entry"]',
).should("have.length", 2);
cy.get('[data-cy="assignment-history"]')
.should("contain", "Ergebnisse abgegeben")
.should("contain", "Bewertung freigegeben");
cy.get('[data-cy="user-points"]').should("contain", "24");
cy.get('[data-cy="total-points"]').should("contain", "100%");
// reevaluation
cy.get('[data-cy="btn-reopen"]').click();
cy.get('[data-cy="evaluation-task"]').should(
"contain",
"Beurteilungskriterium 1 / 5",
);
cy.get('[data-cy="subtask-4"]').click();
cy.wait(500);
cy.get('[data-cy="next-step"]').click();
cy.get('[data-cy="evaluation-task"]').should(
"contain",
"Beurteilungskriterium 2 / 5",
);
cy.get('[data-cy="next-step"]').click();
cy.get('[data-cy="evaluation-task"]').should(
"contain",
"Beurteilungskriterium 3 / 5",
);
cy.get('[data-cy="subtask-4"]').click();
cy.wait(500);
cy.get('[data-cy="next-step"]').click();
cy.get('[data-cy="evaluation-task"]').should(
"contain",
"Beurteilungskriterium 4 / 5",
);
cy.get('[data-cy="subtask-2"]').click();
cy.wait(500);
cy.get('[data-cy="next-step"]').click();
cy.get('[data-cy="evaluation-task"]').should(
"contain",
"Beurteilungskriterium 5 / 5",
);
cy.get('[data-cy="next-step"]').click();
cy.get('[data-cy="user-points"]').should("contain", "19");
cy.get('[data-cy="total-points"]').should("contain", "79%");
cy.get('[data-cy="reason-text"]').type("nochmal bewertet");
cy.get(
'[data-cy="assignment-history"] [data-cy="assignment-history-entry"]',
).should("have.length", 3);
cy.get('[data-cy="assignment-history"]')
.should("contain", "Ergebnisse abgegeben")
.should("contain", "Bewertung freigegeben")
.should("contain", "Bewertung erneut bearbeitet");
cy.get('[data-cy="submit-evaluation"]').click();
// check stored data
cy.get('[data-cy="result-section"]').should(
"contain",
"Deine Bewertung für Test Student1 wurde freigegeben",
);
cy.reload();
cy.get(
'[data-cy="assignment-history"] [data-cy="assignment-history-entry"]',
).should("have.length", 4);
cy.loadAssignmentCompletion(
"evaluation_user_id",
TEST_TRAINER1_USER_ID,
).then((ac) => {
expect(ac.completion_status).to.equal("EVALUATION_SUBMITTED");
expect(ac.evaluation_points).to.equal(19);
expect(ac.completion_data.expert_evaluation_comment.text).to.equal(
"nochmal bewertet",
);
expect(ac.additional_json_data.submission_history).to.have.length(4);
expect(ac.additional_json_data.submission_history[0].status).to.equal(
"SUBMITTED",
);
expect(ac.additional_json_data.submission_history[1].status).to.equal(
"EVALUATION_SUBMITTED",
);
expect(ac.additional_json_data.submission_history[2].status).to.equal(
"EVALUATION_IN_PROGRESS",
);
expect(ac.additional_json_data.submission_history[3].status).to.equal(
"EVALUATION_SUBMITTED",
);
// check AssignmentCompletionAuditLog
cy.task(
"runSql",
`select * from assignment_assignmentcompletionauditlog
where assignment_slug = 'test-lehrgang-assignment-überprüfen-einer-motorfahrzeugs-versicherungspolice'
and assignment_user_id = '${TEST_STUDENT1_USER_ID}'
order by created_at asc;`,
).then((res) => {
console.log(res);
expect(res.rows).to.have.length(3);
expect(res.rows[0].completion_status).to.equal("SUBMITTED");
expect(res.rows[1].completion_status).to.equal(
"EVALUATION_SUBMITTED",
);
expect(res.rows[1].evaluation_points).to.equal(24);
expect(res.rows[2].completion_status).to.equal(
"EVALUATION_SUBMITTED",
);
expect(res.rows[2].evaluation_points).to.equal(19);
expect(res.rows[2].completion_data.expert_evaluation_comment.text).to.equal(
"nochmal bewertet",
);
});
});
});
});
});

View File

@ -6,7 +6,11 @@ from django.contrib.auth.hashers import make_password
from django.db import connection from django.db import connection
from django.utils import timezone from django.utils import timezone
from vbv_lernwelt.assignment.models import Assignment, AssignmentCompletion from vbv_lernwelt.assignment.models import (
Assignment,
AssignmentCompletion,
AssignmentCompletionAuditLog,
)
from vbv_lernwelt.competence.models import PerformanceCriteria from vbv_lernwelt.competence.models import PerformanceCriteria
from vbv_lernwelt.core.constants import ( from vbv_lernwelt.core.constants import (
TEST_COURSE_SESSION_BERN_ID, TEST_COURSE_SESSION_BERN_ID,
@ -183,6 +187,7 @@ def command(
CourseCompletion.objects.all().delete() CourseCompletion.objects.all().delete()
Notification.objects.all().delete() Notification.objects.all().delete()
AssignmentCompletion.objects.all().delete() AssignmentCompletion.objects.all().delete()
AssignmentCompletionAuditLog.objects.all().delete()
FeedbackResponse.objects.all().delete() FeedbackResponse.objects.all().delete()
CourseSessionAttendanceCourse.objects.all().update(attendance_user_list=[]) CourseSessionAttendanceCourse.objects.all().update(attendance_user_list=[])