Bug 1363680 - Adapt mocha tests. r=Honza

MozReview-Commit-ID: Jl48dtpqlm7

--HG--
extra : rebase_source : aa94cd8db6785b19008f67086cd0a9ca3371bcab
This commit is contained in:
Nicolas Chevobbe 2017-06-05 13:41:09 +02:00
Родитель 0cb8dfb5b1
Коммит 33b54ea1bc
3 изменённых файлов: 57 добавлений и 10 удалений

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

@ -67,10 +67,12 @@ describe("ConsoleAPICall component:", () => {
});
it("renders repeat node", () => {
const message =
stubPreparedMessages.get("console.log('foobar', 'test')")
.set("repeat", 107);
const wrapper = render(ConsoleApiCall({ message, serviceContainer }));
const message = stubPreparedMessages.get("console.log('foobar', 'test')");
const wrapper = render(ConsoleApiCall({
message,
serviceContainer,
repeat: 107
}));
expect(wrapper.find(".message-repeats").text()).toBe("107");
expect(wrapper.find(".message-repeats").prop("title")).toBe("107 repeats");

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

@ -11,6 +11,9 @@ const actions = require("devtools/client/webconsole/new-console-output/actions/i
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");
const {
getAllMessagesById,
} = require("devtools/client/webconsole/new-console-output/selectors/messages");
/**
* Prepare actions for use in testing.
@ -66,10 +69,23 @@ function clonePacket(packet) {
return JSON.parse(JSON.stringify(packet));
}
/**
* Return the message in the store at the given index.
*
* @param {object} state - The redux state of the console.
* @param {int} index - The index of the message in the map.
* @return {Message} - The message, or undefined if the index does not exists in the map.
*/
function getMessageAt(state, index) {
const messages = getAllMessagesById(state);
return messages.get([...messages.keys()][index]);
}
module.exports = {
clonePacket,
getMessageAt,
renderComponent,
setupActions,
setupStore,
renderComponent,
shallowRenderComponent,
clonePacket
};

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

@ -7,13 +7,15 @@ const {
getAllMessagesById,
getAllMessagesTableDataById,
getAllMessagesUiById,
getAllRepeatById,
getCurrentGroup,
getVisibleMessages,
} = require("devtools/client/webconsole/new-console-output/selectors/messages");
const {
clonePacket,
getMessageAt,
setupActions,
setupStore,
clonePacket
} = require("devtools/client/webconsole/new-console-output/test/helpers");
const { stubPackets, stubPreparedMessages } = require("devtools/client/webconsole/new-console-output/test/fixtures/stubs/index");
const {
@ -57,7 +59,31 @@ describe("Message reducer:", () => {
const messages = getAllMessagesById(getState());
expect(messages.size).toBe(1);
expect(messages.first().repeat).toBe(4);
const repeat = getAllRepeatById(getState());
expect(repeat[messages.first().id]).toBe(4);
});
it("does not increment repeat after closing a group", () => {
const logKey = "console.log('foobar', 'test')";
const { getState } = setupStore([
logKey,
logKey,
"console.group('bar')",
logKey,
logKey,
logKey,
"console.groupEnd()",
logKey,
]);
const messages = getAllMessagesById(getState());
expect(messages.size).toBe(4);
const repeat = getAllRepeatById(getState());
expect(repeat[messages.first().id]).toBe(2);
expect(repeat[getMessageAt(getState(), 2).id]).toBe(3);
expect(repeat[messages.last().id]).toBe(undefined);
});
it("does not clobber a unique message", () => {
@ -72,8 +98,10 @@ describe("Message reducer:", () => {
const messages = getAllMessagesById(getState());
expect(messages.size).toBe(2);
expect(messages.first().repeat).toBe(3);
expect(messages.last().repeat).toBe(1);
const repeat = getAllRepeatById(getState());
expect(repeat[messages.first().id]).toBe(3);
expect(repeat[messages.last().id]).toBe(undefined);
});
it("adds a message in response to console.clear()", () => {
@ -104,6 +132,7 @@ describe("Message reducer:", () => {
expect(getAllGroupsById(state).size).toBe(0);
expect(getAllMessagesTableDataById(state).size).toBe(0);
expect(getCurrentGroup(state)).toBe(null);
expect(getAllRepeatById(state)).toEqual({});
});
it("properly limits number of messages", () => {