contents.spec.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (c) Jupyter Development Team.
  2. // Copyright (c) Bloomberg Finance LP.
  3. // Distributed under the terms of the Modified BSD License.
  4. import * as path from 'path';
  5. import { expect, test } from '@jupyterlab/galata';
  6. test.describe('Contents API Tests', () => {
  7. test('Upload directory to server', async ({ page, tmpPath }) => {
  8. await page.contents.uploadDirectory(
  9. path.resolve(__dirname, './upload'),
  10. tmpPath
  11. );
  12. // Upload removed existing tmpPath, so we need to get inside
  13. await page.dblclick(`text=${tmpPath}`);
  14. expect(await page.waitForSelector('text=sub_folder')).toBeTruthy();
  15. expect(await page.waitForSelector('text=upload_image.png')).toBeTruthy();
  16. expect(
  17. await page.waitForSelector('text=upload_notebook.ipynb')
  18. ).toBeTruthy();
  19. });
  20. test('File operations', async ({ page, tmpPath }) => {
  21. await page.contents.uploadFile(
  22. path.resolve(__dirname, './upload/upload_image.png'),
  23. `${tmpPath}/upload_image.png`
  24. );
  25. await page.contents.renameFile(
  26. `${tmpPath}/upload_image.png`,
  27. `${tmpPath}/renamed_image.png`
  28. );
  29. expect(
  30. await page.contents.fileExists(`${tmpPath}/renamed_image.png`)
  31. ).toEqual(true);
  32. await page.filebrowser.openDirectory(tmpPath);
  33. expect(await page.filebrowser.getCurrentDirectory()).toEqual(tmpPath);
  34. expect(
  35. await page.contents.deleteFile(`${tmpPath}/renamed_image.png`)
  36. ).toEqual(true);
  37. });
  38. test('Go to home directory', async ({ page }) => {
  39. expect(await page.filebrowser.openHomeDirectory()).toEqual(true);
  40. });
  41. test('File Explorer visibility', async ({ page, tmpPath }) => {
  42. await page.contents.uploadDirectory(
  43. path.resolve(__dirname, './upload'),
  44. tmpPath
  45. );
  46. await page.contents.deleteFile(`${tmpPath}/upload_image.png`);
  47. expect(
  48. await page.filebrowser.isFileListedInBrowser('upload_image.png')
  49. ).toEqual(false);
  50. await page.filebrowser.revealFileInBrowser(
  51. `${tmpPath}/sub_folder/upload_image.png`
  52. );
  53. expect(
  54. await page.filebrowser.isFileListedInBrowser('upload_image.png')
  55. ).toEqual(true);
  56. });
  57. test('Delete uploads', async ({ page, tmpPath }) => {
  58. await page.contents.uploadFile(
  59. path.resolve(__dirname, './upload/upload_notebook.ipynb'),
  60. `${tmpPath}/sub_dir/notebook.ipynb`
  61. );
  62. expect(
  63. await page.contents.deleteFile(`${tmpPath}/sub_dir/notebook.ipynb`)
  64. ).toEqual(true);
  65. expect(await page.contents.deleteDirectory(`${tmpPath}/sub_dir`)).toEqual(
  66. true
  67. );
  68. });
  69. });