util.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { galata, test } from '@jupyterlab/galata';
  4. const menuPaths = [
  5. 'Edit',
  6. 'View',
  7. 'Run',
  8. 'Kernel',
  9. 'Tabs',
  10. 'Settings',
  11. 'Settings>JupyterLab Theme',
  12. 'Settings>Language',
  13. 'Settings>Console Run Keystroke',
  14. 'Settings>Text Editor Key Map',
  15. 'Settings>Text Editor Theme',
  16. 'Settings>Text Editor Indentation',
  17. 'Settings>Terminal Theme',
  18. 'Help'
  19. ];
  20. const sidebarIds: galata.SidebarTabId[] = [
  21. 'filebrowser',
  22. 'jp-property-inspector',
  23. 'jp-running-sessions',
  24. 'table-of-contents',
  25. 'extensionmanager.main-view'
  26. ];
  27. // eslint-disable-next-line jest/no-export
  28. export function runMenuOpenTest(): void {
  29. menuPaths.forEach(menuPath => {
  30. test(`Open menu item ${menuPath}`, async () => {
  31. await galata.menu.open(menuPath);
  32. expect(await galata.menu.isOpen(menuPath)).toBeTruthy();
  33. const imageName = `opened-menu-${menuPath}`;
  34. const menu = await galata.menu.getOpenMenu();
  35. await galata.capture.screenshot(imageName, menu);
  36. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  37. });
  38. });
  39. test('Close all menus', async () => {
  40. await galata.menu.closeAll();
  41. await expect(galata.menu.isAnyOpen()).resolves.toEqual(false);
  42. });
  43. }
  44. // eslint-disable-next-line jest/no-export
  45. export function runSidebarOpenTest(): void {
  46. sidebarIds.forEach(sidebarId => {
  47. test(`Open Sidebar tab ${sidebarId}`, async () => {
  48. await galata.sidebar.openTab(sidebarId);
  49. expect(await galata.sidebar.isTabOpen(sidebarId)).toBeTruthy();
  50. const imageName = `opened-sidebar-${sidebarId}`;
  51. const position = await galata.sidebar.getTabPosition(sidebarId);
  52. const sidebar = await galata.sidebar.getContentPanel(position);
  53. await galata.capture.screenshot(imageName, sidebar);
  54. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  55. });
  56. });
  57. test('Open file browser tab', async () => {
  58. await galata.sidebar.openTab('filebrowser');
  59. await expect(galata.sidebar.isTabOpen('filebrowser')).resolves.toEqual(
  60. true
  61. );
  62. });
  63. }