mainareawidget.spec.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { MainAreaWidget, Toolbar } from '@jupyterlab/apputils';
  4. import { MessageLoop } from '@lumino/messaging';
  5. import { BoxPanel, Widget } from '@lumino/widgets';
  6. describe('@jupyterlab/apputils', () => {
  7. describe('MainAreaWidget', () => {
  8. describe('#constructor()', () => {
  9. it('should create a new main area widget', () => {
  10. const content = new Widget();
  11. const widget = new MainAreaWidget({ content });
  12. expect(widget).toBeInstanceOf(MainAreaWidget);
  13. expect(widget.hasClass('jp-MainAreaWidget')).toBe(true);
  14. expect(widget.title.closable).toBe(true);
  15. });
  16. it('should allow toolbar options', () => {
  17. const content = new Widget();
  18. const toolbar = new Toolbar();
  19. const widget = new MainAreaWidget({ content, toolbar });
  20. expect(widget.hasClass('jp-MainAreaWidget')).toBe(true);
  21. expect(widget.toolbar).toBe(toolbar);
  22. });
  23. });
  24. describe('contentHeader', () => {
  25. it('should exist and have correct type', () => {
  26. const content = new Widget();
  27. const widget = new MainAreaWidget({ content });
  28. expect(widget.contentHeader).toBeInstanceOf(BoxPanel);
  29. });
  30. });
  31. describe('#onActivateRequest()', () => {
  32. it('should focus on activation', () => {
  33. const content = new Widget();
  34. const widget = new MainAreaWidget({ content });
  35. Widget.attach(widget, document.body);
  36. MessageLoop.sendMessage(widget, Widget.Msg.ActivateRequest);
  37. expect(document.activeElement).toBe(widget.content.node);
  38. });
  39. });
  40. describe('#onCloseRequest()', () => {
  41. it('should dispose on close', () => {
  42. const content = new Widget();
  43. const widget = new MainAreaWidget({ content });
  44. Widget.attach(widget, document.body);
  45. MessageLoop.sendMessage(widget, Widget.Msg.CloseRequest);
  46. expect(widget.isDisposed).toBe(true);
  47. });
  48. });
  49. describe('#onUpdateRequest()', () => {
  50. it('should propagate to the content', () => {
  51. let updated: boolean;
  52. const content = new (class extends Widget {
  53. onUpdateRequest() {
  54. updated = true;
  55. }
  56. })();
  57. const widget = new MainAreaWidget({ content });
  58. Widget.attach(widget, document.body);
  59. updated = false;
  60. MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
  61. expect(updated).toBe(true);
  62. });
  63. });
  64. describe('title', () => {
  65. it('should proxy from content to main', () => {
  66. const content = new Widget();
  67. const widget = new MainAreaWidget({ content });
  68. content.title.label = 'foo';
  69. expect(widget.title.label).toBe('foo');
  70. });
  71. it('should proxy from main to content', () => {
  72. const content = new Widget();
  73. const widget = new MainAreaWidget({ content });
  74. widget.title.label = 'foo';
  75. expect(content.title.label).toBe('foo');
  76. });
  77. });
  78. describe('dispose', () => {
  79. it('should dispose of main', () => {
  80. const content = new Widget();
  81. const widget = new MainAreaWidget({ content });
  82. content.dispose();
  83. expect(widget.isDisposed).toBe(true);
  84. });
  85. });
  86. });
  87. });