forked from vernondcole/formhub
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added check for notes while building question list plus its js test - f…
…ixes SEL-Columbia#677
- Loading branch information
Showing
6 changed files
with
114 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var QuestionData = [ | ||
{ | ||
name: 'group_one', | ||
type: 'group', | ||
label: 'A Group', | ||
children: [ | ||
{ | ||
name: 'note_one', | ||
type: 'group', | ||
label: 'A Note', | ||
children: [ | ||
{ | ||
name: 'a_question', | ||
type: 'text', | ||
label: 'A Question' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
]; | ||
var questions = {}; |
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,15 @@ | ||
EnvJasmine.load(EnvJasmine.mocksDir + "instance_view.mock.js"); | ||
EnvJasmine.load(EnvJasmine.jsDir + "main/static/js/underscore-min.js"); | ||
EnvJasmine.load(EnvJasmine.mocksDir + "../utils.js"); | ||
EnvJasmine.load(EnvJasmine.jsDir + "odk_viewer/static/js/instance.js"); | ||
|
||
describe("Instance View tests", function() { | ||
it("checks that parseQuestions builds hierachy's as expected", function() { | ||
expect(QuestionData).toBeDefined(); | ||
expect(questions).toBeDefined(); | ||
parseQuestions(QuestionData); | ||
// must only have one question | ||
expect(Object.size(questions)).toEqual(1); | ||
expect(questions['note_one_a_question']).toBeDefined(); | ||
}); | ||
}); |
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,8 @@ | ||
// get size of an object | ||
Object.size = function(obj) { | ||
var size = 0, key; | ||
for (key in obj) { | ||
if (obj.hasOwnProperty(key)) size++; | ||
} | ||
return size; | ||
}; |
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,51 @@ | ||
Question = function(questionData) | ||
{ | ||
this.name = questionData.name; | ||
this.type = questionData.type; | ||
this.label = questionData.label; | ||
} | ||
|
||
Question.prototype.getLabel = function(language) | ||
{ | ||
/// if plain string, return | ||
if(typeof(this.label) == "string") | ||
return this.label; | ||
else if(typeof(this.label) == "object") | ||
{ | ||
if(language && this.label.hasOwnProperty(language)) | ||
return this.label[language]; | ||
else | ||
{ | ||
var label = null; | ||
for(key in this.label) | ||
{ | ||
label = this.label[key]; | ||
break;// break at first instance and return that | ||
} | ||
return label; | ||
} | ||
|
||
} | ||
// return raw name | ||
return this.name; | ||
} | ||
|
||
function parseQuestions(children, prefix, cleanReplacement) | ||
{ | ||
var idx; | ||
cleanReplacement = typeof cleanReplacement !== 'undefined' ? cleanReplacement : '_'; | ||
|
||
for(idx in children) | ||
{ | ||
var question = children[idx]; | ||
if(question.hasOwnProperty('children') && (question.type == "group" || question.type == "note")) | ||
{ | ||
parseQuestions(question.children, (question.name + cleanReplacement)); | ||
} | ||
else | ||
{ | ||
// TODO: question class that has accessor mesthods for type, label, language etc | ||
questions[((prefix?prefix:'') + question.name)] = new Question(question); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./js_tests/EnvJasmine/bin/run_all_tests.sh --testDir=../ --configFile=../env_jasmine.conf.js |