mainmenu.spec.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import 'jest';
  4. import { find, ArrayExt } from '@lumino/algorithm';
  5. import { CommandRegistry } from '@lumino/commands';
  6. import { Menu } from '@lumino/widgets';
  7. import {
  8. MainMenu,
  9. EditMenu,
  10. FileMenu,
  11. HelpMenu,
  12. KernelMenu,
  13. RunMenu,
  14. SettingsMenu,
  15. TabsMenu,
  16. ViewMenu
  17. } from '@jupyterlab/mainmenu';
  18. describe('@jupyterlab/mainmenu', () => {
  19. describe('MainMenu', () => {
  20. let commands: CommandRegistry;
  21. let mainMenu: MainMenu;
  22. beforeAll(() => {
  23. commands = new CommandRegistry();
  24. });
  25. beforeEach(() => {
  26. mainMenu = new MainMenu(commands);
  27. });
  28. afterEach(() => {
  29. mainMenu.dispose();
  30. });
  31. describe('#constructor()', () => {
  32. it('should construct a new main menu', () => {
  33. const menu = new MainMenu(new CommandRegistry());
  34. expect(menu).toBeInstanceOf(MainMenu);
  35. });
  36. });
  37. describe('#addMenu()', () => {
  38. it('should add a new menu', () => {
  39. const menu = new Menu({ commands });
  40. mainMenu.addMenu(menu);
  41. expect(find(mainMenu.menus, m => menu === m) !== undefined).toBe(true);
  42. });
  43. it('should take a rank as an option', () => {
  44. const menu1 = new Menu({ commands });
  45. const menu2 = new Menu({ commands });
  46. mainMenu.addMenu(menu1, { rank: 300 });
  47. mainMenu.addMenu(menu2, { rank: 200 });
  48. expect(ArrayExt.firstIndexOf(mainMenu.menus, menu1)).toBe(6);
  49. expect(ArrayExt.firstIndexOf(mainMenu.menus, menu2)).toBe(5);
  50. });
  51. });
  52. describe('#fileMenu', () => {
  53. it('should be a FileMenu', () => {
  54. expect(mainMenu.fileMenu).toBeInstanceOf(FileMenu);
  55. });
  56. it('should be the first menu', () => {
  57. expect(
  58. ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.fileMenu.menu)
  59. ).toBe(0);
  60. });
  61. });
  62. describe('#editMenu', () => {
  63. it('should be a EditMenu', () => {
  64. expect(mainMenu.editMenu).toBeInstanceOf(EditMenu);
  65. });
  66. it('should be the second menu', () => {
  67. expect(
  68. ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.editMenu.menu)
  69. ).toBe(1);
  70. });
  71. });
  72. describe('#viewMenu', () => {
  73. it('should be a ViewMenu', () => {
  74. expect(mainMenu.viewMenu).toBeInstanceOf(ViewMenu);
  75. });
  76. it('should be the third menu', () => {
  77. expect(
  78. ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.viewMenu.menu)
  79. ).toBe(2);
  80. });
  81. });
  82. describe('#runMenu', () => {
  83. it('should be a RunMenu', () => {
  84. expect(mainMenu.runMenu).toBeInstanceOf(RunMenu);
  85. });
  86. it('should be the fourth menu', () => {
  87. expect(
  88. ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.runMenu.menu)
  89. ).toBe(3);
  90. });
  91. });
  92. describe('#kernelMenu', () => {
  93. it('should be a KernelMenu', () => {
  94. expect(mainMenu.kernelMenu).toBeInstanceOf(KernelMenu);
  95. });
  96. it('should be the fifth menu', () => {
  97. expect(
  98. ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.kernelMenu.menu)
  99. ).toBe(4);
  100. });
  101. });
  102. describe('#tabsMenu', () => {
  103. it('should be a TabsMenu', () => {
  104. expect(mainMenu.tabsMenu).toBeInstanceOf(TabsMenu);
  105. });
  106. it('should be the sixth menu', () => {
  107. expect(
  108. ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.tabsMenu.menu)
  109. ).toBe(5);
  110. });
  111. });
  112. describe('#settingsMenu', () => {
  113. it('should be a SettingsMenu', () => {
  114. expect(mainMenu.settingsMenu).toBeInstanceOf(SettingsMenu);
  115. });
  116. it('should be the seventh menu', () => {
  117. expect(
  118. ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.settingsMenu.menu)
  119. ).toBe(6);
  120. });
  121. });
  122. describe('#helpMenu', () => {
  123. it('should be a HelpMenu', () => {
  124. expect(mainMenu.helpMenu).toBeInstanceOf(HelpMenu);
  125. });
  126. it('should be the eighth menu', () => {
  127. expect(
  128. ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.helpMenu.menu)
  129. ).toBe(7);
  130. });
  131. });
  132. });
  133. });