Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("pastes a cell", () => {
const firstId = uuid();
const secondId = uuid();
const thirdId = uuid();
const originalState = makeDocumentRecord({
notebook: Immutable.fromJS({
cellOrder: [firstId, secondId, thirdId],
cellMap: {
[firstId]: emptyCodeCell,
[secondId]: emptyCodeCell,
[thirdId]: emptyCodeCell
}
}),
cellFocused: secondId,
copied: emptyCodeCell.set("source", "COPY PASTA")
});
// We will paste the cell after the focused cell
const state = reducers(originalState, actions.pasteCell({}));
// The third cell should be our copied cell
const newCellId = state.getIn(["notebook", "cellOrder", 2]);
expect(state.getIn(["notebook", "cellMap", newCellId])).toEqual(
emptyCodeCell.set("source", "COPY PASTA")
);
expect(state.getIn(["notebook", "cellOrder"])).toEqual(
Immutable.List([firstId, secondId, newCellId, thirdId])
);
// Ensure it's a new cell
test("pastes a cell", () => {
const firstId = uuid();
const secondId = uuid();
const thirdId = uuid();
const originalState = makeDocumentRecord({
notebook: Immutable.fromJS({
cellOrder: [firstId, secondId, thirdId],
cellMap: {
[firstId]: emptyCodeCell,
[secondId]: emptyCodeCell,
[thirdId]: emptyCodeCell
}
}),
cellFocused: secondId,
copied: emptyCodeCell.set("source", "COPY PASTA")
});
// We will paste the cell after the focused cell
const state = reducers(originalState, actions.pasteCell({}));
// The third cell should be our copied cell
const newCellId = state.getIn(["notebook", "cellOrder", 2]);
expect(state.getIn(["notebook", "cellMap", newCellId])).toEqual(
emptyCodeCell.set("source", "COPY PASTA")
);
expect(state.getIn(["notebook", "cellOrder"])).toEqual(
Immutable.List([firstId, secondId, newCellId, thirdId])
);
// Ensure it's a new cell
[firstId]: emptyCodeCell,
[secondId]: emptyCodeCell,
[thirdId]: emptyCodeCell
}
}),
cellFocused: secondId,
copied: emptyCodeCell.set("source", "COPY PASTA")
});
// We will paste the cell after the focused cell
const state = reducers(originalState, actions.pasteCell({}));
// The third cell should be our copied cell
const newCellId = state.getIn(["notebook", "cellOrder", 2]);
expect(state.getIn(["notebook", "cellMap", newCellId])).toEqual(
emptyCodeCell.set("source", "COPY PASTA")
);
expect(state.getIn(["notebook", "cellOrder"])).toEqual(
Immutable.List([firstId, secondId, newCellId, thirdId])
);
// Ensure it's a new cell
expect(
Immutable.Set([firstId, secondId, thirdId]).has(newCellId)
).toBeFalsy();
});
});
[firstId]: emptyCodeCell,
[secondId]: emptyCodeCell,
[thirdId]: emptyCodeCell
}
}),
cellFocused: secondId,
copied: emptyCodeCell.set("source", "COPY PASTA")
});
// We will paste the cell after the focused cell
const state = reducers(originalState, actions.pasteCell({}));
// The third cell should be our copied cell
const newCellId = state.getIn(["notebook", "cellOrder", 2]);
expect(state.getIn(["notebook", "cellMap", newCellId])).toEqual(
emptyCodeCell.set("source", "COPY PASTA")
);
expect(state.getIn(["notebook", "cellOrder"])).toEqual(
Immutable.List([firstId, secondId, newCellId, thirdId])
);
// Ensure it's a new cell
expect(
Immutable.Set([firstId, secondId, thirdId]).has(newCellId)
).toBeFalsy();
});
});
test("updates the metadata of an output by cell ID & index", () => {
const originalState = monocellDocument.set(
"notebook",
appendCellToNotebook(
fixtureCommutable,
emptyCodeCell.set("outputs", Immutable.fromJS([{ empty: "output" }]))
)
);
const newOutputMetadata = Immutable.Map({ meta: "data" });
const id: string = originalState.getIn(["notebook", "cellOrder"]).last();
const state = reducers(
originalState,
actions.updateOutputMetadata({
id,
metadata: newOutputMetadata,
index: 0,
mediaType: "test/mediatype"
})
);
test("copies a cell", () => {
const firstId = uuid();
const secondId = uuid();
const thirdId = uuid();
const originalState = makeDocumentRecord({
notebook: Immutable.fromJS({
cellOrder: [firstId, secondId, thirdId],
cellMap: {
[firstId]: emptyCodeCell.set("source", "data"),
[secondId]: emptyCodeCell,
[thirdId]: emptyCodeCell
}
}),
cellFocused: secondId,
copied: null
});
const state = reducers(originalState, actions.copyCell({ id: firstId }));
expect(state.get("copied")).toEqual(emptyCodeCell.set("source", "data"));
expect(state.get("notebook")).toEqual(
Immutable.fromJS({
cellOrder: [firstId, secondId, thirdId],
cellMap: {
test("clear prompts on code cells", () => {
let originalState = initialDocument.set(
"notebook",
appendCellToNotebook(
fixtureCommutable,
emptyCodeCell.set("outputs", ["dummy outputs"])
)
);
const id: string = originalState.getIn(["notebook", "cellOrder"]).last();
originalState = originalState.set(
"cellPrompts",
Immutable.Map({
[id]: Immutable.List([{ prompt: "Test: ", password: false }])
})
);
expect(originalState.getIn(["cellPrompts", id]).size).toBe(1);
const state = reducers(originalState, actions.clearOutputs({ id }));
const prompts = state.getIn(["cellPrompts", id]);
expect(prompts.size).toBe(0);
});
const originalState = makeDocumentRecord({
notebook: Immutable.fromJS({
cellOrder: [firstId, secondId, thirdId],
cellMap: {
[firstId]: emptyCodeCell.set("source", "data"),
[secondId]: emptyCodeCell,
[thirdId]: emptyCodeCell
}
}),
cellFocused: secondId,
copied: null
});
const state = reducers(originalState, actions.cutCell({ id: firstId }));
expect(state.get("copied")).toEqual(emptyCodeCell.set("source", "data"));
expect(state.getIn(["notebook", "cellMap", firstId])).toBeUndefined();
});
});
["metadata", "kernelspec", "name"],
"python2"
);
if (config) {
if (config.codeCellCount) {
for (let i = 1; i < config.codeCellCount; i++) {
notebook = appendCellToNotebook(notebook, emptyCodeCell);
}
}
if (config.markdownCellCount) {
for (let i = 0; i < config.markdownCellCount; i++) {
notebook = appendCellToNotebook(
notebook,
emptyCodeCell.set("cell_type", "markdown")
);
}
}
if (config.hideAll) {
notebook = hideCells(notebook);
}
}
return notebook;
}