Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes this import question and states for tutorial #86

Open
wants to merge 2 commits into
base: dev/1.2.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions src/controllers/ctl-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const ControllerThisOrThatCreator = function($scope, $timeout, $sanitize,
$scope.tutorial = {
checked: false,
step: 1,
cachedStep:1,
text: [
'Enter a question',
'Pick the answer type',
Expand Down Expand Up @@ -154,6 +155,7 @@ export const ControllerThisOrThatCreator = function($scope, $timeout, $sanitize,
}
},
isValid: true,
isImported: true, //track if imported to disable tutorial
id: item.id
})

Expand All @@ -167,8 +169,9 @@ export const ControllerThisOrThatCreator = function($scope, $timeout, $sanitize,
else $scope.questions[$scope.questions.length-1].incorrect.videoValid = false
}
}

$scope.currIndex = 0
//navigate to the imported question
const newIndex = $scope.questions.length - 1;
_updateIndex('select', newIndex);
$scope.$apply()
}

Expand All @@ -191,27 +194,54 @@ export const ControllerThisOrThatCreator = function($scope, $timeout, $sanitize,
})()

const _updateIndex = function(action, data) {
let updatedIndex = $scope.currIndex;
switch (action) {
//if we go to an imported question, disable the tutorial
case 'prev':
if ($scope.currIndex > 0) {
return $scope.currIndex--
updatedIndex = $scope.currIndex-1;
break;
} else {
return ($scope.currIndex = $scope.questions.length - 1)
updatedIndex = $scope.questions.length - 1;
break;
}
//if we go to an imported question, disable the tutorial
case 'next':
if ($scope.currIndex < $scope.questions.length - 1) {
return $scope.currIndex++
updatedIndex = $scope.currIndex+1;
break;
} else {
return ($scope.currIndex = 0)
updatedIndex = 0;
break;
}
case 'select':
return ($scope.currIndex = data)
updatedIndex = data;
break;
case 'add':
$scope.questions.push(data)
return ($scope.currIndex = $scope.questions.length - 1)
updatedIndex = $scope.questions.length - 1;
$scope.tutorial.checked = true;
break;
case 'remove':
return $scope.currIndex--
updatedIndex = $scope.currIndex-1;
break;
}
//bounds check
if (updatedIndex < 0 || updatedIndex >= $scope.questions.length) {
updatedIndex = Math.max(0, $scope.questions.length - 1);
}
//set tutorial visibility based on whether the current question is imported or if the tutorial has been completed
if ($scope.questions[updatedIndex]?.isImported) {
// disable tutorial if navigating to an imported question
$scope.tutorial.step = null;
} else if ($scope.tutorial.checked) {
//tutorial has been completed
$scope.tutorial.step = null;
} else {
$scope.tutorial.step = $scope.tutorial.cachedStep || 1;
}
$scope.currIndex = updatedIndex;
return updatedIndex;
}

