Skip to content

Commit

Permalink
feat(FEC-13597): add the ability to seek for submitted quiz (#115)
Browse files Browse the repository at this point in the history
add the ability to seek in a case where a user has submitted a quiz, that is configured with no retake and banSeek is enabled.

Solves [FEC-13597](https://kaltura.atlassian.net/browse/FEC-13597)

[FEC-13597]: https://kaltura.atlassian.net/browse/FEC-13597?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
lianbenjamin authored Jan 8, 2024
1 parent 8c6b65d commit 1bff02b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
25 changes: 25 additions & 0 deletions cypress/e2e/ivq.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,29 @@ describe('IVQ plugin', () => {
});
});
});

describe('quiz seek functionality', () => {
it('should prevent seek', () => {
mockKalturaBe('ivq_QuizQuestionChanged_event/quiz_ban_seek_enabled.json');
loadPlayer({}, {autoplay: true}).then(player => {
player.pause();
player.currentTime = 15;
cy.get('.playkit-time-display > span').should($div => {
expect($div.text()).to.not.contain('00:15');
});
});
});

it('should allow seek to submitted quiz', () => {
mockKalturaBe('quiz_ban_seek_no_retake.json');
loadPlayer({}, {autoplay: true}).then(player => {
player.pause();
cy.get('[data-testid="ivqPopupRoot"]').should('exist');
player.currentTime = 15;
cy.get('.playkit-time-display > span').should($div => {
expect($div.text()).to.contain('00:15');
});
});
});
});
});
47 changes: 47 additions & 0 deletions cypress/fixtures/quiz_ban_seek_no_retake.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[
{
"partnerId": 1091,
"ks": "",
"userId": 0,
"objectType": "KalturaStartWidgetSessionResponse"
},
{
"objects": [
{
"score": 1,
"calculatedScore": 1,
"version": 0,
"id": 4184809572,
"entryId": "1_y8dwntss",
"userId": "lian.binyamin@kaltura.com",
"partnerId": 3188353,
"status": "quiz.3",
"createdAt": 1704187674,
"updatedAt": 1704187756,
"type": "quiz.QUIZ",
"objectType": "KalturaQuizUserEntry"
}
],
"totalCount": 1,
"objectType": "KalturaUserEntryListResponse"
},
{
"version": 4,
"uiAttributes": [
{"key": "welcomeMessage", "value": "In this video, you will be given a Quiz. Good Luck!", "objectType": "KalturaKeyValue"},
{"key": "noSeekAlertText", "value": "", "objectType": "KalturaKeyValue"},
{"key": "inVideoTip", "value": "true", "objectType": "KalturaKeyValue"},
{"key": "showWelcomePage", "value": "false", "objectType": "KalturaKeyValue"},
{"key": "canSkip", "value": "true", "objectType": "KalturaKeyValue"},
{"key": "banSeek", "value": "true", "objectType": "KalturaKeyValue"}
],
"allowAnswerUpdate": true,
"showCorrectAfterSubmission": true,
"allowDownload": true,
"showGradeAfterSubmission": true,
"attemptsAllowed": 0,
"scoreType": 3,
"objectType": "KalturaQuiz"
},
{"objects": [], "totalCount": 0, "objectType": "KalturaCuePointListResponse"}
]
4 changes: 2 additions & 2 deletions src/data-sync-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ export class DataSyncManager {
this._quizAnswers = quizAnswers;
};

public initDataManager = () => {
public initDataManager = (allowSeek: boolean) => {
if (!this.quizData || !this.quizUserEntry) {
this._logger.warn('initDataManager: quizData or quizUserEntry absent');
return;
}
if (this.quizData.preventSeek) {
if (this.quizData.preventSeek && !allowSeek) {
this._enableSeekControl();
}
this._syncEvents();
Expand Down
9 changes: 7 additions & 2 deletions src/ivq.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ export class Ivq extends KalturaPlayer.core.BasePlugin {
setQuizUserEntry(lastQuizUserEntry);
}
this._manageWelcomeScreen();
let allowSeek = false;
if (!lastQuizUserEntry || (isQuizSubmitted() && isRetakeAllowed())) {
// in case if quiz attempt doesn't exist
// OR user has more attempts and latest attempt submitted - create new quiz attempt.
Expand All @@ -438,15 +439,19 @@ export class Ivq extends KalturaPlayer.core.BasePlugin {
// for new quiz attempt answers should be empty;
setQuizAnswers([]);
setQuizUserEntry(quizNewUserEntry);
this._dataManager.initDataManager();
this._dataManager.initDataManager(allowSeek);
}
});
} else if (lastQuizUserEntry && isQuizSubmitted() && !isRetakeAllowed()) {
// in case the quiz was already submitted by the same user and retake is not allowed,
// set allowSeek to true, so the data manager will not disable the seek functionality.
allowSeek = true;
}
// set answers for last quiz attempt
if (quizAnswers) {
setQuizAnswers(quizAnswers);
}
this._dataManager.initDataManager();
this._dataManager.initDataManager(allowSeek);
}
})
.catch((e: any) => {
Expand Down

0 comments on commit 1bff02b

Please sign in to comment.