Bug 1307884 - Implement tests; r=bgrins,nchevobbe

MozReview-Commit-ID: KdYSPciSvJk

--HG--
extra : rebase_source : e9f905571608ae4386ea528d3f373e587c7121df
This commit is contained in:
Jan Odvarko 2017-05-22 19:59:28 +02:00
Родитель 29ca14c02a
Коммит 6a123ea736
3 изменённых файлов: 111 добавлений и 26 удалений

Просмотреть файл

@ -31,8 +31,8 @@ function setupActions() {
/**
* Prepare the store for use in testing.
*/
function setupStore(input) {
const store = configureStore();
function setupStore(input, hud) {
const store = configureStore(hud);
// Add the messages from the input commands to the store.
input.forEach((cmd) => {

Просмотреть файл

@ -102,16 +102,62 @@ describe("Message reducer:", () => {
expect(messages.size).toBe(0);
});
it("limits the number of messages displayed", () => {
it("properly limits number of messages", () => {
const { dispatch, getState } = setupStore([]);
const logLimit = 1000;
const packet = clonePacket(stubPackets.get("console.log(undefined)"));
for (let i = 1; i <= logLimit + 1; i++) {
for (let i = 1; i <= logLimit + 2; 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 3`);
expect(messages.last().parameters[0]).toBe(`message num ${logLimit + 2}`);
});
it("properly limits number of groups", () => {
const { dispatch, getState } = setupStore([]);
const logLimit = 1000;
const packet = clonePacket(stubPackets.get("console.log(undefined)"));
const packetGroup = clonePacket(stubPackets.get("console.group('bar')"));
const packetGroupEnd = clonePacket(stubPackets.get("console.groupEnd()"));
for (let i = 0; i < logLimit + 2; i++) {
packet.message.arguments = [`message num ${i}`];
dispatch(actions.messageAdd(packetGroup));
dispatch(actions.messageAdd(packet));
dispatch(actions.messageAdd(packetGroupEnd));
}
const messages = getAllMessages(getState());
expect(messages.count()).toBe(logLimit * 2);
expect(messages.get(1).parameters[0]).toBe(`message num 2`);
expect(messages.last().parameters[0]).toBe(`message num ${logLimit + 1}`);
});
it("properly limits number of collapsed groups", () => {
const { dispatch, getState } = setupStore([]);
const logLimit = 1000;
const packet = clonePacket(stubPackets.get("console.log(undefined)"));
const packetGroupCollapsed = clonePacket(
stubPackets.get("console.groupCollapsed('foo')"));
const packetGroupEnd = clonePacket(stubPackets.get("console.groupEnd()"));
for (let i = 0; i < logLimit + 2; i++) {
packetGroupCollapsed.message.arguments = [`message num ${i}`];
dispatch(actions.messageAdd(packetGroupCollapsed));
dispatch(actions.messageAdd(packet));
dispatch(actions.messageAdd(packetGroupEnd));
}
const messages = getAllMessages(getState());
expect(messages.count()).toBe(logLimit);
expect(messages.first().parameters[0]).toBe(`message num 2`);
@ -186,28 +232,6 @@ describe("Message reducer:", () => {
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 = clonePacket(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([]);

Просмотреть файл

@ -0,0 +1,61 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {
setupActions,
setupStore,
clonePacket
} = require("devtools/client/webconsole/new-console-output/test/helpers");
const { stubPackets } = require("devtools/client/webconsole/new-console-output/test/fixtures/stubs/index");
const expect = require("expect");
describe("Release actor enhancer:", () => {
let actions;
before(() => {
actions = setupActions();
});
describe("Client proxy", () => {
it("properly releases backend actors when limit is reached", () => {
let proxyExecuted = 0;
const { dispatch } = setupStore([], {
proxy: {
releaseActor: (actor) => {
proxyExecuted++;
}
}
});
const logCount = 1001;
const packet = clonePacket(stubPackets.get(
"console.assert(false, {message: 'foobar'})"));
for (let i = 1; i <= logCount; i++) {
packet.message.arguments.push(`message num ${i}`);
dispatch(actions.messageAdd(packet));
}
expect(proxyExecuted).toBe(1);
});
it("properly releases backend actors after clear", () => {
let proxyExecuted = 0;
const { dispatch } = setupStore([], {
proxy: {
releaseActor: (actor) => {
proxyExecuted++;
}
}
});
dispatch(actions.messageAdd(clonePacket(stubPackets.get(
"console.assert(false, {message: 'foobar'})"))));
dispatch(actions.messagesClear());
expect(proxyExecuted).toBe(1);
});
});
});