Skip to content

Commit

Permalink
fix(FEC-13089): dispatch QuestionChanged event in onContinue flow whe…
Browse files Browse the repository at this point in the history
…n answer is the same (#84)

* fix(FEC-13089): dispatch QuestionChanged event in onContinue flow when answer is the same

* add tests
  • Loading branch information
lianbenjamin authored Apr 11, 2023
1 parent e5aeceb commit 0f03831
Show file tree
Hide file tree
Showing 9 changed files with 7,714 additions and 2 deletions.
171 changes: 171 additions & 0 deletions cypress/e2e/ivq-QuizQuestionChanged-event.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// @ts-ignore
import {core, KalturaPlayer} from 'kaltura-player-js';

const {EventManager} = core;
const MANIFEST = `#EXTM3U
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="en",NAME="English",AUTOSELECT=YES,DEFAULT=YES,URI="${location.origin}/media/index_1.m3u8",SUBTITLES="subs"
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=509496,RESOLUTION=480x272,AUDIO="audio",SUBTITLES="subs"
${location.origin}/media/index.m3u8`;

const preparePage = (ivqConf = {}, playerConf = {}) => {
cy.visit('index.html');
return cy.window().then(win => {
try {
// @ts-ignore
var kalturaPlayer = win.KalturaPlayer.setup({
targetId: 'player-placeholder',
provider: {
partnerId: -1,
env: {
cdnUrl: 'http://mock-cdn',
serviceUrl: 'http://mock-api'
}
},
...playerConf,
plugins: {
ivq: ivqConf
}
});
kalturaPlayer.loadMedia({entryId: '0_wifqaipd'});
} catch (e: any) {
console.error(e.message);
}
});
};

const checkRequest = (reqBody: any, service: string, action: string) => {
return reqBody?.service === service && reqBody?.action === action;
};

const mockQuiz = (quizFixture = 'quiz_welcome_page_disabled_with_attempt.json', cuesFixture = 'ivq_QuizQuestionChanged_event/cues_1_question.json') => {
cy.intercept('http://mock-api/service/multirequest', req => {
if (checkRequest(req.body[2], 'baseEntry', 'list')) {
return req.reply({fixture: 'base_entry.json'});
}
if (checkRequest(req.body[3], 'quiz_quiz', 'get')) {
return req.reply({fixture: quizFixture});
}
if (checkRequest(req.body[2], 'cuepoint_cuepoint', 'list')) {
if (req.body[2].filter.objectType === 'KalturaAnswerCuePointFilter') {
return req.reply({fixture: 'ivq_QuizQuestionChanged_event/quiz_answers.json'});
}
return req.reply({fixture: cuesFixture});
}
if (checkRequest(req.body[2], 'userEntry', 'add')) {
return req.reply({fixture: 'quiz_entry.json'});
}
if (checkRequest(req.body[2], 'userEntry', 'submitQuiz')) {
return req.reply({fixture: 'submit.json'});
}
if (checkRequest(req.body[2], 'cuepoint_cuepoint', 'add')) {
return req.reply({fixture: 'ivq_QuizQuestionChanged_event/add_cuepoint_response.json'});
}
});
};

const getPlayer = () => {
// @ts-ignore
return cy.window().then($win => $win.KalturaPlayer.getPlayers()['player-placeholder']);
};

const eventManager: any = new EventManager();

describe('IVQ plugin', () => {
beforeEach(() => {
// manifest
cy.intercept('GET', '**/a.m3u8*', MANIFEST);
// thumbnails
cy.intercept('GET', '**/width/164/vid_slices/100', {fixture: '100.jpeg'});
cy.intercept('GET', '**/height/360/width/640', {fixture: '640.jpeg'});
// kava
cy.intercept('GET', '**/index.php?service=analytics*', {});
});

afterEach(() => {
eventManager.removeAll();
});

describe('QuizQuestionChanged event', () => {
it('should dispatch QuizQuestionChanged event with Answered state after clicking on continue', done => {
mockQuiz();
preparePage({}, {playback: {autoplay: true}});
getPlayer().then(player => {
player.addEventListener('QuizQuestionChanged', (event: any) => {
expect(event.payload.qqa[0].state).to.equal(2);
done();
});
cy.get('[data-testid="continueButton"]', {timeout: 5000}).click({force: true});
});
});
it('should dispatch QuizQuestionChanged event with Correct state after submitting the quiz', done => {
mockQuiz();
preparePage({}, {playback: {autoplay: true}});
getPlayer().then(player => {
player.addEventListener('QuizQuestionChanged', (event: any) => {
expect(event.payload.qqa[0].state).to.equal(4);
done();
});
cy.get('[data-testid="continueButton"]').should('exist').click({force: true});
cy.get('[data-testid="ivqPopupSubmitButton"]', {timeout: 1000}).click({force: true});
});
});
it('should dispatch QuizQuestionChanged event with empty array', done => {
mockQuiz('ivq_QuizQuestionChanged_event/quiz_ban_seek_enabled.json');
preparePage({}, {playback: {autoplay: true}});
getPlayer().then(player => {
eventManager.listenOnce(player, 'QuizQuestionChanged', (event: any) => {
expect(event.payload.qqa.length).to.equal(0);
done();
});
});
});
it('should dispatch QuizQuestionChanged event with a non empty array, after clicking on continue', done => {
mockQuiz('ivq_QuizQuestionChanged_event/quiz_ban_seek_enabled.json');
preparePage({}, {playback: {autoplay: true}});
getPlayer().then(player => {
eventManager.listen(player, 'QuizQuestionChanged', (event: any) => {
expect(event.payload.qqa.length).to.equal(1);
done();
});
cy.get('[data-testid="continueButton"]').should('exist').click({force: true});
});
});
it('should dispatch QuizQuestionChanged event with Answered state after submission', done => {
mockQuiz('quiz_welcome_page_disabled.json');
preparePage({}, {playback: {autoplay: true}});
getPlayer().then(player => {
let counter = 0;
eventManager.listen(player, 'QuizQuestionChanged', (event: any) => {
expect(event.payload.qqa[0].state).to.equal(2);
counter++;
// the first time will come from onContinue- we want to make sure the state Answered (2) stays also after submission
if (counter === 2) {
done();
}
});
cy.get('[data-testid="continueButton"]').should('exist').click({force: true});
cy.get('[data-testid="ivqPopupSubmitButton"]').should('exist').click({force: true});
});
});
it('should dispatch QuizQuestionChanged event with Unanswered state after retake', done => {
mockQuiz('ivq_QuizQuestionChanged_event/quiz_multiple_attempts.json');
preparePage({}, {playback: {autoplay: true}});
getPlayer().then(player => {
let counter = 0;
eventManager.listen(player, 'QuizQuestionChanged', (event: any) => {
console.log(event.payload);
expect(event.payload.qqa[0].state).to.equal(1);
counter++;
// the first time will come from initializing the quiz- we want to make sure the state Unanswered (1) comes after retake
if (counter === 2) {
done();
}
});
cy.get('[data-testid="continueButton"]').should('exist').click({force: true});
cy.get('[data-testid="ivqPopupSubmitButton"]').should('exist').click({force: true});
cy.get('[data-testid="reviewRetakeButton"]').should('exist').click({force: true});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"partnerId": 1091,
"ks": "",
"userId": 0,
"objectType": "KalturaStartWidgetSessionResponse"
},
{
"parentId": "1_6zqqj2e6",
"quizUserEntryId": "3445745162",
"answerKey": "1",
"isCorrect": true,
"correctAnswerKeys": [
{
"value": "1",
"objectType": "KalturaString"
}
],
"id": "1_666",
"intId": 4808573692,
"cuePointType": "quiz.QUIZ_ANSWER",
"status": 1,
"entryId": "1_5q6uf02d",
"partnerId": 3188353,
"createdAt": 1680509431,
"updatedAt": 1680509431,
"startTime": 1100,
"userId": "[email protected]",
"isMomentary": true,
"objectType": "KalturaAnswerCuePoint"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"partnerId": 1091,
"ks": "",
"userId": 0,
"objectType": "KalturaStartWidgetSessionResponse"
},
{
"objects": [
{
"optionalAnswers": [
{"key": "1", "weight": 1, "isCorrect": true, "objectType": "KalturaOptionalAnswer"},
{"key": "2", "weight": 1, "isCorrect": false, "objectType": "KalturaOptionalAnswer"}
],
"question": "Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem.",
"questionType": 3,
"excludeFromScore": true,
"id": "1_6zqqj2e6",
"intId": 4799603282,
"cuePointType": "quiz.QUIZ_QUESTION",
"status": 1,
"entryId": "1_5q6uf02d",
"partnerId": 3188353,
"createdAt": 1679985724,
"updatedAt": 1679985724,
"startTime": 1000,
"userId": "[email protected]",
"isMomentary": true,
"objectType": "KalturaQuestionCuePoint"
}
],
"totalCount": 1,
"objectType": "KalturaCuePointListResponse"
},
{"objects": [], "totalCount": 0, "objectType": "KalturaCuePointListResponse"}
]
38 changes: 38 additions & 0 deletions cypress/fixtures/ivq_QuizQuestionChanged_event/quiz_answers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"partnerId": 1091,
"ks": "",
"userId": 0,
"objectType": "KalturaStartWidgetSessionResponse"
},
{
"objects": [
{
"parentId": "1_6zqqj2e6",
"quizUserEntryId": "3445745162",
"answerKey": "1",
"isCorrect": true,
"correctAnswerKeys": [
{
"value": "1",
"objectType": "KalturaString"
}
],
"id": "1_89vs9lmb",
"intId": 4810538262,
"cuePointType": "quiz.QUIZ_ANSWER",
"status": 1,
"entryId": "1_5q6uf02d",
"partnerId": 3188353,
"createdAt": 1680605159,
"updatedAt": 1680605159,
"startTime": 0,
"userId": "[email protected]",
"isMomentary": true,
"objectType": "KalturaAnswerCuePoint"
}
],
"totalCount": 1,
"objectType": "KalturaCuePointListResponse"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[
{
"partnerId": 1091,
"ks": "",
"userId": 0,
"objectType": "KalturaStartWidgetSessionResponse"
},
{
"objects": [
{
"version": 0,
"id": 875390275,
"entryId": "0_5n7s22ge",
"userId": "unmod",
"partnerId": 5174,
"status": 1,
"createdAt": 1671109941,
"updatedAt": 1671109941,
"type": "quiz.QUIZ",
"objectType": "KalturaQuizUserEntry"
}
],
"totalCount": 1,
"objectType": "KalturaUserEntryListResponse"
},
{
"version": 24,
"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": false,
"showCorrectAfterSubmission": false,
"allowDownload": false,
"showGradeAfterSubmission": false,
"attemptsAllowed": 88,
"scoreType": 3,
"objectType": "KalturaQuiz"
},
{"objects": [], "totalCount": 0, "objectType": "KalturaCuePointListResponse"}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[
{
"partnerId": 1091,
"ks": "",
"userId": 0,
"objectType": "KalturaStartWidgetSessionResponse"
},
{
"objects": [
{
"version": 0,
"id": 875390275,
"entryId": "0_5n7s22ge",
"userId": "unmod",
"partnerId": 5174,
"status": 1,
"createdAt": 1671109941,
"updatedAt": 1671109941,
"type": "quiz.QUIZ",
"objectType": "KalturaQuizUserEntry"
}
],
"totalCount": 1,
"objectType": "KalturaUserEntryListResponse"
},
{
"version": 24,
"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": "false", "objectType": "KalturaKeyValue"}
],
"allowAnswerUpdate": true,
"showCorrectAfterSubmission": true,
"allowDownload": false,
"showGradeAfterSubmission": true,
"attemptsAllowed": 88,
"scoreType": 3,
"objectType": "KalturaQuiz"
},
{"objects": [], "totalCount": 0, "objectType": "KalturaCuePointListResponse"}
]
Loading

0 comments on commit 0f03831

Please sign in to comment.