forked from oppia/oppia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce CurrentInteractionService * Add preSubmitHooks * remove extra files introduced in merge conflict resolution * oppia#2584-When adding a Link to a lesson, example URL is now a placeholder instead of default text * Fix merge conflicts * Remove accidental change to rich_text_components_definitions.js * training * solution editor fix * Address other issues * Handle case where NumberWithUnits form is not defined * Add test and address comments * Add test * Address comments
- Loading branch information
1 parent
26b53cf
commit bd5a4d9
Showing
37 changed files
with
424 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
core/templates/dev/head/pages/exploration_player/CurrentInteractionService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2018 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Facilitates communication between the current interaction | ||
* and the progress nav. The former holds data about the learner's answer, | ||
* while the latter contains the actual "Submit" button which triggers the | ||
* answer submission process. | ||
*/ | ||
|
||
oppia.factory('CurrentInteractionService', [ | ||
function() { | ||
var _submitAnswerFn = null; | ||
var _onSubmitFn = null; | ||
var _validityCheckFn = null; | ||
var _presubmitHooks = []; | ||
|
||
return { | ||
setOnSubmitFn: function(onSubmit) { | ||
/** | ||
* The ConversationSkinDirective should register its onSubmit | ||
* callback here. | ||
* | ||
* @param {function(answer, interactionRulesService)} onSubmit | ||
*/ | ||
_onSubmitFn = onSubmit; | ||
}, | ||
registerCurrentInteraction: function(submitAnswerFn, validityCheckFn) { | ||
/** | ||
* Each interaction directive should call registerCurrentInteraction | ||
* when the interaction directive is first created. | ||
* | ||
* @param {function|null} submitAnswerFn - Should grab the learner's | ||
* answer and pass it to onSubmit. The interaction can pass in | ||
* null if it does not use the progress nav's submit button | ||
* (ex: MultipleChoiceInput). | ||
* @param {function} validityCheckFn - The progress nav will use this | ||
* to decide whether or not to disable the submit button. If the | ||
* interaction passes in null, the submit button will remain | ||
* enabled (for the entire duration of the current interaction). | ||
*/ | ||
_submitAnswerFn = submitAnswerFn || null; | ||
_validityCheckFn = validityCheckFn || null; | ||
}, | ||
registerPresubmitHook: function(hookFn) { | ||
/* Register a hook that will be called right before onSubmit. | ||
* All hooks for the current interaction will be cleared right | ||
* before loading the next card. | ||
*/ | ||
_presubmitHooks.push(hookFn); | ||
}, | ||
clearPresubmitHooks: function() { | ||
/* Clear out all the hooks for the current interaction. Should | ||
* be called before loading the next card. | ||
*/ | ||
_presubmitHooks = []; | ||
}, | ||
onSubmit: function(answer, interactionRulesService) { | ||
for (var i = 0; i < _presubmitHooks.length; i++) { | ||
_presubmitHooks[i](); | ||
} | ||
_onSubmitFn(answer, interactionRulesService); | ||
}, | ||
submitAnswer: function() { | ||
/* This starts the answer submit process, it should be called once the | ||
* learner presses the "Submit" button. | ||
*/ | ||
if (_submitAnswerFn === null) { | ||
throw Error('The current interaction did not ' + | ||
'register a _submitAnswerFn.'); | ||
} else { | ||
_submitAnswerFn(); | ||
} | ||
}, | ||
isSubmitButtonDisabled: function() { | ||
/* Returns whether or not the Submit button should be disabled based on | ||
* the validity of the current answer. If the interaction does not pass | ||
* in a _validityCheckFn, then _validityCheckFn will be null and by | ||
* default we assume the answer is valid, so the submit button should | ||
* not be disabled. | ||
*/ | ||
if (_validityCheckFn === null) { | ||
return false; | ||
} | ||
return !_validityCheckFn(); | ||
}, | ||
}; | ||
} | ||
]); |
89 changes: 89 additions & 0 deletions
89
core/templates/dev/head/pages/exploration_player/CurrentInteractionServiceSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2018 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Unit tests for CurrentInteractionService. | ||
*/ | ||
|
||
describe('Current Interaction Service', function() { | ||
beforeEach(module('oppia')); | ||
|
||
var DUMMY_ANSWER = 'dummy_answer'; | ||
|
||
var CurrentInteractionService; | ||
beforeEach(inject(function($injector) { | ||
CurrentInteractionService = $injector.get('CurrentInteractionService'); | ||
})); | ||
|
||
it('should properly register onSubmitFn and submitAnswerFn', function() { | ||
var answerState = null; | ||
var dummyOnSubmitFn = function(answer, interactionRulesService) { | ||
answerState = answer; | ||
}; | ||
|
||
CurrentInteractionService.setOnSubmitFn(dummyOnSubmitFn); | ||
CurrentInteractionService.onSubmit(DUMMY_ANSWER, null); | ||
expect(answerState).toEqual(DUMMY_ANSWER); | ||
|
||
answerState = null; | ||
var dummySubmitAnswerFn = function() { | ||
CurrentInteractionService.onSubmit(DUMMY_ANSWER, null); | ||
}; | ||
CurrentInteractionService.registerCurrentInteraction( | ||
dummySubmitAnswerFn, null); | ||
CurrentInteractionService.submitAnswer(); | ||
expect(answerState).toEqual(DUMMY_ANSWER); | ||
}); | ||
|
||
it('should properly register validityCheckFn', function() { | ||
var dummyValidityCheckFn = function() { | ||
return false; | ||
}; | ||
CurrentInteractionService.registerCurrentInteraction( | ||
null, dummyValidityCheckFn); | ||
expect(CurrentInteractionService.isSubmitButtonDisabled()).toBe( | ||
!dummyValidityCheckFn()); | ||
}); | ||
|
||
it('should handle case where validityCheckFn is null', function() { | ||
CurrentInteractionService.registerCurrentInteraction(null, null); | ||
expect(CurrentInteractionService.isSubmitButtonDisabled()).toBe(false); | ||
}); | ||
|
||
it('should properly register and clear presubmit hooks', function() { | ||
var hookStateA = 0; | ||
var hookStateB = 1; | ||
var hookA = function() { | ||
hookStateA = hookStateA + 1; | ||
}; | ||
var hookB = function() { | ||
hookStateB = hookStateB * 3; | ||
}; | ||
|
||
CurrentInteractionService.registerPresubmitHook(hookA); | ||
CurrentInteractionService.registerPresubmitHook(hookB); | ||
|
||
CurrentInteractionService.setOnSubmitFn(function() {}); | ||
CurrentInteractionService.onSubmit(null, null); | ||
|
||
expect(hookStateA).toEqual(1); | ||
expect(hookStateB).toEqual(3); | ||
|
||
CurrentInteractionService.clearPresubmitHooks(); | ||
CurrentInteractionService.onSubmit(null, null); | ||
|
||
expect(hookStateA).toEqual(1); | ||
expect(hookStateB).toEqual(3); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.