Bug 1558757 - Add unit tests for reducers. r=Ola
authorBelén Albeza <balbeza@mozilla.com>
Tue, 09 Jul 2019 13:40:55 +0000
changeset 481908 1b982af25d34fe3d15cd758f581ff8b95e4e509f
parent 481907 99a239deee753d11dfdf1c6011fdbe32574f6aa2
child 481909 f2e2b64a9329f2560ba41ad0764b06a2028462e1
push id113647
push useraciure@mozilla.com
push dateWed, 10 Jul 2019 09:46:39 +0000
treeherdermozilla-inbound@f3a387c13e2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersOla
bugs1558757
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1558757 - Add unit tests for reducers. r=Ola Differential Revision: https://phabricator.services.mozilla.com/D36741
devtools/client/application/moz.build
devtools/client/application/test/unit/test_page_reducer.js
devtools/client/application/test/unit/test_workers_reducer.js
devtools/client/application/test/unit/xpcshell.ini
--- a/devtools/client/application/moz.build
+++ b/devtools/client/application/moz.build
@@ -10,8 +10,12 @@ DevToolsModules(
     'application.css',
     'initializer.js',
     'panel.js'
 )
 
 BROWSER_CHROME_MANIFESTS += [
     'test/browser/browser.ini'
 ]
+
+XPCSHELL_TESTS_MANIFESTS += [
+    'test/unit/xpcshell.ini'
+]
new file mode 100644
--- /dev/null
+++ b/devtools/client/application/test/unit/test_page_reducer.js
@@ -0,0 +1,22 @@
+/* Any copyright is dedicated to the Public Domain.
+http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const {
+  updateDomain,
+} = require("devtools/client/application/src/actions/page.js");
+
+const {
+  pageReducer,
+  PageState,
+} = require("devtools/client/application/src/reducers/page-state.js");
+
+add_task(async function() {
+  info("Test page reducer: UPDATE_DOMAIN action");
+  const state = PageState();
+  const action = updateDomain("https://example.com/foo/#bar");
+
+  const newState = pageReducer(state, action);
+  equal(newState.domain, "example.com");
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/application/test/unit/test_workers_reducer.js
@@ -0,0 +1,45 @@
+/* Any copyright is dedicated to the Public Domain.
+http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const {
+  updateCanDebugWorkers,
+  updateWorkers,
+} = require("devtools/client/application/src/actions/workers.js");
+
+const {
+  workersReducer,
+  WorkersState,
+} = require("devtools/client/application/src/reducers/workers-state.js");
+
+add_task(async function() {
+  info("Test workers reducer: UPDATE_CAN_DEBUG_WORKERS action");
+
+  function testUpdateCanDebugWorkers(flagValue) {
+    const state = WorkersState();
+    const action = updateCanDebugWorkers(flagValue);
+    const newState = workersReducer(state, action);
+    equal(
+      newState.canDebugWorkers,
+      flagValue,
+      "canDebugWorkers contains the expected value"
+    );
+  }
+
+  testUpdateCanDebugWorkers(false);
+  testUpdateCanDebugWorkers(true);
+});
+
+add_task(async function() {
+  info("Test workers reducer: UPDATE_WORKERS action");
+
+  const state = WorkersState();
+  const action = updateWorkers([{ foo: "bar" }, { lorem: "ipsum" }]);
+  const newState = workersReducer(state, action);
+  deepEqual(
+    newState.list,
+    [{ foo: "bar" }, { lorem: "ipsum" }],
+    "workers contains the expected list"
+  );
+});
--- a/devtools/client/application/test/unit/xpcshell.ini
+++ b/devtools/client/application/test/unit/xpcshell.ini
@@ -1,6 +1,8 @@
 [DEFAULT]
 tags = devtools
 head = xpcshell-head.js
 firefox-appdir = browser
 skip-if = toolkit == 'android'
 
+[test_page_reducer.js]
+[test_workers_reducer.js]