|
| 1 | +import { expect, test } from '@jupyterlab/galata'; |
| 2 | + |
| 3 | +import { ContentsHelper } from './utils/contents'; |
| 4 | +import { TERMINAL_SELECTOR, WAIT_MS, inputLine } from './utils/misc'; |
| 5 | + |
| 6 | +// Long wait such as for starting/stopping a complex WebAssembly command. |
| 7 | +export const LONG_WAIT_MS = 300; |
| 8 | + |
| 9 | +test.describe('individual command', () => { |
| 10 | + test.beforeEach(async ({ page }) => { |
| 11 | + await page.goto(); |
| 12 | + await page.waitForTimeout(WAIT_MS); |
| 13 | + |
| 14 | + // Overwrite the (read-only) page.contents with our own ContentsHelper. |
| 15 | + // @ts-ignore |
| 16 | + page.contents = new ContentsHelper(page); |
| 17 | + |
| 18 | + await page.menu.clickMenuItem('File>New>Terminal'); |
| 19 | + await page.locator(TERMINAL_SELECTOR).waitFor(); |
| 20 | + await page.locator('div.xterm-screen').click(); // sets focus for keyboard input |
| 21 | + await page.waitForTimeout(WAIT_MS); |
| 22 | + }); |
| 23 | + |
| 24 | + test.describe('nano', () => { |
| 25 | + const stdinOptions = ['sab', 'sw']; |
| 26 | + stdinOptions.forEach(stdinOption => { |
| 27 | + test(`should create new file using ${stdinOption} for stdin`, async ({ |
| 28 | + page |
| 29 | + }) => { |
| 30 | + await inputLine(page, `cockle-config -s ${stdinOption}`); |
| 31 | + await page.waitForTimeout(WAIT_MS); |
| 32 | + |
| 33 | + await inputLine(page, 'nano a.txt'); |
| 34 | + await page.waitForTimeout(LONG_WAIT_MS); |
| 35 | + |
| 36 | + // Insert new characters. |
| 37 | + await page.keyboard.type('mnopqrst'); |
| 38 | + |
| 39 | + // Save and quit. |
| 40 | + await page.keyboard.press('Control+x'); |
| 41 | + await page.keyboard.type('y'); |
| 42 | + await page.keyboard.press('Enter'); |
| 43 | + await page.waitForTimeout(LONG_WAIT_MS); |
| 44 | + |
| 45 | + const outputFile = await page.contents.getContentMetadata('a.txt'); |
| 46 | + expect(outputFile?.content).toEqual('mnopqrst\n'); |
| 47 | + }); |
| 48 | + |
| 49 | + test(`should delete data from file using ${stdinOption} for stdin`, async ({ |
| 50 | + page |
| 51 | + }) => { |
| 52 | + await inputLine(page, `cockle-config -s ${stdinOption}`); |
| 53 | + await page.waitForTimeout(WAIT_MS); |
| 54 | + |
| 55 | + // Prepare file to delete from. |
| 56 | + await inputLine(page, 'echo mnopqrst > b.txt'); |
| 57 | + await page.waitForTimeout(WAIT_MS); |
| 58 | + |
| 59 | + await inputLine(page, 'nano b.txt'); |
| 60 | + await page.waitForTimeout(LONG_WAIT_MS); |
| 61 | + |
| 62 | + // Delete first 4 characters. |
| 63 | + for (let i = 0; i < 4; i++) { |
| 64 | + await page.keyboard.press('Delete'); |
| 65 | + } |
| 66 | + |
| 67 | + // Save and quit. |
| 68 | + await page.keyboard.press('Control+x'); |
| 69 | + await page.keyboard.type('y'); |
| 70 | + await page.keyboard.press('Enter'); |
| 71 | + await page.waitForTimeout(LONG_WAIT_MS); |
| 72 | + |
| 73 | + const outputFile = await page.contents.getContentMetadata('b.txt'); |
| 74 | + expect(outputFile?.content).toEqual('qrst\n'); |
| 75 | + }); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + test.describe('vim', () => { |
| 80 | + const stdinOptions = ['sab', 'sw']; |
| 81 | + stdinOptions.forEach(stdinOption => { |
| 82 | + test(`should create new file using ${stdinOption} for stdin`, async ({ |
| 83 | + page |
| 84 | + }) => { |
| 85 | + await inputLine(page, `cockle-config -s ${stdinOption}`); |
| 86 | + await page.waitForTimeout(WAIT_MS); |
| 87 | + |
| 88 | + await inputLine(page, 'vim c.txt'); |
| 89 | + await page.waitForTimeout(LONG_WAIT_MS); |
| 90 | + |
| 91 | + // Insert new characters. |
| 92 | + await page.keyboard.type('iabcdefgh'); |
| 93 | + |
| 94 | + // Save and quit. |
| 95 | + await page.keyboard.press('Escape'); |
| 96 | + await inputLine(page, ':wq'); |
| 97 | + await page.waitForTimeout(LONG_WAIT_MS); |
| 98 | + |
| 99 | + const outputFile = await page.contents.getContentMetadata('c.txt'); |
| 100 | + expect(outputFile?.content).toEqual('abcdefgh\n'); |
| 101 | + }); |
| 102 | + |
| 103 | + test(`should delete data from file using ${stdinOption} for stdin`, async ({ |
| 104 | + page |
| 105 | + }) => { |
| 106 | + await inputLine(page, `cockle-config -s ${stdinOption}`); |
| 107 | + await page.waitForTimeout(WAIT_MS); |
| 108 | + |
| 109 | + // Prepare file to delete from. |
| 110 | + await inputLine(page, 'echo abcdefgh > d.txt'); |
| 111 | + await page.waitForTimeout(WAIT_MS); |
| 112 | + |
| 113 | + await inputLine(page, 'vim d.txt'); |
| 114 | + await page.waitForTimeout(LONG_WAIT_MS); |
| 115 | + |
| 116 | + // Delete first 4 characters. |
| 117 | + await page.keyboard.type('d4l'); |
| 118 | + |
| 119 | + // Save and quit. |
| 120 | + await page.keyboard.press('Escape'); |
| 121 | + await inputLine(page, ':wq'); |
| 122 | + await page.waitForTimeout(LONG_WAIT_MS); |
| 123 | + |
| 124 | + const outputFile = await page.contents.getContentMetadata('d.txt'); |
| 125 | + expect(outputFile?.content).toEqual('efgh\n'); |
| 126 | + }); |
| 127 | + }); |
| 128 | + }); |
| 129 | +}); |
0 commit comments