|
@@ -4,44 +4,196 @@
|
|
|
import expect = require('expect.js');
|
|
|
|
|
|
import {
|
|
|
- TooolbarItems
|
|
|
+ MimeData
|
|
|
+} from 'phosphor-dragdrop';
|
|
|
+
|
|
|
+import {
|
|
|
+ CodeCellWidget
|
|
|
+} from '../../../../lib/notebook/cells/widget';
|
|
|
+
|
|
|
+import {
|
|
|
+ JUPYTER_CELL_MIME, NotebookActions
|
|
|
+} from '../../../../lib/notebook/notebook/actions';
|
|
|
+
|
|
|
+import {
|
|
|
+ ToolbarItems
|
|
|
+} from '../../../../lib/notebook/notebook/default-toolbar';
|
|
|
+
|
|
|
+import {
|
|
|
+ NotebookModel
|
|
|
} from '../../../../lib/notebook/notebook/model';
|
|
|
|
|
|
+import {
|
|
|
+ NotebookPanel
|
|
|
+} from '../../../../lib/notebook/notebook/panel';
|
|
|
+
|
|
|
+import {
|
|
|
+ MockContext
|
|
|
+} from '../../docmanager/mockcontext';
|
|
|
+
|
|
|
+import {
|
|
|
+ defaultRenderMime
|
|
|
+} from '../../rendermime/rendermime.spec';
|
|
|
+
|
|
|
+import {
|
|
|
+ DEFAULT_CONTENT
|
|
|
+} from '../utils';
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Default data.
|
|
|
+ */
|
|
|
+const rendermime = defaultRenderMime();
|
|
|
+const clipboard = new MimeData();
|
|
|
+
|
|
|
|
|
|
describe('notebook/notebook/default-toolbar', () => {
|
|
|
|
|
|
describe('TooolbarItems', () => {
|
|
|
|
|
|
+ let panel: NotebookPanel;
|
|
|
+ let context: MockContext<NotebookModel>;
|
|
|
+
|
|
|
+ beforeEach(() => {
|
|
|
+ panel = new NotebookPanel({ rendermime, clipboard });
|
|
|
+ let model = new NotebookModel();
|
|
|
+ model.fromJSON(DEFAULT_CONTENT);
|
|
|
+ context = new MockContext<NotebookModel>(model);
|
|
|
+ context.changeKernel({ name: 'python' });
|
|
|
+ panel.context = context;
|
|
|
+ return panel;
|
|
|
+ });
|
|
|
+
|
|
|
+ afterEach(() => {
|
|
|
+ panel.dispose();
|
|
|
+ });
|
|
|
+
|
|
|
describe('#createSaveButton()', () => {
|
|
|
|
|
|
+ it('should save when clicked', () => {
|
|
|
+ let button = ToolbarItems.createSaveButton(panel);
|
|
|
+ button.attach(document.body);
|
|
|
+ button.node.click();
|
|
|
+ expect(context.methods).to.contain('save');
|
|
|
+ button.dispose();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should have the `'jp-NBToolbar-save'` class", () => {
|
|
|
+ let button = ToolbarItems.createSaveButton(panel);
|
|
|
+ expect(button.hasClass('jp-NBToolbar-save')).to.be(true);
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
describe('#createInsertButton()', () => {
|
|
|
|
|
|
+ it('should insert below when clicked', () => {
|
|
|
+ let button = ToolbarItems.createInsertButton(panel);
|
|
|
+ button.attach(document.body);
|
|
|
+ button.node.click();
|
|
|
+ expect(panel.content.activeCellIndex).to.be(1);
|
|
|
+ expect(panel.content.activeCell).to.be.a(CodeCellWidget);
|
|
|
+ button.dispose();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should have the `'jp-NBToolbar-insert'` class", () => {
|
|
|
+ let button = ToolbarItems.createInsertButton(panel);
|
|
|
+ expect(button.hasClass('jp-NBToolbar-insert')).to.be(true);
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
describe('#createCutButton()', () => {
|
|
|
|
|
|
+ it('should cut when clicked', () => {
|
|
|
+ let button = ToolbarItems.createCutButton(panel);
|
|
|
+ let count = panel.content.childCount();
|
|
|
+ button.attach(document.body);
|
|
|
+ button.node.click();
|
|
|
+ expect(panel.content.childCount()).to.be(count - 1);
|
|
|
+ expect(clipboard.hasData(JUPYTER_CELL_MIME)).to.be(true);
|
|
|
+ button.dispose();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should have the `'jp-NBToolbar-cut'` class", () => {
|
|
|
+ let button = ToolbarItems.createCutButton(panel);
|
|
|
+ expect(button.hasClass('jp-NBToolbar-cut')).to.be(true);
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
describe('#createCopyButton()', () => {
|
|
|
|
|
|
+ it('should copy when clicked', () => {
|
|
|
+ let button = ToolbarItems.createCopyButton(panel);
|
|
|
+ let count = panel.content.childCount();
|
|
|
+ button.attach(document.body);
|
|
|
+ button.node.click();
|
|
|
+ expect(panel.content.childCount()).to.be(count);
|
|
|
+ expect(clipboard.hasData(JUPYTER_CELL_MIME)).to.be(true);
|
|
|
+ button.dispose();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should have the `'jp-NBToolbar-copy'` class", () => {
|
|
|
+ let button = ToolbarItems.createCopyButton(panel);
|
|
|
+ expect(button.hasClass('jp-NBToolbar-copy')).to.be(true);
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
describe('#createPasteButton()', () => {
|
|
|
|
|
|
+ it('should paste when clicked', () => {
|
|
|
+ let button = ToolbarItems.createPasteButton(panel);
|
|
|
+ let count = panel.content.childCount();
|
|
|
+ button.attach(document.body);
|
|
|
+ NotebookActions.copy(panel.content, clipboard);
|
|
|
+ button.node.click();
|
|
|
+ expect(panel.content.childCount()).to.be(count + 1);
|
|
|
+ button.dispose();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should have the `'jp-NBToolbar-paste'` class", () => {
|
|
|
+ let button = ToolbarItems.createPasteButton(panel);
|
|
|
+ expect(button.hasClass('jp-NBToolbar-paste')).to.be(true);
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
describe('#createRunButton()', () => {
|
|
|
|
|
|
+ it('should run and advance when clicked', () => {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should have the `'jp-NBToolbar-run'` class", () => {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
describe('#createInterruptButton()', () => {
|
|
|
|
|
|
+ it('should interrupt the kernel when clicked', () => {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should have the `'jp-NBToolbar-interrupt'` class", () => {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
describe('#createRestartButton()', () => {
|
|
|
|
|
|
+ it('should restart the kernel when clicked', () => {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should have the `'jp-NBToolbar-restart'` class", () => {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
describe('#createCellTypeItem()', () => {
|