Example #1
0
      it('should update the node content on command change event', async () => {
        const id = 'to-be-removed';
        let iconClassValue: string | null = null;
        const cmd = commands.addCommand(id, {
          execute: () => {
            /* no op */
          },
          label: 'Label-only button',
          iconClass: () => iconClassValue
        });
        const button = new CommandToolbarButton({
          commands,
          id
        });
        await render(button);
        const buttonNode = button.node.firstChild as HTMLButtonElement;
        expect(buttonNode.textContent).to.equal('Label-only button');
        expect(buttonNode.classList.contains(iconClassValue)).to.equal(false);

        iconClassValue = 'updated-icon-class';
        commands.notifyCommandChanged(id);
        await render(button);
        const wrapperNode = buttonNode.firstChild as HTMLElement;
        const iconNode = wrapperNode.firstChild as HTMLElement;
        expect(iconNode.classList.contains(iconClassValue)).to.equal(true);

        cmd.dispose();
      });
Example #2
0
 it('should be emitted when a command is changed', () => {
   let called = false;
   registry.addCommand('test', NULL_COMMAND);
   registry.commandChanged.connect((reg, args) => {
     expect(reg).to.equal(registry);
     expect(args.id).to.equal('test');
     expect(args.type).to.equal('changed');
     called = true;
   });
   registry.notifyCommandChanged('test');
   expect(called).to.equal(true);
 });
Example #3
0
 execute: () => {
   if (searchInstance) {
     searchInstance.focusInput();
     return;
   }
   const provider = new NotebookSearchProvider();
   searchInstance = new SearchInstance(nbWidget, provider);
   searchInstance.disposed.connect(() => {
     searchInstance = undefined;
     // find next and previous are now not enabled
     commands.notifyCommandChanged();
   });
   // find next and previous are now enabled
   commands.notifyCommandChanged();
   searchInstance.focusInput();
 }
Example #4
0
 it('should update state classes', async () => {
   enabled = false;
   toggled = true;
   visible = false;
   const button = new CommandToolbarButton({
     commands,
     id: testLogCommandId
   });
   await render(button);
   const buttonNode = button.node.firstChild as HTMLButtonElement;
   expect(buttonNode.disabled).to.equal(true);
   expect(buttonNode.classList.contains('p-mod-toggled')).to.equal(true);
   expect(buttonNode.classList.contains('p-mod-hidden')).to.equal(true);
   enabled = true;
   visible = true;
   commands.notifyCommandChanged(testLogCommandId);
   expect(buttonNode.disabled).to.equal(false);
   expect(buttonNode.classList.contains('p-mod-toggled')).to.equal(true);
   expect(buttonNode.classList.contains('p-mod-hidden')).to.equal(false);
   enabled = false;
   visible = false;
   button.dispose();
 });
Example #5
0
 expect(() => {
   registry.notifyCommandChanged('foo');
 }).to.throw(Error);
Example #6
0
 tracker.currentChanged.connect(() => {
   if (tracker.size <= 1) {
     commands.notifyCommandChanged(CommandIDs.zoomIn);
   }
 });
Example #7
0
 searchInstance.disposed.connect(() => {
   searchInstance = undefined;
   // find next and previous are now not enabled
   commands.notifyCommandChanged();
 });