const _copyQuestion = function(original) {
Expand Down Expand Up @@ -549,9 +579,12 @@ export const ControllerThisOrThatCreator = function($scope, $timeout, $sanitize,
if (step >= $scope.tutorial.step)
{
if (step == 9) {
$scope.tutorial.checked = true;
return $scope.tutorial.step = null
}
else {
//have a cached step incase we go to another question but dont finish the tutorial
$scope.tutorial.cachedStep = $scope.tutorial.step+2;
return $scope.tutorial.step = step + 1
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/controllers/ctl-scoreScreen.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const ControllerThisOrThatScorescreen = function($scope, $sce) {

$scope.items = []

const materiaCallbacks = {}

const getHeight = () => Math.ceil(parseFloat(window.getComputedStyle(document.querySelector('html')).height))
Expand All @@ -12,13 +12,16 @@ export const ControllerThisOrThatScorescreen = function($scope, $sce) {
}
return -1
}
if (typeof global !== 'undefined') {
global.getQuestionIndex = getQuestionIndex
}

const getIndividualScoreDeduction = (table) => {
let numIncorrect = 0
table.forEach(item => {
if (item.score < 100) numIncorrect++
})

let overallDeduction = numIncorrect / table.length
return parseInt((overallDeduction / numIncorrect) * 100)
}
Expand Down Expand Up @@ -71,6 +74,6 @@ export const ControllerThisOrThatScorescreen = function($scope, $sce) {
}

Materia.ScoreCore.hideResultsTable()

return Materia.ScoreCore.start(materiaCallbacks)
}
}
48 changes: 48 additions & 0 deletions src/creator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,4 +881,52 @@ describe('Creator Controller', function() {

})

test('should set tutorial.step to cachedStep or 1 if tutorial is not checked and question is not imported', () => {
const $scope = {
currIndex: 0,
questions: [
{ isImported: false },
{ isImported: false }
],
tutorial: {
checked: false,
cachedStep: 2,
step: null,
},
}

const _updateIndex = function(action, data) {
let updatedIndex = $scope.currIndex
switch (action) {
case 'next':
if ($scope.currIndex < $scope.questions.length - 1) {
updatedIndex = $scope.currIndex + 1
} else {
updatedIndex = 0
}
break
}

if (updatedIndex < 0 || updatedIndex >= $scope.questions.length) {
updatedIndex = Math.max(0, $scope.questions.length - 1)
}

if ($scope.questions[updatedIndex]?.isImported) {
$scope.tutorial.step = null
} else if ($scope.tutorial.checked) {
$scope.tutorial.step = null
} else {
$scope.tutorial.step = $scope.tutorial.cachedStep || 1
}

$scope.currIndex = updatedIndex
return updatedIndex
}

_updateIndex('next')

expect($scope.currIndex).toBe(1)
expect($scope.tutorial.step).toBe(2)
})

})
44 changes: 43 additions & 1 deletion src/scoreScreen.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,47 @@ describe('Score Screen Controller', function() {
expect($scope.items[1].deduction).toBe(50)
})

test('should return -1 when question ID is not found in qset', () => {
const testQset = {
items: [
{ id: '1', questions: [{ text: 'Question 1' }] },
{ id: '2', questions: [{ text: 'Question 2' }] }
]
}

expect(global.getQuestionIndex(testQset, 'nonexistent_id')).toBe(-1)
expect(global.getQuestionIndex(testQset, '1')).toBe(0)
expect(global.getQuestionIndex(testQset, '2')).toBe(1)
})


test('should fetch media URL for left asset when value is missing', () => {
// Modify the qset for the test case
qset.items[0].answers[0].options.asset.value = null

publicMethods.start({}, qset, scoreTable, false, 1)
expect($scope.items[0].left.asset.value).toBe(
`MEDIA_URL/assets/img/demo/the_fall_of_phaeton.jpg`
)
})

test('should trust mp3 URL for right asset when type is video/mp3 file', () => {
publicMethods.start({}, qset, scoreTable, false, 1)
expect($scope.items[1].right.asset.value).toBe(
'MEDIA_URL/birds.mp3'
)
})
test('should recieve trusted object for video', () => {
qset.items[1].answers[1].options.asset.type = 'video'
qset.items[1].answers[1].options.asset.value = 'https://materia.com/video.mp4'

publicMethods.start({}, qset, scoreTable, false, 1)

expect($scope.items[1].right.asset.value).toEqual(
expect.objectContaining({
$$unwrapTrustedValue: expect.any(Function)
})
)
})

})
})
13 changes: 4 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3098,15 +3098,10 @@ caniuse-api@^3.0.0:
lodash.memoize "^4.1.2"
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001538, caniuse-lite@^1.0.30001541:
version "1.0.30001554"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001554.tgz#ba80d88dff9acbc0cd4b7535fc30e0191c5e2e2a"
integrity sha512-A2E3U//MBwbJVzebddm1YfNp7Nud5Ip+IPn4BozBmn4KqVX7AvluoIDFWjsv5OkGnKUXQVmMSoMKLa3ScCblcQ==

caniuse-lite@^1.0.30001449:
version "1.0.30001487"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001487.tgz#d882d1a34d89c11aea53b8cdc791931bdab5fe1b"
integrity sha512-83564Z3yWGqXsh2vaH/mhXfEM0wX+NlBCm1jYHOb97TrTWJEmPTccZgeLTPBUUb0PNVo+oomb7wkimZBIERClA==
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001449, caniuse-lite@^1.0.30001538, caniuse-lite@^1.0.30001541:
version "1.0.30001680"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001680.tgz"
integrity sha512-rPQy70G6AGUMnbwS1z6Xg+RkHYPAi18ihs47GH0jcxIG7wArmPgY3XbS2sRdBbxJljp3thdT8BIqv9ccCypiPA==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down
Loading