mainmenu.spec.ts 4.0 KB

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