Skip to content

Commit

Permalink
FLUID-6176: Expanding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jobara committed Mar 29, 2018
1 parent 34ad1e1 commit 6a7b0b7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/textToSpeech/js/MockTTS.js
Expand Up @@ -50,7 +50,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
},
cancel: {
funcName: "fluid.mock.textToSpeech.cancel",
args: ["{that}", "{that}.events.utteranceOnEnd.fire"]
args: ["{that}"]
},
getVoices: {
funcName: "fluid.identity",
Expand Down
2 changes: 1 addition & 1 deletion src/framework/preferences/js/SelfVoicingEnactor.js
Expand Up @@ -322,7 +322,7 @@ var fluid_3_0_0 = fluid_3_0_0 || {};
var maxBoundary = parseQueue[maxIndex].blockIndex + parseQueue[maxIndex].word.length;


if (boundary < 0 || boundary > maxBoundary ) {
if (!fluid.isValue(boundary) || boundary < 0 || boundary > maxBoundary ) {
return undefined;
}

Expand Down
87 changes: 77 additions & 10 deletions tests/framework-tests/preferences/js/SelfVoicingEnactorTests.js
Expand Up @@ -328,12 +328,43 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
expectedText: [
{text: "{selfVoicing}.options.strings.welcomeMsg", interrupt: true},
{text: "Reading text from DOM", interrupt: false}
]
],
// a mock parseQueue for testing adding and removing the mark
parseQueue: [[{
"blockIndex": 0,
"childIndex": 0,
"endOffset": 20,
"node": {},
"parentNode": {
expander: {
"this": "{selfVoicing}.container",
method: "get",
args: [0]
}
},
"startOffset": 13,
"word": "Reading"
}, {
"blockIndex": 8,
"childIndex": 0,
"endOffset": 4,
"node": {},
"parentNode": {
expander: {
func: function (elm) {
return $(elm).children()[0];
},
args: ["{selfVoicing}.container"]
}
},
"startOffset": 0,
"word": "text"
}]]
},
modules: [{
name: "fluid.prefs.enactor.selfVoicing",
tests: [{
expect: 5,
expect: 15,
name: "Dom Reading",
sequence: [{
func: "{selfVoicing}.toggle",
Expand All @@ -348,6 +379,12 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
args: ["{selfVoicing}", "{that}.options.testOptions.expectedText"],
spec: {priority: "last:testing"},
event: "{selfVoicing}.tts.events.onStop"
}, {
funcName: "jqUnit.assertEquals",
args: ["The parseQueue should be empty.", 0, "{selfVoicing}.parseQueue.length"]
}, {
funcName: "jqUnit.assertEquals",
args: ["The parseIndex should be reset to 0.", 0, "{selfVoicing}.parseIndex"]
}, {
funcName: "jqUnit.assertNodeNotExists",
args: ["The self voicing has completed. All marks should be removed.", "{selfVoicing}.dom.mark"]
Expand All @@ -357,19 +394,43 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
}, {
funcName: "jqUnit.assertNodeNotExists",
args: ["The parseQueue is empty, so no mark should be added", "{selfVoicing}.dom.mark"]
}, {
// manually add items to parseQueue so that we can more easily test adding and removing the mark
funcName: "fluid.set",
args: ["{selfVoicing}", ["parseQueue"], "{that}.options.testOptions.parseQueue"]
}, {
func: "{selfVoicing}.tts.events.utteranceOnBoundary.fire",
args: [{charIndex: "{that}.options.testOptions.parseQueue.0.0.blockIndex"}]
}, {
funcName: "fluid.tests.selfVoicingTester.verifyMark",
args: ["{selfVoicing}.dom.mark", "{that}.options.testOptions.parseQueue.0.0.word"]
}, {
func: "{selfVoicing}.tts.events.utteranceOnBoundary.fire",
args: [{charIndex: "{that}.options.testOptions.parseQueue.0.1.blockIndex"}]
}, {
funcName: "fluid.tests.selfVoicingTester.verifyMark",
args: ["{selfVoicing}.dom.mark", "{that}.options.testOptions.parseQueue.0.1.word"]
}, {
// disabled text to speech
func: "{selfVoicing}.applier.change",
args: ["enabled", false]
}, {
listener: "jqUnit.assert",
args: ["The utteranceOnEnd event should have fired"],
spec: {priority: "last:testing"},
event: "{selfVoicing}.tts.events.utteranceOnEnd"
}, {
// test readFromDom if the element to parse isn't available
funcName: "fluid.prefs.enactor.selfVoicing.readFromDOM",
args: ["{selfVoicing}", "{selfVoicing}.dom.mark"]
}, {
funcName: "jqUnit.assertEquals",
args: ["The parseQueue should still be empty after trying to parse an unavailable DOM node.", 0, "{selfVoicing}.parseQueue.length"]
}]
}]
}]
});

//TODO: Add tests for the following
// - highlight
// - mark added (need to directly add items to the parseQueue first)
// - correct word highlighted
// - mark removed
// - handleSelfVoicing when speech disabled
// - readFromDOM when element length is 0

fluid.tests.selfVoicingTester.verifySpeakQueue = function (that, expectedText) {
jqUnit.assertDeepEq("The text to be spoken should have been queued correctly", expectedText, that.tts.speechRecord);
};
Expand All @@ -379,6 +440,12 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
jqUnit.assertDeepEq("The parseQueue should have been populated correctly", expected, that.parseQueue);
};

fluid.tests.selfVoicingTester.verifyMark = function (elm, expectedText) {
jqUnit.assertNodeExists("The mark should have been added", elm);
jqUnit.assertEquals("Only one mark should be present", 1, elm.length);
jqUnit.assertEquals("The marked textnode should be correct", elm.text(), expectedText);
};

$(document).ready(function () {
fluid.test.runTests([
"fluid.tests.speakTests",
Expand Down

0 comments on commit 6a7b0b7

Please sign in to comment.