Bug 1371721 - Test messagesAdd repeat behavior. r=nchevobbe draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 20 Sep 2017 16:54:18 +0200
changeset 668432 8676099f4f9550051f9ed17c2c0aeea8fb6ba516
parent 668431 cde553689a73adc19e007a89612092d28e9e9793
child 732699 74c738ddb1e727b3405006ab85fd0df0c50ae840
push id81043
push userbmo:poirot.alex@gmail.com
push dateThu, 21 Sep 2017 16:57:41 +0000
reviewersnchevobbe
bugs1371721
milestone57.0a1
Bug 1371721 - Test messagesAdd repeat behavior. r=nchevobbe MozReview-Commit-ID: 4qGkb0odIwf
devtools/client/webconsole/new-console-output/test/store/messages.test.js
--- a/devtools/client/webconsole/new-console-output/test/store/messages.test.js
+++ b/devtools/client/webconsole/new-console-output/test/store/messages.test.js
@@ -752,9 +752,40 @@ describe("Message reducer:", () => {
       expect(table.get(id2)).toBe(tableData2);
 
       // This addition will remove the second table message.
       dispatch(actions.messageAdd(stubPackets.get("console.log('foobar', 'test')")));
 
       expect(getAllMessagesTableDataById(getState()).size).toBe(0);
     });
   });
+
+  describe("messagesAdd", () => {
+    it("still log repeated message over logLimit, but only repeated ones", () => {
+      // Log two distinct messages
+      const key1 = "console.log('foobar', 'test')";
+      const key2 = "console.log(undefined)";
+      const { dispatch, getState } = setupStore([key1, key2], null, {
+        logLimit: 2
+      });
+
+      // Then repeat the last one two times and log the first one again
+      const packet1 = clonePacket(stubPackets.get(key2));
+      const packet2 = clonePacket(stubPackets.get(key2));
+      const packet3 = clonePacket(stubPackets.get(key1));
+
+      // Repeat ID must be the same even if the timestamp is different.
+      packet1.message.timeStamp = 1;
+      packet2.message.timeStamp = 2;
+      packet3.message.timeStamp = 3;
+      dispatch(actions.messagesAdd([packet1, packet2, packet3]));
+
+      // There is still only two messages being logged,
+      const messages = getAllMessagesById(getState());
+      expect(messages.size).toBe(2);
+
+      // the second one being repeated 3 times
+      const repeat = getAllRepeatById(getState());
+      expect(repeat[messages.first().id]).toBe(3);
+      expect(repeat[messages.last().id]).toBe(undefined);
+    });
+  });
 });