Skip to content

Commit

Permalink
test(e2e): add initial test for path to rad binary setting
Browse files Browse the repository at this point in the history
- adds test/e2e/helpers/actions.ts and test/e2e/helpers/queries.ts and extracts 2 helper
functions
- adds new test/e2e/specs/settings.spec.ts suite and implements initial test
- sets order of suites to:
  1. onboarding (sequential)
  2. rest of the settings (parallel)

Signed-off-by: Zacharias Fragkiadakis <[email protected]>
  • Loading branch information
QZera committed Dec 1, 2024
1 parent 7c2b5e1 commit 1046eb8
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 23 deletions.
15 changes: 15 additions & 0 deletions test/e2e/helpers/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Workbench } from 'wdio-vscode-service'

/**
* Opens the Radicle view container in the sidebar, by clicking the radicle button in the
* activity bar.
*/
export async function openRadicleViewContainer(workbench: Workbench) {
const activityBar = workbench.getActivityBar()
await activityBar.wait()

const radicleViewControl = await activityBar.getViewControl('Radicle')
await radicleViewControl?.wait()

await radicleViewControl?.openView()
}
19 changes: 19 additions & 0 deletions test/e2e/helpers/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Workbench } from 'wdio-vscode-service'

/**
* Retrieves the welcome text content from the first section in the sidebar view.
*
* @returns The text content found as an array of strings split by newlines. if no content is
* found, an empty array.
*/
export async function getFirstWelcomeViewText(workbench: Workbench) {
const sidebarView = workbench.getSideBar().getContent()
await sidebarView.wait()

const welcomeText =
(await (
await (await sidebarView.getSections())[0]?.findWelcomeContent()
)?.getTextSections()) ?? []

return welcomeText
}
24 changes: 2 additions & 22 deletions test/e2e/specs/onboarding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { e2eTestDirPath } from 'test/e2e/constants/config'
import type { ViewSection, Workbench } from 'wdio-vscode-service'
import { $, cd } from 'zx'
import type * as VsCode from 'vscode'
import { openRadicleViewContainer } from '../helpers/actions'
import { getFirstWelcomeViewText } from '../helpers/queries'

describe('Onboarding Flow', () => {
let workbench: Workbench
Expand Down Expand Up @@ -110,25 +112,3 @@ async function initGitRepo() {
await $`git add README.md`
await $`git commit -m 'adds readme' --no-gpg-sign`
}

async function openRadicleViewContainer(workbench: Workbench) {
const activityBar = workbench.getActivityBar()
await activityBar.wait()

const radicleViewControl = await activityBar.getViewControl('Radicle')
await radicleViewControl?.wait()

await radicleViewControl?.openView()
}

async function getFirstWelcomeViewText(workbench: Workbench) {
const sidebarView = workbench.getSideBar().getContent()
await sidebarView.wait()

const welcomeText =
(await (
await (await sidebarView.getSections())[0]?.findWelcomeContent()
)?.getTextSections()) ?? []

return welcomeText
}
84 changes: 84 additions & 0 deletions test/e2e/specs/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { browser } from '@wdio/globals'
import type { SettingsEditor, Workbench } from 'wdio-vscode-service'
import isEqual from 'lodash/isEqual'
import { Key } from 'webdriverio'
import { getFirstWelcomeViewText } from '../helpers/queries'
import { openRadicleViewContainer } from '../helpers/actions'

describe('Settings', () => {
let workbench: Workbench
let settings: SettingsEditor

before(async () => {
workbench = await browser.getWorkbench()
settings = await workbench.openSettings()
})

after(async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
if (settings && (await settings.elem.isExisting())) {
await browser.keys([Key.Ctrl, 'w'])
}
})

describe('Setting: Path to Rad Binary', () => {
it('warns the user if the rad binary is not found', async () => {
const pathToRadBinary = await settings.findSetting(
'Path To Rad Binary',
'Radicle',
'Advanced',
)
await pathToRadBinary.setValue('/tmp')
await openRadicleViewContainer(workbench)

await expectRadCliBinaryNotFoundToBeVisible(workbench)

/**
* `.setValue('')` updates the value of the input but does not trigger an
* update in the extension. Not sure if this is a bug in the extension, vscode, or
* webdriverio.
*
* The following is a workaround that does trigger an update in the extension.
*/
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
await (await pathToRadBinary.textSetting$).click()
await browser.keys([Key.Ctrl, 'a'])
await browser.keys(Key.Backspace)

await expectCliCommandsAndPatchesToBeVisible(workbench)
})
})

// describe('Setting: Path To Node Home', () => { })
})

async function expectRadCliBinaryNotFoundToBeVisible(workbench: Workbench) {
return await browser.waitUntil(async () => {
const welcomeText = await getFirstWelcomeViewText(workbench)

return isEqual(welcomeText, [
/* eslint-disable max-len */
'Failed resolving the Radicle CLI binary.',
"Please ensure it is installed on your machine and either that it is globally accessible in the shell as `rad` or that its path is correctly defined in the extension's settings.",
"Please expect the extention's capabilities to remain severely limited until this issue is resolved.",
/* eslint-enable max-len */
])
})
}

async function expectCliCommandsAndPatchesToBeVisible(workbench: Workbench) {
const sidebarView = workbench.getSideBar().getContent()
await sidebarView.wait()

return await browser.waitUntil(async () => {
let sectionsFound = false
try {
await sidebarView.getSection('CLI COMMANDS')
await sidebarView.getSection('PATCHES')
sectionsFound = true
// eslint-disable-next-line prettier-vue/prettier
} catch { }

return sectionsFound
})
}
3 changes: 2 additions & 1 deletion test/e2e/wdio.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const vscodeVersion = (packageJson.engines.vscode as string).replace(/^\^/, '')
export const config: WebdriverIO.Config = {
runner: 'local',
tsConfigPath: './tsconfig.wdio.json',
specs: ['./specs/**/*.ts'],
// Order matters, onboarding.spec.ts should run first as it sets up the workspace
specs: ['./specs/onboarding.spec.ts', './specs/**/*.spec.ts'],
maxInstances: 10,
capabilities: [
{
Expand Down

0 comments on commit 1046eb8

Please sign in to comment.