Skip to content

Commit

Permalink
Merge pull request #35 from reichlab/issue_34
Browse files Browse the repository at this point in the history
closes [make disclaimer optional #34]
  • Loading branch information
matthewcornell authored Nov 4, 2024
2 parents f269e27 + a106bc2 commit 7255517
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/predtimechart.bundle.js

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions src/predtimechart.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function _setSelectedTruths() {
* @param taskIdsKeys - array of options.task_ids keys. used to create task rows - one per task ID
* @private
*/
function _createUIElements($componentDiv, isUemEnabled, taskIdsKeys) {
function _createUIElements($componentDiv, isUemEnabled, taskIdsKeys, isDisclaimerPresent) {
//
// helper functions for creating for rows
//
Expand Down Expand Up @@ -195,7 +195,9 @@ function _createUIElements($componentDiv, isUemEnabled, taskIdsKeys) {
' </div>\n' +
'</div>'
);
$vizDiv.append($('<p class="forecastViz_disclaimer"><b><span id="disclaimer">(disclaimer here)</span></b></p>'));
if (isDisclaimerPresent) {
$vizDiv.append($('<p class="forecastViz_disclaimer"><b><span id="disclaimer">(disclaimer here)</span></b></p>'));
}
$vizDiv.append($('<div id="ploty_div" style="width: 100%; height: 72vh; position: relative;"></div>'));
$vizDiv.append($buttonsDiv);
$vizDiv.append($('<p style="text-align:center"><small>Note: You can navigate to forecasts from previous weeks with the left and right arrow keys</small></p>'));
Expand Down Expand Up @@ -379,7 +381,7 @@ const App = {
this.state.available_as_ofs = options['available_as_ofs'];
this.state.current_date = options['current_date'];
this.state.models = options['models'];
this.state.disclaimer = options['disclaimer'];
this.state.disclaimer = options['disclaimer']; // undefined if not present
this.state.colors = Array(parseInt(this.state.models.length / 10, 10) + 1).fill([
'#0d0887',
'#46039f',
Expand Down Expand Up @@ -429,8 +431,9 @@ const App = {

console.debug('initialize(): initializing UI');
const $componentDiv = $(componentDivEle);
_createUIElements($componentDiv, this.isUemEnabled, Object.keys(this.state.task_ids));
this.initializeUI(options['initial_task_ids']);
const isDisclaimerPresent = options.hasOwnProperty('disclaimer');
_createUIElements($componentDiv, this.isUemEnabled, Object.keys(this.state.task_ids), isDisclaimerPresent);
this.initializeUI(options['initial_task_ids'], isDisclaimerPresent);

// wire up UI controls (event handlers)
this.addEventHandlers();
Expand Down Expand Up @@ -527,7 +530,7 @@ const App = {
window.history.replaceState(newUrl.toString(), '', newUrl);
}
},
initializeUI(initial_task_ids) {
initializeUI(initial_task_ids, isDisclaimerPresent) {
// populate options and models list (left column)
this.initializeTargetVarsUI();
this.initializeTaskIDsUI(initial_task_ids);
Expand All @@ -539,7 +542,9 @@ const App = {
this.updateTruthAsOfCheckboxText();

// initialize disclaimer
$('#disclaimer').text(this.state.disclaimer);
if (isDisclaimerPresent) {
$('#disclaimer').text(this.state.disclaimer);
}

// initialize plotly (right column)
const plotyDiv = document.getElementById('ploty_div');
Expand Down
2 changes: 1 addition & 1 deletion src/schema-validator.cjs

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,5 @@
"additionalProperties": false
}
},
"required": ["available_as_ofs", "current_date", "disclaimer", "initial_as_of", "initial_checked_models",
"initial_interval", "initial_target_var", "initial_task_ids", "intervals", "models", "target_variables",
"task_ids"]}
"required": ["available_as_ofs", "current_date", "initial_as_of", "initial_checked_models", "initial_interval",
"initial_target_var", "initial_task_ids", "intervals", "models", "target_variables", "task_ids"]}
22 changes: 22 additions & 0 deletions test/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,25 @@ test('selectedTaskIDs() and selectedTaskIDValues() are correct', assert => {
// test selectedTaskIDValues()
assert.deepEqual(App.selectedTaskIDValues(), {"scenario_id": "1", "location": "48"});
});


//
// optional disclaimer tests
//

QUnit.module('optional disclaimer');

test('initialize() creates .forecastViz_disclaimer <P> only if disclaimer present', assert => {
// case 1: disclaimer is present
let optionsCopy = structuredClone(covid19ForecastsVizTestOptions);
App.initialize('qunit-fixture', _fetchData, true, optionsCopy, null);
let foundEles = document.getElementsByClassName('forecastViz_disclaimer');
assert.equal(foundEles.length, 1);

// case 1: disclaimer is missing
optionsCopy = structuredClone(covid19ForecastsVizTestOptions);
delete optionsCopy['disclaimer'];
App.initialize('qunit-fixture', _fetchData, true, optionsCopy, null);
foundEles = document.getElementsByClassName('forecastViz_disclaimer');
assert.equal(foundEles.length, 0);
});
8 changes: 8 additions & 0 deletions test/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@ test('options object missing', assert => {

test('options object blue sky', assert => {
// per https://stackoverflow.com/questions/9822400/how-to-assert-that-a-function-does-not-raise-an-exception

// case: description present
App.initialize('qunit-fixture', null, true, covid19ForecastsVizTestOptions, null);
assert.ok(true, "no Error raised");

// case: description missing
const optionsCopy = structuredClone(covid19ForecastsVizTestOptions);
delete optionsCopy['disclaimer'];
App.initialize('qunit-fixture', null, true, optionsCopy, null);
assert.ok(true, "no Error raised");
});


Expand Down

0 comments on commit 7255517

Please sign in to comment.