Skip to content

Commit

Permalink
Merge pull request #34012 from dimagi/jls/web-apps-spec-toggle-depend…
Browse files Browse the repository at this point in the history
…encies

Web apps tests: make toggle dependencies explicit
  • Loading branch information
orangejenny committed Jan 24, 2024
2 parents 2becc26 + 6ed39a7 commit 3e5e386
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ hqDefine("cloudcare/js/form_entry/spec/entries_spec", function () {
);
});

after(function () {
hqImport("hqwebapp/js/initial_page_data").unregister("toggles_dict");
});

beforeEach(function () {
window.MAPBOX_ACCESS_TOKEN = 'xxx';
questionJSON = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ hqDefine("cloudcare/js/form_entry/spec/form_ui_spec", function () {
repeatJSON,
repeatNestJSON;

before(function () {
hqImport("hqwebapp/js/initial_page_data").register(
"toggles_dict",
{
WEB_APPS_UPLOAD_QUESTIONS: true,
WEB_APPS_ANCHORED_SUBMIT: false,
}
);
});

after(function () {
hqImport("hqwebapp/js/initial_page_data").unregister("toggles_dict");
});

beforeEach(function () {
questionJSON = fixtures.selectJSON();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ hqDefine("cloudcare/js/form_entry/spec/integration_spec", function () {
questionJSONMulti,
questionJSONString;

before(function () {
hqImport("hqwebapp/js/initial_page_data").register("toggles_dict", { WEB_APPS_ANCHORED_SUBMIT: false });
});

after(function () {
hqImport("hqwebapp/js/initial_page_data").unregister("toggles_dict");
});

beforeEach(function () {
questionJSONMulti = {
"caption_audio": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ hqDefine("cloudcare/js/form_entry/spec/utils_spec", function () {
* groupInRepeat
* textInRepeat
*/
hqImport("hqwebapp/js/initial_page_data").register("toggles_dict", { WEB_APPS_ANCHORED_SUBMIT: false });
var text = fixtures.textJSON({ix: "0"}),
textInGroup = fixtures.textJSON({ix: "1,0"}),
group = fixtures.groupJSON({ix: "1", children: [textInGroup]}),
Expand All @@ -52,6 +53,8 @@ hqDefine("cloudcare/js/form_entry/spec/utils_spec", function () {

assert.equal(utils.getBroadcastContainer(text), form);
assert.equal(utils.getBroadcastContainer(textInRepeat), groupInRepeat);

hqImport("hqwebapp/js/initial_page_data").unregister("toggles_dict");
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ hqDefine("cloudcare/js/form_entry/spec/web_form_session_spec", function () {
var constants = hqImport("cloudcare/js/form_entry/const"),
formUI = hqImport("cloudcare/js/form_entry/form_ui");

before(function () {
hqImport("hqwebapp/js/initial_page_data").register("toggles_dict", { WEB_APPS_ANCHORED_SUBMIT: false });
});

after(function () {
hqImport("hqwebapp/js/initial_page_data").unregister("toggles_dict");
});

describe('TaskQueue', function () {
var callCount,
flag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ hqDefine("cloudcare/js/formplayer/spec/menu_list_spec", function () {
sinon.stub(Utils, 'getCurrentQueryInputs').callsFake(function () { return {}; });
});

after(function () {
hqImport("hqwebapp/js/initial_page_data").unregister("toggles_dict");
});

describe('#getMenuView', function () {
let FormplayerFrontend = hqImport("cloudcare/js/formplayer/app"),
server,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ hqDefine("cloudcare/js/formplayer/spec/query_spec", function () {
const QueryListView = hqImport("cloudcare/js/formplayer/menus/views/query");
const Utils = hqImport("cloudcare/js/formplayer/utils/utils");

hqImport("hqwebapp/js/initial_page_data").register("toggles_dict", { DYNAMICALLY_UPDATE_SEARCH_RESULTS: false });

const QueryViewModel = Backbone.Model.extend();
const QueryViewCollection = Backbone.Collection.extend();
const keyModel = new QueryViewModel({
Expand All @@ -34,6 +36,10 @@ hqDefine("cloudcare/js/formplayer/spec/query_spec", function () {
keyQueryView = new childViewConstructor({ parentView: keyQueryListView, model: keyModel});
});

after(function () {
hqImport("hqwebapp/js/initial_page_data").unregister("toggles_dict");
});

it('should create dictionary with either keys', function () {
const expectedKeyItemsetChoicesDict = { "CA": "California", "MA": "Massachusetts", "FL": "Florida"};
assert.deepEqual(expectedKeyItemsetChoicesDict, keyQueryView.model.get("itemsetChoicesDict"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ hqDefine("cloudcare/js/formplayer/spec/utils_spec", function () {
describe('CloudcareUrl', function () {
let stubs = {};

before(function () {
hqImport("hqwebapp/js/initial_page_data").register("toggles_dict", {
SPLIT_SCREEN_CASE_SEARCH: false,
DYNAMICALLY_UPDATE_SEARCH_RESULTS: false,
});
});

after(function () {
hqImport("hqwebapp/js/initial_page_data").unregister("toggles_dict");
});

beforeEach(function () {
let currentUrl = new Utils.CloudcareUrl({appId: 'abc123'});

Expand Down
12 changes: 12 additions & 0 deletions corehq/apps/hqwebapp/static/hqwebapp/js/initial_page_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ hqDefine('hqwebapp/js/initial_page_data', ['jquery', 'underscore'], function ($,
_initData[name] = value;
};

/*
* Remove item from initial page data.
* Useful for mocha test cleanup.
*/
var unregister = function (name) {
if (_initData[name] === undefined) {
throw new Error("Could not unregister initial page data: " + name);
}
delete _initData[name];
};

// http://stackoverflow.com/a/21903119/240553
var getUrlParameter = function (param) {
return getUrlParameterFromString(param, window.location.search);
Expand Down Expand Up @@ -116,6 +127,7 @@ hqDefine('hqwebapp/js/initial_page_data', ['jquery', 'underscore'], function ($,
gather: gather,
get: get,
register: register,
unregister: unregister,
getUrlParameter: getUrlParameter,
getUrlParameterFromString: getUrlParameterFromString,
registerUrl: registerUrl,
Expand Down

0 comments on commit 3e5e386

Please sign in to comment.