From 8e86a266d90f071e47b404f54159ef32b06b8e06 Mon Sep 17 00:00:00 2001 From: Jan Odvarko Date: Tue, 25 Apr 2017 15:31:22 +0200 Subject: [PATCH] Bug 1307879 - Implement test for searching in grips; r=nchevobbe MozReview-Commit-ID: Gj1Yu6CHzLz --HG-- extra : rebase_source : 820470ad57bc8ee7c567d5544f8e21566a7ab2e2 --- .../fixtures/stub-generators/stub-snippets.js | 13 + .../test/fixtures/stubs/consoleApi.js | 449 ++++++++++++++++++ .../test/store/search.test.js | 76 +++ 3 files changed, 538 insertions(+) create mode 100644 devtools/client/webconsole/new-console-output/test/store/search.test.js diff --git a/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/stub-snippets.js b/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/stub-snippets.js index f4165fefd979..562f0be18f31 100644 --- a/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/stub-snippets.js +++ b/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/stub-snippets.js @@ -18,11 +18,24 @@ const consoleApiCommands = [ "console.log('hello \\nfrom \\rthe \\\"string world!')", "console.log('\xFA\u1E47\u0129\xE7\xF6d\xEA \u021B\u0115\u0219\u0165')", "console.dirxml(window)", + "console.log('myarray', ['red', 'green', 'blue'])", + "console.log('myregex', /a.b.c/)", + "console.table(['red', 'green', 'blue']);", + "console.log('myobject', {red: 'redValue', green: 'greenValue', blue: 'blueValue'});", ]; let consoleApi = new Map(consoleApiCommands.map( cmd => [cmd, {keys: [cmd], code: cmd}])); +consoleApi.set("console.map('mymap')", { + keys: ["console.map('mymap')"], + code: ` +var map = new Map(); +map.set("key1", "value1"); +map.set("key2", "value2"); +console.log('mymap', map); +`}); + consoleApi.set("console.trace()", { keys: ["console.trace()"], code: ` diff --git a/devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js b/devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js index 0a9abb99a02f..1b5acfedb452 100644 --- a/devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js +++ b/devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js @@ -359,6 +359,233 @@ stubPreparedMessages.set("console.dirxml(window)", new ConsoleMessage({ "notes": null })); +stubPreparedMessages.set("console.log('myarray', ['red', 'green', 'blue'])", new ConsoleMessage({ + "id": "1", + "allowRepeating": true, + "source": "console-api", + "timeStamp": 1493123239624, + "type": "log", + "level": "log", + "messageText": null, + "parameters": [ + "myarray", + { + "type": "object", + "actor": "server1.conn0.child1/obj32", + "class": "Array", + "extensible": true, + "frozen": false, + "sealed": false, + "ownPropertyLength": 4, + "preview": { + "kind": "ArrayLike", + "length": 3, + "items": [ + "red", + "green", + "blue" + ] + } + } + ], + "repeat": 1, + "repeatId": "{\"id\":null,\"allowRepeating\":true,\"source\":\"console-api\",\"timeStamp\":1493123239624,\"type\":\"log\",\"level\":\"log\",\"messageText\":null,\"parameters\":[\"myarray\",{\"type\":\"object\",\"actor\":\"server1.conn0.child1/obj32\",\"class\":\"Array\",\"extensible\":true,\"frozen\":false,\"sealed\":false,\"ownPropertyLength\":4,\"preview\":{\"kind\":\"ArrayLike\",\"length\":3,\"items\":[\"red\",\"green\",\"blue\"]}}],\"repeatId\":null,\"stacktrace\":null,\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html\",\"line\":1,\"column\":27},\"groupId\":null,\"exceptionDocURL\":null,\"userProvidedStyles\":[],\"notes\":null}", + "stacktrace": null, + "frame": { + "source": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html", + "line": 1, + "column": 27 + }, + "groupId": null, + "exceptionDocURL": null, + "userProvidedStyles": [], + "notes": null +})); + +stubPreparedMessages.set("console.log('myregex', /a.b.c/)", new ConsoleMessage({ + "id": "1", + "allowRepeating": true, + "source": "console-api", + "timeStamp": 1493123770223, + "type": "log", + "level": "log", + "messageText": null, + "parameters": [ + "myregex", + { + "type": "object", + "actor": "server1.conn0.child1/obj33", + "class": "RegExp", + "extensible": true, + "frozen": false, + "sealed": false, + "ownPropertyLength": 1, + "displayString": "/a.b.c/" + } + ], + "repeat": 1, + "repeatId": "{\"id\":null,\"allowRepeating\":true,\"source\":\"console-api\",\"timeStamp\":1493123770223,\"type\":\"log\",\"level\":\"log\",\"messageText\":null,\"parameters\":[\"myregex\",{\"type\":\"object\",\"actor\":\"server1.conn0.child1/obj33\",\"class\":\"RegExp\",\"extensible\":true,\"frozen\":false,\"sealed\":false,\"ownPropertyLength\":1,\"displayString\":\"/a.b.c/\"}],\"repeatId\":null,\"stacktrace\":null,\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html\",\"line\":1,\"column\":27},\"groupId\":null,\"exceptionDocURL\":null,\"userProvidedStyles\":[],\"notes\":null}", + "stacktrace": null, + "frame": { + "source": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html", + "line": 1, + "column": 27 + }, + "groupId": null, + "exceptionDocURL": null, + "userProvidedStyles": [], + "notes": null +})); + +stubPreparedMessages.set("console.table(['red', 'green', 'blue']);", new ConsoleMessage({ + "id": "1", + "allowRepeating": true, + "source": "console-api", + "timeStamp": 1493124761377, + "type": "table", + "level": "log", + "messageText": null, + "parameters": [ + { + "type": "object", + "actor": "server1.conn0.child1/obj34", + "class": "Array", + "extensible": true, + "frozen": false, + "sealed": false, + "ownPropertyLength": 4, + "preview": { + "kind": "ArrayLike", + "length": 3, + "items": [ + "red", + "green", + "blue" + ] + } + } + ], + "repeat": 1, + "repeatId": "{\"id\":null,\"allowRepeating\":true,\"source\":\"console-api\",\"timeStamp\":1493124761377,\"type\":\"table\",\"level\":\"log\",\"messageText\":null,\"parameters\":[{\"type\":\"object\",\"actor\":\"server1.conn0.child1/obj34\",\"class\":\"Array\",\"extensible\":true,\"frozen\":false,\"sealed\":false,\"ownPropertyLength\":4,\"preview\":{\"kind\":\"ArrayLike\",\"length\":3,\"items\":[\"red\",\"green\",\"blue\"]}}],\"repeatId\":null,\"stacktrace\":null,\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html\",\"line\":1,\"column\":27},\"groupId\":null,\"exceptionDocURL\":null,\"userProvidedStyles\":[],\"notes\":null}", + "stacktrace": null, + "frame": { + "source": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html", + "line": 1, + "column": 27 + }, + "groupId": null, + "exceptionDocURL": null, + "userProvidedStyles": [], + "notes": null +})); + +stubPreparedMessages.set("console.log('myobject', {red: 'redValue', green: 'greenValue', blue: 'blueValue'});", new ConsoleMessage({ + "id": "1", + "allowRepeating": true, + "source": "console-api", + "timeStamp": 1493125748177, + "type": "log", + "level": "log", + "messageText": null, + "parameters": [ + "myobject", + { + "type": "object", + "actor": "server1.conn0.child1/obj35", + "class": "Object", + "extensible": true, + "frozen": false, + "sealed": false, + "ownPropertyLength": 3, + "preview": { + "kind": "Object", + "ownProperties": { + "red": { + "configurable": true, + "enumerable": true, + "writable": true, + "value": "redValue" + }, + "green": { + "configurable": true, + "enumerable": true, + "writable": true, + "value": "greenValue" + }, + "blue": { + "configurable": true, + "enumerable": true, + "writable": true, + "value": "blueValue" + } + }, + "ownPropertiesLength": 3, + "safeGetterValues": {} + } + } + ], + "repeat": 1, + "repeatId": "{\"id\":null,\"allowRepeating\":true,\"source\":\"console-api\",\"timeStamp\":1493125748177,\"type\":\"log\",\"level\":\"log\",\"messageText\":null,\"parameters\":[\"myobject\",{\"type\":\"object\",\"actor\":\"server1.conn0.child1/obj35\",\"class\":\"Object\",\"extensible\":true,\"frozen\":false,\"sealed\":false,\"ownPropertyLength\":3,\"preview\":{\"kind\":\"Object\",\"ownProperties\":{\"red\":{\"configurable\":true,\"enumerable\":true,\"writable\":true,\"value\":\"redValue\"},\"green\":{\"configurable\":true,\"enumerable\":true,\"writable\":true,\"value\":\"greenValue\"},\"blue\":{\"configurable\":true,\"enumerable\":true,\"writable\":true,\"value\":\"blueValue\"}},\"ownPropertiesLength\":3,\"safeGetterValues\":{}}}],\"repeatId\":null,\"stacktrace\":null,\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html\",\"line\":1,\"column\":27},\"groupId\":null,\"exceptionDocURL\":null,\"userProvidedStyles\":[],\"notes\":null}", + "stacktrace": null, + "frame": { + "source": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html", + "line": 1, + "column": 27 + }, + "groupId": null, + "exceptionDocURL": null, + "userProvidedStyles": [], + "notes": null +})); + +stubPreparedMessages.set("console.map('mymap')", new ConsoleMessage({ + "id": "1", + "allowRepeating": true, + "source": "console-api", + "timeStamp": 1493125410207, + "type": "log", + "level": "log", + "messageText": null, + "parameters": [ + "mymap", + { + "type": "object", + "actor": "server1.conn0.child1/obj36", + "class": "Map", + "extensible": true, + "frozen": false, + "sealed": false, + "ownPropertyLength": 0, + "preview": { + "kind": "MapLike", + "size": 2, + "entries": [ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ] + } + } + ], + "repeat": 1, + "repeatId": "{\"id\":null,\"allowRepeating\":true,\"source\":\"console-api\",\"timeStamp\":1493125410207,\"type\":\"log\",\"level\":\"log\",\"messageText\":null,\"parameters\":[\"mymap\",{\"type\":\"object\",\"actor\":\"server1.conn0.child1/obj36\",\"class\":\"Map\",\"extensible\":true,\"frozen\":false,\"sealed\":false,\"ownPropertyLength\":0,\"preview\":{\"kind\":\"MapLike\",\"size\":2,\"entries\":[[\"key1\",\"value1\"],[\"key2\",\"value2\"]]}}],\"repeatId\":null,\"stacktrace\":null,\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html\",\"line\":5,\"column\":1},\"groupId\":null,\"exceptionDocURL\":null,\"userProvidedStyles\":[],\"notes\":null}", + "stacktrace": null, + "frame": { + "source": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html", + "line": 5, + "column": 1 + }, + "groupId": null, + "exceptionDocURL": null, + "userProvidedStyles": [], + "notes": null +})); + stubPreparedMessages.set("console.trace()", new ConsoleMessage({ "id": "1", "allowRepeating": true, @@ -1132,6 +1359,228 @@ stubPackets.set("console.dirxml(window)", { } }); +stubPackets.set("console.log('myarray', ['red', 'green', 'blue'])", { + "from": "server1.conn0.child1/consoleActor2", + "type": "consoleAPICall", + "message": { + "addonId": "", + "arguments": [ + "myarray", + { + "type": "object", + "actor": "server1.conn0.child1/obj32", + "class": "Array", + "extensible": true, + "frozen": false, + "sealed": false, + "ownPropertyLength": 4, + "preview": { + "kind": "ArrayLike", + "length": 3, + "items": [ + "red", + "green", + "blue" + ] + } + } + ], + "columnNumber": 27, + "counter": null, + "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html", + "functionName": "triggerPacket", + "groupName": "", + "level": "log", + "lineNumber": 1, + "private": false, + "styles": [], + "timeStamp": 1493123239624, + "timer": null, + "workerType": "none", + "category": "webdev" + } +}); + +stubPackets.set("console.log('myregex', /a.b.c/)", { + "from": "server1.conn0.child1/consoleActor2", + "type": "consoleAPICall", + "message": { + "addonId": "", + "arguments": [ + "myregex", + { + "type": "object", + "actor": "server1.conn0.child1/obj33", + "class": "RegExp", + "extensible": true, + "frozen": false, + "sealed": false, + "ownPropertyLength": 1, + "displayString": "/a.b.c/" + } + ], + "columnNumber": 27, + "counter": null, + "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html", + "functionName": "triggerPacket", + "groupName": "", + "level": "log", + "lineNumber": 1, + "private": false, + "styles": [], + "timeStamp": 1493123770223, + "timer": null, + "workerType": "none", + "category": "webdev" + } +}); + +stubPackets.set("console.table(['red', 'green', 'blue']);", { + "from": "server1.conn0.child1/consoleActor2", + "type": "consoleAPICall", + "message": { + "addonId": "", + "arguments": [ + { + "type": "object", + "actor": "server1.conn0.child1/obj34", + "class": "Array", + "extensible": true, + "frozen": false, + "sealed": false, + "ownPropertyLength": 4, + "preview": { + "kind": "ArrayLike", + "length": 3, + "items": [ + "red", + "green", + "blue" + ] + } + } + ], + "columnNumber": 27, + "counter": null, + "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html", + "functionName": "triggerPacket", + "groupName": "", + "level": "table", + "lineNumber": 1, + "private": false, + "timeStamp": 1493124761377, + "timer": null, + "workerType": "none", + "styles": [], + "category": "webdev" + } +}); + +stubPackets.set("console.log('myobject', {red: 'redValue', green: 'greenValue', blue: 'blueValue'});", { + "from": "server1.conn0.child1/consoleActor2", + "type": "consoleAPICall", + "message": { + "addonId": "", + "arguments": [ + "myobject", + { + "type": "object", + "actor": "server1.conn0.child1/obj35", + "class": "Object", + "extensible": true, + "frozen": false, + "sealed": false, + "ownPropertyLength": 3, + "preview": { + "kind": "Object", + "ownProperties": { + "red": { + "configurable": true, + "enumerable": true, + "writable": true, + "value": "redValue" + }, + "green": { + "configurable": true, + "enumerable": true, + "writable": true, + "value": "greenValue" + }, + "blue": { + "configurable": true, + "enumerable": true, + "writable": true, + "value": "blueValue" + } + }, + "ownPropertiesLength": 3, + "safeGetterValues": {} + } + } + ], + "columnNumber": 27, + "counter": null, + "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html", + "functionName": "triggerPacket", + "groupName": "", + "level": "log", + "lineNumber": 1, + "private": false, + "styles": [], + "timeStamp": 1493125748177, + "timer": null, + "workerType": "none", + "category": "webdev" + } +}); + +stubPackets.set("console.map('mymap')", { + "from": "server1.conn0.child1/consoleActor2", + "type": "consoleAPICall", + "message": { + "addonId": "", + "arguments": [ + "mymap", + { + "type": "object", + "actor": "server1.conn0.child1/obj36", + "class": "Map", + "extensible": true, + "frozen": false, + "sealed": false, + "ownPropertyLength": 0, + "preview": { + "kind": "MapLike", + "size": 2, + "entries": [ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ] + } + } + ], + "columnNumber": 1, + "counter": null, + "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html", + "functionName": "triggerPacket", + "groupName": "", + "level": "log", + "lineNumber": 5, + "private": false, + "styles": [], + "timeStamp": 1493125410207, + "timer": null, + "workerType": "none", + "category": "webdev" + } +}); + stubPackets.set("console.trace()", { "from": "server1.conn12.child1/consoleActor2", "type": "consoleAPICall", diff --git a/devtools/client/webconsole/new-console-output/test/store/search.test.js b/devtools/client/webconsole/new-console-output/test/store/search.test.js new file mode 100644 index 000000000000..032c7719d83c --- /dev/null +++ b/devtools/client/webconsole/new-console-output/test/store/search.test.js @@ -0,0 +1,76 @@ +/* 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 { getAllMessages } = require("devtools/client/webconsole/new-console-output/selectors/messages"); +const { setupStore } = require("devtools/client/webconsole/new-console-output/test/helpers"); + +describe("Searching in grips", () => { + let store; + + beforeEach(() => { + store = prepareBaseStore(); + store.dispatch(actions.filtersClear()); + }); + + describe("Search in table & array & object props", () => { + it("matches on value grips", () => { + store.dispatch(actions.filterTextSet("red")); + expect(getAllMessages(store.getState()).size).toEqual(3); + }); + }); + + describe("Search in object value", () => { + it("matches on value grips", () => { + store.dispatch(actions.filterTextSet("redValue")); + expect(getAllMessages(store.getState()).size).toEqual(1); + }); + }); + + describe("Search in regex", () => { + it("matches on value grips", () => { + store.dispatch(actions.filterTextSet("a.b.c")); + expect(getAllMessages(store.getState()).size).toEqual(1); + }); + }); + + describe("Search in map values", () => { + it("matches on value grips", () => { + store.dispatch(actions.filterTextSet("value1")); + expect(getAllMessages(store.getState()).size).toEqual(1); + }); + }); + + describe("Search in map keys", () => { + it("matches on value grips", () => { + store.dispatch(actions.filterTextSet("key1")); + expect(getAllMessages(store.getState()).size).toEqual(1); + }); + }); + + describe("Search in text", () => { + it("matches on value grips", () => { + store.dispatch(actions.filterTextSet("myobj")); + expect(getAllMessages(store.getState()).size).toEqual(1); + }); + }); +}); + +function prepareBaseStore() { + const store = setupStore([ + "console.log('foobar', 'test')", + "console.warn('danger, will robinson!')", + "console.table(['red', 'green', 'blue']);", + "console.count('bar')", + "console.log('myarray', ['red', 'green', 'blue'])", + "console.log('myregex', /a.b.c/)", + "console.map('mymap')", + "console.log('myobject', {red: 'redValue', green: 'greenValue', blue: 'blueValue'});", + ]); + + return store; +}