it('should paste when clicked', async () => {
   const button = ToolbarItems.createPasteButton(panel);
   const count = panel.content.widgets.length;
   Widget.attach(button, document.body);
   await framePromise();
   NotebookActions.copy(panel.content);
   (button.node.firstChild as HTMLElement).click();
   await sleep();
   expect(panel.content.widgets.length).to.equal(count + 1);
   button.dispose();
 });
Example #2
0
 it('should emit a tick identical to the poll state', async () => {
   poll = new Poll<void, void>({
     factory: () => Promise.resolve(),
     frequency: { interval: 100, backoff: false },
     name: '@jupyterlab/test-coreutils:Poll#ticked-3'
   });
   poll.ticked.connect((_, tick) => {
     expect(tick).to.equal(poll.state);
   });
   await sleep(250);
 });
Example #3
0
 it('should emit when the poll ticks after `when` resolves', async () => {
   const expected = 'when-resolved resolved';
   const ticker: IPoll.Phase[] = [];
   poll = new Poll<void, void>({
     factory: () => Promise.resolve(),
     frequency: { interval: 2000, backoff: false },
     name: '@jupyterlab/test-coreutils:Poll#ticked-1'
   });
   poll.ticked.connect(() => {
     ticker.push(poll.state.phase);
   });
   await sleep(200); // Sleep for less than the interval.
   expect(ticker.join(' ')).to.equal(expected);
 });
Example #4
0
 it('should resolve after a tick', async () => {
   poll = new Poll({
     factory: () => Promise.resolve(),
     frequency: { interval: 2000, backoff: false },
     name: '@jupyterlab/test-coreutils:Poll#tick-1'
   });
   const expected = 'when-resolved resolved';
   const ticker: IPoll.Phase[] = [];
   const tock = (poll: IPoll) => {
     ticker.push(poll.state.phase);
     poll.tick.then(tock).catch(() => undefined);
   };
   void poll.tick.then(tock);
   await sleep(200); // Sleep for less than the interval.
   expect(ticker.join(' ')).to.equal(expected);
 });
Example #5
0
      it('should resolve after the reveal and context ready promises', async () => {
        const x = Object.create(null);
        const reveal = sleep(300, x);
        const contextReady = Promise.all([context.ready, x]);
        const widget = new DocumentWidget({ context, content, reveal });
        expect(widget.isRevealed).to.equal(false);

        // Our promise should resolve before the widget reveal promise.
        expect(await Promise.race([widget.revealed, reveal])).to.equal(x);
        // The context ready promise should also resolve first.
        context.initialize(true);
        expect(
          await Promise.race([widget.revealed, contextReady])
        ).to.deep.equal([undefined, x]);
        // The widget.revealed promise should finally resolve.
        expect(await widget.revealed).to.be.undefined;
      });
Example #6
0
 it('should resolve after `ticked` emits in lock step', async () => {
   poll = new Poll({
     factory: () =>
       Math.random() > 0.5 ? Promise.resolve() : Promise.reject(),
     frequency: { interval: 0, backoff: false },
     name: '@jupyterlab/test-coreutils:Poll#tick-2'
   });
   const ticker: IPoll.Phase[] = [];
   const tocker: IPoll.Phase[] = [];
   poll.ticked.connect(async (_, state) => {
     ticker.push(state.phase);
     expect(ticker.length).to.equal(tocker.length + 1);
   });
   const tock = async (poll: IPoll) => {
     tocker.push(poll.state.phase);
     expect(ticker.join(' ')).to.equal(tocker.join(' '));
     poll.tick.then(tock).catch(() => undefined);
   };
   // Kick off the promise listener, but void its settlement to verify that
   // the poll's internal sync of the promise and the signal is correct.
   void poll.tick.then(tock);
   await poll.stop();
   await poll.start();
   await poll.tick;
   await poll.refresh();
   await poll.tick;
   await poll.refresh();
   await poll.tick;
   await poll.refresh();
   await poll.tick;
   await poll.stop();
   await poll.start();
   await poll.tick;
   await sleep(100);
   await poll.tick;
   expect(ticker.join(' ')).to.equal(tocker.join(' '));
 });