Bug 1431327 - Refactor setupStore helper function; r=bgrins.

Change the signature of setupStore to accept an option object as
its second parameter so it's more easy to remember what it does
when reading the consumer code.
Also, pass the wrapped actions object to setupStore so we do use
the same generator when adding messages later.
Add more group messages in the group test to make sure group are being
closed when a groupEnd message is passed in a messagesAdd batch.

MozReview-Commit-ID: CBN0r8nBaAr

--HG--
extra : rebase_source : 8ed36805f16e2741bcaef6dcddb5c35f61981055
extra : source : 3de06907b8f2857eaa7e29c676e7c0898f30a39b
This commit is contained in:
Nicolas Chevobbe 2018-01-17 09:36:19 +01:00
Родитель 11f7cdb11c
Коммит 2d7063da60
9 изменённых файлов: 119 добавлений и 75 удалений

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

@ -270,7 +270,7 @@ describe("ConsoleAPICall component:", () => {
});
it("toggle the group when the collapse button is clicked", () => {
const store = setupStore([]);
const store = setupStore();
store.dispatch = sinon.spy();
const message = stubPreparedMessages.get("console.group('bar')");

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

@ -65,7 +65,7 @@ describe("EvaluationResult component:", () => {
});
it("displays a [Learn more] link", () => {
const store = setupStore([]);
const store = setupStore();
const message = stubPreparedMessages.get("asdf()");

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

@ -31,7 +31,7 @@ describe("FilterBar component:", () => {
});
it("initial render", () => {
const store = setupStore([]);
const store = setupStore();
const wrapper = render(Provider({store}, FilterBar({ serviceContainer })));
const toolbar = wrapper.find(
@ -169,7 +169,7 @@ describe("FilterBar component:", () => {
});
it("does not display the number of hidden messages when there are no messages", () => {
const store = setupStore([]);
const store = setupStore();
const wrapper = mount(Provider({store}, FilterBar({ serviceContainer })));
const toolbar = wrapper.find(".webconsole-filterbar-filtered-messages");
expect(toolbar.exists()).toBeFalsy();
@ -194,7 +194,7 @@ describe("FilterBar component:", () => {
});
it("displays filter bar when button is clicked", () => {
const store = setupStore([]);
const store = setupStore();
expect(getAllUi(store.getState()).filterBarVisible).toBe(false);
expect(ServicesMock.prefs.getBoolPref(PREFS.UI.FILTER_BAR), false);
@ -236,7 +236,7 @@ describe("FilterBar component:", () => {
});
it("fires MESSAGES_CLEAR action when clear button is clicked", () => {
const store = setupStore([]);
const store = setupStore();
store.dispatch = sinon.spy();
const wrapper = mount(Provider({store}, FilterBar({ serviceContainer })));
@ -248,7 +248,7 @@ describe("FilterBar component:", () => {
});
it("sets filter text when text is typed", () => {
const store = setupStore([]);
const store = setupStore();
const wrapper = mount(Provider({store}, FilterBar({ serviceContainer })));
wrapper.find(".devtools-plaininput").simulate("input", { target: { value: "a" } });
@ -256,7 +256,7 @@ describe("FilterBar component:", () => {
});
it("toggles persist logs when checkbox is clicked", () => {
const store = setupStore([]);
const store = setupStore();
expect(getAllUi(store.getState()).persistLogs).toBe(false);
expect(ServicesMock.prefs.getBoolPref(PREFS.UI.PERSIST), false);

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

@ -70,7 +70,7 @@ describe("PageError component:", () => {
});
it("displays a [Learn more] link", () => {
const store = setupStore([]);
const store = setupStore();
const message = stubPreparedMessages.get("ReferenceError: asdf is not defined");
@ -104,7 +104,7 @@ describe("PageError component:", () => {
});
it("toggle the stacktrace when the collapse button is clicked", () => {
const store = setupStore([]);
const store = setupStore();
store.dispatch = sinon.spy();
const message = stubPreparedMessages.get("ReferenceError: asdf is not defined");

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

@ -9,7 +9,7 @@ const dom = require("devtools/client/shared/vendor/react-dom-factories");
const { createElement } = React;
const TestUtils = ReactDOM.TestUtils;
const actions = require("devtools/client/webconsole/new-console-output/actions/index");
const reduxActions = require("devtools/client/webconsole/new-console-output/actions/index");
const { configureStore } = require("devtools/client/webconsole/new-console-output/store");
const { IdGenerator } = require("devtools/client/webconsole/new-console-output/utils/id-generator");
const { stubPackets } = require("devtools/client/webconsole/new-console-output/test/fixtures/stubs/index");
@ -23,23 +23,27 @@ const {
function setupActions() {
// Some actions use dependency injection. This helps them avoid using state in
// a hard-to-test way. We need to inject stubbed versions of these dependencies.
const wrappedActions = Object.assign({}, actions);
const wrappedActions = Object.assign({}, reduxActions);
const idGenerator = new IdGenerator();
wrappedActions.messagesAdd = (packets) => {
return actions.messagesAdd(packets, idGenerator);
return reduxActions.messagesAdd(packets, idGenerator);
};
return {
...actions,
messagesAdd: packets => actions.messagesAdd(packets, idGenerator)
...reduxActions,
messagesAdd: packets => reduxActions.messagesAdd(packets, idGenerator)
};
}
/**
* Prepare the store for use in testing.
*/
function setupStore(input = [], hud, options, wrappedActions) {
function setupStore(input = [], {
storeOptions,
actions,
hud,
} = {}) {
if (!hud) {
hud = {
proxy: {
@ -47,12 +51,12 @@ function setupStore(input = [], hud, options, wrappedActions) {
}
};
}
const store = configureStore(hud, options);
const store = configureStore(hud, storeOptions);
// Add the messages from the input commands to the store.
const messagesAdd = wrappedActions
? wrappedActions.messagesAdd
: actions.messagesAdd;
const messagesAdd = actions
? actions.messagesAdd
: reduxActions.messagesAdd;
store.dispatch(messagesAdd(input.map(cmd => stubPackets.get(cmd))));
return store;

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

@ -204,7 +204,7 @@ describe("Filtering", () => {
describe("Clear filters", () => {
it("clears all filters", () => {
const store = setupStore([]);
const store = setupStore();
// Setup test case
store.dispatch(actions.filterToggle(FILTERS.ERROR));
@ -266,7 +266,7 @@ describe("Clear filters", () => {
describe("Resets filters", () => {
it("resets default filters value to their original one.", () => {
const store = setupStore([]);
const store = setupStore();
// Setup test case
store.dispatch(actions.filterToggle(FILTERS.ERROR));

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

@ -36,7 +36,7 @@ describe("Message reducer:", () => {
describe("messagesById", () => {
it("adds a message to an empty store", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const packet = stubPackets.get("console.log('foobar', 'test')");
const message = stubPreparedMessages.get("console.log('foobar', 'test')");
@ -47,15 +47,15 @@ describe("Message reducer:", () => {
it("increments repeat on a repeating log message", () => {
const key1 = "console.log('foobar', 'test')";
const { dispatch, getState } = setupStore([key1, key1]);
const { dispatch, getState } = setupStore([key1, key1], {actions});
const packet = clonePacket(stubPackets.get(key1));
const packet2 = clonePacket(packet);
// Repeat ID must be the same even if the timestamp is different.
packet.message.timeStamp = 1;
dispatch(actions.messagesAdd([packet]));
packet.message.timeStamp = 2;
dispatch(actions.messagesAdd([packet]));
packet2.message.timeStamp = 2;
dispatch(actions.messagesAdd([packet, packet2]));
const messages = getAllMessagesById(getState());
@ -184,11 +184,12 @@ describe("Message reducer:", () => {
"console.log(undefined)",
"console.log(undefined)",
],
null, {
logLimit: 2
},
actions
);
{
actions,
storeOptions: {
logLimit: 2
}
});
// Check that we have the expected data.
let repeats = getAllRepeatById(getState());
@ -215,7 +216,7 @@ describe("Message reducer:", () => {
});
it("properly limits number of messages", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const logLimit = 1000;
const packet = clonePacket(stubPackets.get("console.log(undefined)"));
@ -233,7 +234,7 @@ describe("Message reducer:", () => {
});
it("properly limits number of messages when there are nested groups", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const logLimit = 1000;
@ -279,7 +280,7 @@ describe("Message reducer:", () => {
it("properly limits number of groups", () => {
const logLimit = 100;
const { dispatch, getState } = setupStore([], null, {logLimit});
const { dispatch, getState } = setupStore([], {storeOptions: {logLimit}});
const packet = clonePacket(stubPackets.get("console.log(undefined)"));
const packetGroup = clonePacket(stubPackets.get("console.group('bar')"));
@ -309,7 +310,7 @@ describe("Message reducer:", () => {
it("properly limits number of collapsed groups", () => {
const logLimit = 100;
const { dispatch, getState } = setupStore([], null, {logLimit});
const { dispatch, getState } = setupStore([], {storeOptions: {logLimit}});
const packet = clonePacket(stubPackets.get("console.log(undefined)"));
const packetGroupCollapsed = clonePacket(
@ -345,7 +346,7 @@ describe("Message reducer:", () => {
});
it("does not add null messages to the store", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const message = stubPackets.get("console.time('bar')");
dispatch(actions.messagesAdd([message]));
@ -355,7 +356,7 @@ describe("Message reducer:", () => {
});
it("adds console.table call with unsupported type as console.log", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const packet = stubPackets.get("console.table('bar')");
dispatch(actions.messagesAdd([packet]));
@ -365,7 +366,7 @@ describe("Message reducer:", () => {
});
it("adds console.group messages to the store", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const message = stubPackets.get("console.group('bar')");
dispatch(actions.messagesAdd([message]));
@ -375,7 +376,7 @@ describe("Message reducer:", () => {
});
it("adds messages in console.group to the store", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const groupPacket = stubPackets.get("console.group('bar')");
const groupEndPacket = stubPackets.get("console.groupEnd('bar')");
@ -416,7 +417,7 @@ describe("Message reducer:", () => {
});
it("sets groupId property as expected", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
dispatch(actions.messagesAdd([
stubPackets.get("console.group('bar')"),
@ -429,7 +430,7 @@ describe("Message reducer:", () => {
});
it("does not display console.groupEnd messages to the store", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const message = stubPackets.get("console.groupEnd('bar')");
dispatch(actions.messagesAdd([message]));
@ -439,7 +440,7 @@ describe("Message reducer:", () => {
});
it("filters out message added after a console.groupCollapsed message", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
dispatch(actions.messagesAdd([
stubPackets.get("console.groupCollapsed('foo')"),
@ -451,7 +452,7 @@ describe("Message reducer:", () => {
});
it("adds console.dirxml call as console.log", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const packet = stubPackets.get("console.dirxml(window)");
dispatch(actions.messagesAdd([packet]));
@ -463,7 +464,7 @@ describe("Message reducer:", () => {
describe("expandedMessageIds", () => {
it("opens console.trace messages when they are added", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const message = stubPackets.get("console.trace()");
dispatch(actions.messagesAdd([message]));
@ -491,8 +492,10 @@ describe("Message reducer:", () => {
it("cleans the messages UI list when messages are pruned", () => {
const { dispatch, getState } = setupStore(
["console.trace()", "console.log(undefined)", "console.trace()"],
null, {
logLimit: 3
{
storeOptions: {
logLimit: 3
}
}
);
@ -524,7 +527,7 @@ describe("Message reducer:", () => {
});
it("opens console.group messages when they are added", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const message = stubPackets.get("console.group('bar')");
dispatch(actions.messagesAdd([message]));
@ -535,7 +538,7 @@ describe("Message reducer:", () => {
});
it("does not open console.groupCollapsed messages when they are added", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const message = stubPackets.get("console.groupCollapsed('foo')");
dispatch(actions.messagesAdd([message]));
@ -586,7 +589,7 @@ describe("Message reducer:", () => {
describe("currentGroup", () => {
it("sets the currentGroup when console.group message is added", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const packet = stubPackets.get("console.group('bar')");
dispatch(actions.messagesAdd([packet]));
@ -598,11 +601,13 @@ describe("Message reducer:", () => {
it("sets currentGroup to expected value when console.groupEnd is added", () => {
const { dispatch, getState } = setupStore([
"console.group('bar')",
"console.groupCollapsed('foo')"
"console.groupCollapsed('foo')",
"console.group('bar')",
"console.groupEnd('bar')",
]);
let currentGroup = getCurrentGroup(getState());
expect(currentGroup).toBe(getLastMessage(getState()).id);
expect(currentGroup).toBe(getMessageAt(getState(), 1).id);
const endFooPacket = stubPackets.get("console.groupEnd('foo')");
dispatch(actions.messagesAdd([endFooPacket]));
@ -629,7 +634,7 @@ describe("Message reducer:", () => {
describe("groupsById", () => {
it("adds the group with expected array when console.group message is added", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
const barPacket = stubPackets.get("console.group('bar')");
dispatch(actions.messagesAdd([barPacket]));
@ -675,25 +680,46 @@ describe("Message reducer:", () => {
"console.groupEnd('bar')",
"console.log('foobar', 'test')",
],
null, {
logLimit: 3
{
actions,
storeOptions: {
logLimit: 3
}
}
);
/*
* Here is the initial state of the console:
* bar
* noLabel
* bar
* foobar test
*/
// Check that we have the expected data.
let groupsById = getGroupsById(getState());
expect(groupsById.size).toBe(3);
// This addition will prune the first group (and its child group) out of the store.
/*
* bar
* foobar test
* undefined
*/
let packet = stubPackets.get("console.log(undefined)");
dispatch(actions.messagesAdd([packet]));
groupsById = getGroupsById(getState());
// There should be only the id of the last console.trace message.
// There should be only the id of the last console.group message.
expect(groupsById.size).toBe(1);
// This additions will prune the last group message out of the store.
/*
* foobar test
* undefined
* foobar test
*/
packet = stubPackets.get("console.log('foobar', 'test')");
dispatch(actions.messagesAdd([packet]));
@ -704,7 +730,7 @@ describe("Message reducer:", () => {
describe("networkMessagesUpdateById", () => {
it("adds the network update message when network update action is called", () => {
const { dispatch, getState } = setupStore([]);
const { dispatch, getState } = setupStore();
let packet = clonePacket(stubPackets.get("GET request"));
let updatePacket = clonePacket(stubPackets.get("GET request update"));
@ -749,8 +775,10 @@ describe("Message reducer:", () => {
});
it("cleans the networkMessagesUpdateById property when messages are pruned", () => {
const { dispatch, getState } = setupStore([], null, {
logLimit: 3
const { dispatch, getState } = setupStore([], {
storeOptions: {
logLimit: 3
}
});
// Add 3 network messages and their updates
@ -836,8 +864,10 @@ describe("Message reducer:", () => {
});
it("cleans the messagesTableDataById property when messages are pruned", () => {
const { dispatch, getState } = setupStore([], null, {
logLimit: 2
const { dispatch, getState } = setupStore([], {
storeOptions: {
logLimit: 2
}
});
// Add 2 table message and their data.
@ -875,8 +905,10 @@ describe("Message reducer:", () => {
// Log two distinct messages
const key1 = "console.log('foobar', 'test')";
const key2 = "console.log(undefined)";
const { dispatch, getState } = setupStore([key1, key2], null, {
logLimit: 2
const { dispatch, getState } = setupStore([key1, key2], {
storeOptions: {
logLimit: 2
}
});
// Then repeat the last one two times and log the first one again

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

@ -24,7 +24,7 @@ describe("Network message reducer:", () => {
});
beforeEach(() => {
const store = setupStore([]);
const store = setupStore();
getState = store.getState;
dispatch = store.dispatch;

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

@ -24,12 +24,15 @@ describe("Release actor enhancer:", () => {
const logLimit = 100;
let releasedActors = [];
const { dispatch, getState } = setupStore([], {
proxy: {
releaseActor: (actor) => {
releasedActors.push(actor);
storeOptions: {logLimit},
hud: {
proxy: {
releaseActor: (actor) => {
releasedActors.push(actor);
}
}
}
}, { logLimit });
});
// Add a log message.
dispatch(actions.messagesAdd([
@ -63,12 +66,15 @@ describe("Release actor enhancer:", () => {
const logLimit = 100;
let releasedActors = [];
const { dispatch, getState } = setupStore([], {
proxy: {
releaseActor: (actor) => {
releasedActors.push(actor);
storeOptions: {logLimit},
hud: {
proxy: {
releaseActor: (actor) => {
releasedActors.push(actor);
}
}
}
}, { logLimit });
});
// Add a log message.
dispatch(actions.messagesAdd([
@ -109,9 +115,11 @@ describe("Release actor enhancer:", () => {
it("properly releases backend actors after clear", () => {
let releasedActors = [];
const { dispatch, getState } = setupStore([], {
proxy: {
releaseActor: (actor) => {
releasedActors.push(actor);
hud: {
proxy: {
releaseActor: (actor) => {
releasedActors.push(actor);
}
}
}
});