summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/new-console-output/test/store
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/webconsole/new-console-output/test/store
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/webconsole/new-console-output/test/store')
-rw-r--r--devtools/client/webconsole/new-console-output/test/store/filters.test.js215
-rw-r--r--devtools/client/webconsole/new-console-output/test/store/messages.test.js353
2 files changed, 568 insertions, 0 deletions
diff --git a/devtools/client/webconsole/new-console-output/test/store/filters.test.js b/devtools/client/webconsole/new-console-output/test/store/filters.test.js
new file mode 100644
index 000000000..3c38a255a
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/store/filters.test.js
@@ -0,0 +1,215 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const expect = require("expect");
+
+const actions = require("devtools/client/webconsole/new-console-output/actions/index");
+const { messageAdd } = require("devtools/client/webconsole/new-console-output/actions/index");
+const { ConsoleCommand } = require("devtools/client/webconsole/new-console-output/types");
+const { getAllMessages } = require("devtools/client/webconsole/new-console-output/selectors/messages");
+const { getAllFilters } = require("devtools/client/webconsole/new-console-output/selectors/filters");
+const { setupStore } = require("devtools/client/webconsole/new-console-output/test/helpers");
+const { MESSAGE_LEVEL } = require("devtools/client/webconsole/new-console-output/constants");
+const { stubPackets } = require("devtools/client/webconsole/new-console-output/test/fixtures/stubs/index");
+const { stubPreparedMessages } = require("devtools/client/webconsole/new-console-output/test/fixtures/stubs/index");
+
+describe("Filtering", () => {
+ let store;
+ let numMessages;
+ // Number of messages in prepareBaseStore which are not filtered out, i.e. Evaluation
+ // Results, console commands and console.groups .
+ const numUnfilterableMessages = 3;
+
+ beforeEach(() => {
+ store = prepareBaseStore();
+ store.dispatch(actions.filtersClear());
+ numMessages = getAllMessages(store.getState()).size;
+ });
+
+ describe("Level filter", () => {
+ it("filters log messages", () => {
+ store.dispatch(actions.filterToggle(MESSAGE_LEVEL.LOG));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size).toEqual(numMessages - 3);
+ });
+
+ it("filters debug messages", () => {
+ store.dispatch(actions.filterToggle(MESSAGE_LEVEL.DEBUG));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size).toEqual(numMessages - 1);
+ });
+
+ // @TODO add info stub
+ it("filters info messages");
+
+ it("filters warning messages", () => {
+ store.dispatch(actions.filterToggle(MESSAGE_LEVEL.WARN));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size).toEqual(numMessages - 1);
+ });
+
+ it("filters error messages", () => {
+ store.dispatch(actions.filterToggle(MESSAGE_LEVEL.ERROR));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size).toEqual(numMessages - 1);
+ });
+
+ it("filters xhr messages", () => {
+ let message = stubPreparedMessages.get("XHR GET request");
+ store.dispatch(messageAdd(message));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size).toEqual(numMessages);
+
+ store.dispatch(actions.filterToggle("netxhr"));
+ messages = getAllMessages(store.getState());
+ expect(messages.size).toEqual(numMessages + 1);
+ });
+
+ it("filters network messages", () => {
+ let message = stubPreparedMessages.get("GET request");
+ store.dispatch(messageAdd(message));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size).toEqual(numMessages);
+
+ store.dispatch(actions.filterToggle("net"));
+ messages = getAllMessages(store.getState());
+ expect(messages.size).toEqual(numMessages + 1);
+ });
+ });
+
+ describe("Text filter", () => {
+ it("matches on value grips", () => {
+ store.dispatch(actions.filterTextSet("danger"));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size - numUnfilterableMessages).toEqual(1);
+ });
+
+ it("matches unicode values", () => {
+ store.dispatch(actions.filterTextSet("鼬"));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size - numUnfilterableMessages).toEqual(1);
+ });
+
+ it("matches locations", () => {
+ // Add a message with a different filename.
+ let locationMsg =
+ Object.assign({}, stubPackets.get("console.log('foobar', 'test')"));
+ locationMsg.message =
+ Object.assign({}, locationMsg.message, { filename: "search-location-test.js" });
+ store.dispatch(messageAdd(locationMsg));
+
+ store.dispatch(actions.filterTextSet("search-location-test.js"));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size - numUnfilterableMessages).toEqual(1);
+ });
+
+ it("matches stacktrace functionName", () => {
+ let traceMessage = stubPackets.get("console.trace()");
+ store.dispatch(messageAdd(traceMessage));
+
+ store.dispatch(actions.filterTextSet("testStacktraceFiltering"));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size - numUnfilterableMessages).toEqual(1);
+ });
+
+ it("matches stacktrace location", () => {
+ let traceMessage = stubPackets.get("console.trace()");
+ traceMessage.message =
+ Object.assign({}, traceMessage.message, {
+ filename: "search-location-test.js",
+ lineNumber: 85,
+ columnNumber: 13
+ });
+
+ store.dispatch(messageAdd(traceMessage));
+
+ store.dispatch(actions.filterTextSet("search-location-test.js:85:13"));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size - numUnfilterableMessages).toEqual(1);
+ });
+
+ it("restores all messages once text is cleared", () => {
+ store.dispatch(actions.filterTextSet("danger"));
+ store.dispatch(actions.filterTextSet(""));
+
+ let messages = getAllMessages(store.getState());
+ expect(messages.size).toEqual(numMessages);
+ });
+ });
+
+ describe("Combined filters", () => {
+ // @TODO add test
+ it("filters");
+ });
+});
+
+describe("Clear filters", () => {
+ it("clears all filters", () => {
+ const store = setupStore([]);
+
+ // Setup test case
+ store.dispatch(actions.filterToggle(MESSAGE_LEVEL.ERROR));
+ store.dispatch(actions.filterToggle("netxhr"));
+ store.dispatch(actions.filterTextSet("foobar"));
+
+ let filters = getAllFilters(store.getState());
+ expect(filters.toJS()).toEqual({
+ "debug": true,
+ "error": false,
+ "info": true,
+ "log": true,
+ "net": false,
+ "netxhr": true,
+ "warn": true,
+ "text": "foobar"
+ });
+
+ store.dispatch(actions.filtersClear());
+
+ filters = getAllFilters(store.getState());
+ expect(filters.toJS()).toEqual({
+ "debug": true,
+ "error": true,
+ "info": true,
+ "log": true,
+ "net": false,
+ "netxhr": false,
+ "warn": true,
+ "text": ""
+ });
+ });
+});
+
+function prepareBaseStore() {
+ const store = setupStore([
+ // Console API
+ "console.log('foobar', 'test')",
+ "console.warn('danger, will robinson!')",
+ "console.log(undefined)",
+ "console.count('bar')",
+ "console.log('鼬')",
+ // Evaluation Result - never filtered
+ "new Date(0)",
+ // PageError
+ "ReferenceError: asdf is not defined",
+ "console.group('bar')"
+ ]);
+
+ // Console Command - never filtered
+ store.dispatch(messageAdd(new ConsoleCommand({ messageText: `console.warn("x")` })));
+
+ return store;
+}
diff --git a/devtools/client/webconsole/new-console-output/test/store/messages.test.js b/devtools/client/webconsole/new-console-output/test/store/messages.test.js
new file mode 100644
index 000000000..582ca36e3
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/store/messages.test.js
@@ -0,0 +1,353 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+const {
+ getAllMessages,
+ getAllMessagesUiById,
+ getAllGroupsById,
+ getCurrentGroup,
+} = require("devtools/client/webconsole/new-console-output/selectors/messages");
+const {
+ setupActions,
+ setupStore
+} = require("devtools/client/webconsole/new-console-output/test/helpers");
+const { stubPackets, stubPreparedMessages } = require("devtools/client/webconsole/new-console-output/test/fixtures/stubs/index");
+const {
+ MESSAGE_TYPE,
+} = require("devtools/client/webconsole/new-console-output/constants");
+
+const expect = require("expect");
+
+describe("Message reducer:", () => {
+ let actions;
+
+ before(() => {
+ actions = setupActions();
+ });
+
+ describe("messagesById", () => {
+ it("adds a message to an empty store", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const packet = stubPackets.get("console.log('foobar', 'test')");
+ const message = stubPreparedMessages.get("console.log('foobar', 'test')");
+ dispatch(actions.messageAdd(packet));
+
+ const messages = getAllMessages(getState());
+
+ expect(messages.first()).toEqual(message);
+ });
+
+ it("increments repeat on a repeating message", () => {
+ const { dispatch, getState } = setupStore([
+ "console.log('foobar', 'test')",
+ "console.log('foobar', 'test')"
+ ]);
+
+ const packet = stubPackets.get("console.log('foobar', 'test')");
+ dispatch(actions.messageAdd(packet));
+ dispatch(actions.messageAdd(packet));
+
+ const messages = getAllMessages(getState());
+
+ expect(messages.size).toBe(1);
+ expect(messages.first().repeat).toBe(4);
+ });
+
+ it("does not clobber a unique message", () => {
+ const { dispatch, getState } = setupStore([
+ "console.log('foobar', 'test')",
+ "console.log('foobar', 'test')"
+ ]);
+
+ const packet = stubPackets.get("console.log('foobar', 'test')");
+ dispatch(actions.messageAdd(packet));
+
+ const packet2 = stubPackets.get("console.log(undefined)");
+ dispatch(actions.messageAdd(packet2));
+
+ const messages = getAllMessages(getState());
+
+ expect(messages.size).toBe(2);
+ expect(messages.first().repeat).toBe(3);
+ expect(messages.last().repeat).toBe(1);
+ });
+
+ it("adds a message in response to console.clear()", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ dispatch(actions.messageAdd(stubPackets.get("console.clear()")));
+
+ const messages = getAllMessages(getState());
+
+ expect(messages.size).toBe(1);
+ expect(messages.first().parameters[0]).toBe("Console was cleared.");
+ });
+
+ it("clears the messages list in response to MESSAGES_CLEAR action", () => {
+ const { dispatch, getState } = setupStore([
+ "console.log('foobar', 'test')",
+ "console.log(undefined)"
+ ]);
+
+ dispatch(actions.messagesClear());
+
+ const messages = getAllMessages(getState());
+ expect(messages.size).toBe(0);
+ });
+
+ it("limits the number of messages displayed", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const logLimit = 1000;
+ const packet = stubPackets.get("console.log(undefined)");
+ for (let i = 1; i <= logLimit + 1; i++) {
+ packet.message.arguments = [`message num ${i}`];
+ dispatch(actions.messageAdd(packet));
+ }
+
+ const messages = getAllMessages(getState());
+ expect(messages.count()).toBe(logLimit);
+ expect(messages.first().parameters[0]).toBe(`message num 2`);
+ expect(messages.last().parameters[0]).toBe(`message num ${logLimit + 1}`);
+ });
+
+ it("does not add null messages to the store", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const message = stubPackets.get("console.time('bar')");
+ dispatch(actions.messageAdd(message));
+
+ const messages = getAllMessages(getState());
+ expect(messages.size).toBe(0);
+ });
+
+ it("adds console.table call with unsupported type as console.log", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const packet = stubPackets.get("console.table('bar')");
+ dispatch(actions.messageAdd(packet));
+
+ const messages = getAllMessages(getState());
+ const tableMessage = messages.last();
+ expect(tableMessage.level).toEqual(MESSAGE_TYPE.LOG);
+ });
+
+ it("adds console.group messages to the store", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const message = stubPackets.get("console.group('bar')");
+ dispatch(actions.messageAdd(message));
+
+ const messages = getAllMessages(getState());
+ expect(messages.size).toBe(1);
+ });
+
+ it("sets groupId property as expected", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ dispatch(actions.messageAdd(
+ stubPackets.get("console.group('bar')")));
+
+ const packet = stubPackets.get("console.log('foobar', 'test')");
+ dispatch(actions.messageAdd(packet));
+
+ const messages = getAllMessages(getState());
+ expect(messages.size).toBe(2);
+ expect(messages.last().groupId).toBe(messages.first().id);
+ });
+
+ it("does not display console.groupEnd messages to the store", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const message = stubPackets.get("console.groupEnd('bar')");
+ dispatch(actions.messageAdd(message));
+
+ const messages = getAllMessages(getState());
+ expect(messages.size).toBe(0);
+ });
+
+ it("filters out message added after a console.groupCollapsed message", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const message = stubPackets.get("console.groupCollapsed('foo')");
+ dispatch(actions.messageAdd(message));
+
+ dispatch(actions.messageAdd(
+ stubPackets.get("console.log('foobar', 'test')")));
+
+ const messages = getAllMessages(getState());
+ expect(messages.size).toBe(1);
+ });
+
+ it("shows the group of the first displayed message when messages are pruned", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const logLimit = 1000;
+
+ const groupMessage = stubPreparedMessages.get("console.group('bar')");
+ dispatch(actions.messageAdd(
+ stubPackets.get("console.group('bar')")));
+
+ const packet = stubPackets.get("console.log(undefined)");
+ for (let i = 1; i <= logLimit + 1; i++) {
+ packet.message.arguments = [`message num ${i}`];
+ dispatch(actions.messageAdd(packet));
+ }
+
+ const messages = getAllMessages(getState());
+ expect(messages.count()).toBe(logLimit);
+ expect(messages.first().messageText).toBe(groupMessage.messageText);
+ expect(messages.get(1).parameters[0]).toBe(`message num 3`);
+ expect(messages.last().parameters[0]).toBe(`message num ${logLimit + 1}`);
+ });
+
+ it("adds console.dirxml call as console.log", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const packet = stubPackets.get("console.dirxml(window)");
+ dispatch(actions.messageAdd(packet));
+
+ const messages = getAllMessages(getState());
+ const dirxmlMessage = messages.last();
+ expect(dirxmlMessage.level).toEqual(MESSAGE_TYPE.LOG);
+ });
+ });
+
+ describe("messagesUiById", () => {
+ it("opens console.trace messages when they are added", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const message = stubPackets.get("console.trace()");
+ dispatch(actions.messageAdd(message));
+
+ const messages = getAllMessages(getState());
+ const messagesUi = getAllMessagesUiById(getState());
+ expect(messagesUi.size).toBe(1);
+ expect(messagesUi.first()).toBe(messages.first().id);
+ });
+
+ it("clears the messages UI list in response to MESSAGES_CLEAR action", () => {
+ const { dispatch, getState } = setupStore([
+ "console.log('foobar', 'test')",
+ "console.log(undefined)"
+ ]);
+
+ const traceMessage = stubPackets.get("console.trace()");
+ dispatch(actions.messageAdd(traceMessage));
+
+ dispatch(actions.messagesClear());
+
+ const messagesUi = getAllMessagesUiById(getState());
+ expect(messagesUi.size).toBe(0);
+ });
+
+ it("opens console.group messages when they are added", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const message = stubPackets.get("console.group('bar')");
+ dispatch(actions.messageAdd(message));
+
+ const messages = getAllMessages(getState());
+ const messagesUi = getAllMessagesUiById(getState());
+ expect(messagesUi.size).toBe(1);
+ expect(messagesUi.first()).toBe(messages.first().id);
+ });
+
+ it("does not open console.groupCollapsed messages when they are added", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const message = stubPackets.get("console.groupCollapsed('foo')");
+ dispatch(actions.messageAdd(message));
+
+ const messagesUi = getAllMessagesUiById(getState());
+ expect(messagesUi.size).toBe(0);
+ });
+ });
+
+ describe("currentGroup", () => {
+ it("sets the currentGroup when console.group message is added", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const packet = stubPackets.get("console.group('bar')");
+ dispatch(actions.messageAdd(packet));
+
+ const messages = getAllMessages(getState());
+ const currentGroup = getCurrentGroup(getState());
+ expect(currentGroup).toBe(messages.first().id);
+ });
+
+ it("sets currentGroup to expected value when console.groupEnd is added", () => {
+ const { dispatch, getState } = setupStore([
+ "console.group('bar')",
+ "console.groupCollapsed('foo')"
+ ]);
+
+ let messages = getAllMessages(getState());
+ let currentGroup = getCurrentGroup(getState());
+ expect(currentGroup).toBe(messages.last().id);
+
+ const endFooPacket = stubPackets.get("console.groupEnd('foo')");
+ dispatch(actions.messageAdd(endFooPacket));
+ messages = getAllMessages(getState());
+ currentGroup = getCurrentGroup(getState());
+ expect(currentGroup).toBe(messages.first().id);
+
+ const endBarPacket = stubPackets.get("console.groupEnd('foo')");
+ dispatch(actions.messageAdd(endBarPacket));
+ messages = getAllMessages(getState());
+ currentGroup = getCurrentGroup(getState());
+ expect(currentGroup).toBe(null);
+ });
+
+ it("resets the currentGroup to null in response to MESSAGES_CLEAR action", () => {
+ const { dispatch, getState } = setupStore([
+ "console.group('bar')"
+ ]);
+
+ dispatch(actions.messagesClear());
+
+ const currentGroup = getCurrentGroup(getState());
+ expect(currentGroup).toBe(null);
+ });
+ });
+
+ describe("groupsById", () => {
+ it("adds the group with expected array when console.group message is added", () => {
+ const { dispatch, getState } = setupStore([]);
+
+ const barPacket = stubPackets.get("console.group('bar')");
+ dispatch(actions.messageAdd(barPacket));
+
+ let messages = getAllMessages(getState());
+ let groupsById = getAllGroupsById(getState());
+ expect(groupsById.size).toBe(1);
+ expect(groupsById.has(messages.first().id)).toBe(true);
+ expect(groupsById.get(messages.first().id)).toEqual([]);
+
+ const fooPacket = stubPackets.get("console.groupCollapsed('foo')");
+ dispatch(actions.messageAdd(fooPacket));
+ messages = getAllMessages(getState());
+ groupsById = getAllGroupsById(getState());
+ expect(groupsById.size).toBe(2);
+ expect(groupsById.has(messages.last().id)).toBe(true);
+ expect(groupsById.get(messages.last().id)).toEqual([messages.first().id]);
+ });
+
+ it("resets groupsById in response to MESSAGES_CLEAR action", () => {
+ const { dispatch, getState } = setupStore([
+ "console.group('bar')",
+ "console.groupCollapsed('foo')",
+ ]);
+
+ let groupsById = getAllGroupsById(getState());
+ expect(groupsById.size).toBe(2);
+
+ dispatch(actions.messagesClear());
+
+ groupsById = getAllGroupsById(getState());
+ expect(groupsById.size).toBe(0);
+ });
+ });
+});