/** * Prepare actions for use in testing.
*/ 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({}, reduxActions);
/** * Prepare the store for use in testing.
*/ function setupStore(
input = [],
{ storeOptions = {}, actions, webConsoleUI } = {}
) { if (!webConsoleUI) {
webConsoleUI = getWebConsoleUiMock();
} const store = configureStore(webConsoleUI, {
...storeOptions,
thunkArgs: { toolbox: {}, webConsoleUI },
telemetry: new Telemetry(),
});
// Add the messages from the input commands to the store. const messagesAdd = actions ? actions.messagesAdd : reduxActions.messagesAdd;
store.dispatch(messagesAdd(input.map(cmd => stubPackets.get(cmd))));
return store;
}
/** * Create deep copy of given packet object.
*/ function clonePacket(packet) { const strPacket = getSerializedPacket(packet); return parsePacketAndCreateFronts(JSON.parse(strPacket));
}
/** * 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 messageMap = getMutableMessagesById(state); return messageMap.get(state.messages.mutableMessagesOrder[index]);
}
/** * Return the first message in the store. * * @param {object} state - The redux state of the console. * @return {Message} - The last message, or undefined if there are no message in store.
*/ function getFirstMessage(state) { return getMessageAt(state, 0);
}
/** * Return the last message in the store. * * @param {object} state - The redux state of the console. * @return {Message} - The last message, or undefined if there are no message in store.
*/ function getLastMessage(state) { const lastIndex = state.messages.mutableMessagesOrder.length - 1; return getMessageAt(state, lastIndex);
}
function formatErrorTextWithCausedBy(text) { // The component text does not append new line character before // the "Caused by" label, so add it here to make the assertions // look more legible return text.replace(/Caused by/g, "\nCaused by");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.