How to use the @nteract/commutable.emptyCodeCell.set function in @nteract/commutable

To help you get started, we’ve selected a few @nteract/commutable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
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
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
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
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
[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();
  });
});
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
[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();
  });
});
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
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"
      })
    );
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
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: {
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
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);
  });
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
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();
  });
});
github nteract / nteract / packages / core / src / dummy / index.js View on Github external
["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;
}