|
| 1 | +import type { WebView, Workbench } from 'wdio-vscode-service' |
| 2 | +import { $, browser } from '@wdio/globals' |
| 3 | +import { $ as zx } from 'zx' |
| 4 | +import { Key } from 'webdriverio' |
| 5 | +import { openRadicleViewContainer } from '../helpers/actions' |
| 6 | + |
| 7 | +const selectors = { |
| 8 | + openPatchDetailsButton: 'aria/Open Patch Details', |
| 9 | + changePathStatusButton: '[title="Change Patch Status"]', |
| 10 | + draftRadioButton: 'aria/Draft', |
| 11 | + stopEditingPatchStatusButton: '[title="Stop Editing Patch Status"]', |
| 12 | + refreshPatchDataButton: '[title="Refresh Patch Data"]', |
| 13 | + editPatchTitleButton: '[title="Edit Patch Title and Description"]', |
| 14 | + patchTitleInput: 'aria/Patch Title:', |
| 15 | + patchDescriptionInput: 'aria/Patch Description:', |
| 16 | + savePatchTitleButton: '[title="Save Changes to Radicle (Ctrl + Enter)"]', |
| 17 | + openPatchIcon: '.codicon-git-pull-request', |
| 18 | + draftPatchIcon: '.codicon-git-pull-request-draft', |
| 19 | + closedPatchIcon: '.codicon-git-pull-request-closed', |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * These tests are failing because the extension is not picking up httpd. |
| 24 | + * An iteration of this suite with adjustments to run locally (with a pre-existing patch) has been |
| 25 | + * tested (on macOS) and works as expected. |
| 26 | + * Barring any unexpected behavior due to the CI environment, these tests *should* pass once the |
| 27 | + * httpd issue is resolved. |
| 28 | + * |
| 29 | + * TODO: Figure out why the extension is not picking up httpd |
| 30 | + */ |
| 31 | +describe('Patch Details', () => { |
| 32 | + const patchTitle = 'feat: foo bar' |
| 33 | + let workbench: Workbench |
| 34 | + |
| 35 | + before(async () => { |
| 36 | + workbench = await browser.getWorkbench() |
| 37 | + await zx`git checkout -b branch-1` |
| 38 | + await zx`echo "Hello, World!" > hello.txt` |
| 39 | + await zx`git add .` |
| 40 | + await zx`git commit -m "${patchTitle}"` |
| 41 | + await zx`git push rad HEAD:refs/patches` |
| 42 | + await openRadicleViewContainer(workbench) |
| 43 | + await openPatchDetails(workbench, patchTitle) |
| 44 | + }) |
| 45 | + |
| 46 | + describe("VS Code, when viewing a patch's details,", () => { |
| 47 | + it('allows the user to edit the patch status', async () => { |
| 48 | + const patchDetails = await switchToFirstWebView(workbench) |
| 49 | + |
| 50 | + await $(selectors.changePathStatusButton).click() |
| 51 | + await $(selectors.draftRadioButton).click() |
| 52 | + await $(selectors.stopEditingPatchStatusButton).click() |
| 53 | + await $(selectors.refreshPatchDataButton).moveTo() |
| 54 | + |
| 55 | + await expect($(`header ${selectors.draftPatchIcon}`)).toBeDisplayed() |
| 56 | + |
| 57 | + await patchDetails?.close() |
| 58 | + |
| 59 | + await expect( |
| 60 | + await (await findPatch(workbench, patchTitle))?.elem.$(selectors.draftPatchIcon), |
| 61 | + ).toBeDisplayed() |
| 62 | + }) |
| 63 | + |
| 64 | + it('allows the user to edit that patch title and description', async () => { |
| 65 | + const patchDetails = await switchToFirstWebView(workbench) |
| 66 | + await $(selectors.editPatchTitleButton).click() |
| 67 | + |
| 68 | + const newTitle = 'feat: new foo bar' |
| 69 | + const newDescription = 'foo bar baz' |
| 70 | + await findAndFillInput(selectors.patchTitleInput, newTitle) |
| 71 | + await findAndFillInput(selectors.patchDescriptionInput, newDescription) |
| 72 | + await $(selectors.savePatchTitleButton).click() |
| 73 | + |
| 74 | + await expect($(`p=${newTitle}`)).toBeDisplayed() |
| 75 | + |
| 76 | + await expect($(`p=${newDescription}`)).toBeDisplayed() |
| 77 | + |
| 78 | + await patchDetails?.close() |
| 79 | + |
| 80 | + await expect(await findPatch(workbench, newTitle)).toBeDisplayed() |
| 81 | + }) |
| 82 | + }) |
| 83 | +}) |
| 84 | + |
| 85 | +async function findAndFillInput(selector: string, value: string) { |
| 86 | + await $(selector).click() |
| 87 | + await browser.keys([Key.Ctrl, 'a']) |
| 88 | + await browser.keys(value.split('')) |
| 89 | +} |
| 90 | + |
| 91 | +async function findPatch(workbench: Workbench, label: string) { |
| 92 | + const sidebarView = workbench.getSideBar().getContent() |
| 93 | + const patchesSection = await sidebarView.getSection('PATCHES') |
| 94 | + const patch = await patchesSection.findItem(label) |
| 95 | + |
| 96 | + return patch |
| 97 | +} |
| 98 | + |
| 99 | +async function openPatchDetails(workbench: Workbench, label: string) { |
| 100 | + const patch = await findPatch(workbench, label) |
| 101 | + if (!patch) { |
| 102 | + return undefined |
| 103 | + } |
| 104 | + |
| 105 | + await patch.elem.moveTo() |
| 106 | + await patch.elem.$(selectors.openPatchDetailsButton)?.click() |
| 107 | + |
| 108 | + return patch |
| 109 | +} |
| 110 | + |
| 111 | +async function switchToFirstWebView(workbench: Workbench) { |
| 112 | + let webviews: WebView[] = [] |
| 113 | + await browser.waitUntil( |
| 114 | + async () => { |
| 115 | + webviews = await workbench.getAllWebviews() |
| 116 | + |
| 117 | + return webviews.length > 0 |
| 118 | + }, |
| 119 | + { timeoutMsg: 'no webviews found' }, |
| 120 | + ) |
| 121 | + await webviews[0]?.open() |
| 122 | + |
| 123 | + return webviews[0] |
| 124 | +} |
0 commit comments