|
| 1 | +import { getBaseURL, startGitButler, type GitButler } from '../src/setup.ts'; |
| 2 | +import { clickByTestId, waitForTestId } from '../src/util.ts'; |
| 3 | +import { expect, test } from '@playwright/test'; |
| 4 | +import { readFileSync, writeFileSync } from 'fs'; |
| 5 | + |
| 6 | +let gitbutler: GitButler; |
| 7 | + |
| 8 | +test.use({ |
| 9 | + baseURL: getBaseURL() |
| 10 | +}); |
| 11 | + |
| 12 | +test.afterEach(async () => { |
| 13 | + gitbutler?.destroy(); |
| 14 | +}); |
| 15 | + |
| 16 | +test('should be able to edit a commit through the edit mode', async ({ |
| 17 | + page, |
| 18 | + context |
| 19 | +}, testInfo) => { |
| 20 | + const workdir = testInfo.outputPath('workdir'); |
| 21 | + const configdir = testInfo.outputPath('config'); |
| 22 | + gitbutler = await startGitButler(workdir, configdir, context); |
| 23 | + |
| 24 | + const fileBPath = gitbutler.pathInWorkdir('file-b.txt'); |
| 25 | + |
| 26 | + await gitbutler.runScript('project-with-remote-branches.sh'); |
| 27 | + await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']); |
| 28 | + |
| 29 | + await page.goto('/'); |
| 30 | + |
| 31 | + // Should load the workspace |
| 32 | + await waitForTestId(page, 'workspace-view'); |
| 33 | + |
| 34 | + const commitRows = page.getByTestId('commit-row'); |
| 35 | + await expect(commitRows).toHaveCount(2); |
| 36 | + const bottomCommit = commitRows.filter({ hasText: 'branch1: first commit' }); |
| 37 | + |
| 38 | + bottomCommit.click({ button: 'right' }); |
| 39 | + await clickByTestId(page, 'commit-row-context-menu-edit-commit'); |
| 40 | + // Should open the edit mode |
| 41 | + await waitForTestId(page, 'edit-mode'); |
| 42 | + |
| 43 | + // Create another file to commit |
| 44 | + writeFileSync(fileBPath, 'This is file B\n', { encoding: 'utf-8' }); |
| 45 | + |
| 46 | + // Click the save and exit button |
| 47 | + await clickByTestId(page, 'edit-mode-save-and-exit-button'); |
| 48 | + |
| 49 | + // Should be back in the workspace |
| 50 | + await waitForTestId(page, 'workspace-view'); |
| 51 | + |
| 52 | + const fileBContent = readFileSync(fileBPath, { encoding: 'utf-8' }); |
| 53 | + |
| 54 | + expect(fileBContent).toEqual('This is file B\n'); |
| 55 | +}); |
0 commit comments