Skip to content

Commit

Permalink
test(e2e): write test for setting an invalid node home path
Browse files Browse the repository at this point in the history
Signed-off-by: Zacharias Fragkiadakis <[email protected]>
  • Loading branch information
QZera committed Jan 4, 2025
1 parent cf661db commit 110b791
Showing 1 changed file with 76 additions and 6 deletions.
82 changes: 76 additions & 6 deletions test/e2e/specs/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { browser } from '@wdio/globals'
import type { Setting, SettingsEditor, Workbench } from 'wdio-vscode-service'
import type { OutputView, Setting, SettingsEditor, Workbench } from 'wdio-vscode-service'
import isEqual from 'lodash/isEqual'
import { Key } from 'webdriverio'
import { $ } from 'zx'
import { getFirstWelcomeViewText } from '../helpers/queries'
import { expectCliCommandsAndPatchesToBeVisible } from '../helpers/assertions'
import { expectStandardSidebarViewsToBeVisible } from '../helpers/assertions'
import { closeRadicleViewContainer, openRadicleViewContainer } from '../helpers/actions'
import { nodeHomePath } from '../constants/config'

Expand All @@ -16,7 +16,7 @@ describe('Settings', () => {
workbench = await browser.getWorkbench()
settings = await workbench.openSettings()
await openRadicleViewContainer(workbench)
await expectCliCommandsAndPatchesToBeVisible(workbench)
await expectStandardSidebarViewsToBeVisible(workbench)
})

after(async () => {
Expand All @@ -34,10 +34,15 @@ describe('Settings', () => {
)
})

after(async () => {
const searchBox = await getSettingsSearchBox(settings)
await clearInput(searchBox)
})

afterEach(async () => {
await clearTextSetting(pathToRadBinarySetting)

await expectCliCommandsAndPatchesToBeVisible(workbench)
await expectStandardSidebarViewsToBeVisible(workbench)
})

it('warns the user if the rad binary is not found', async () => {
Expand All @@ -57,7 +62,7 @@ describe('Settings', () => {

await setTextSettingValue(pathToRadBinarySetting, `${tempNodeHomePath}/bin/rad`)

await expectCliCommandsAndPatchesToBeVisible(workbench)
await expectStandardSidebarViewsToBeVisible(workbench)

await $`rm -rf ${tempNodeHomePath}`
})
Expand All @@ -73,13 +78,51 @@ describe('Settings', () => {

await $`cp -r ${nodeHomePath} ${tempNodeHomePath}`

await expectCliCommandsAndPatchesToBeVisible(workbench)
await expectStandardSidebarViewsToBeVisible(workbench)

await clearTextSetting(pathToRadBinarySetting)

await $`rm -rf ${tempNodeHomePath}`
})
})

describe('VS Code, when updating the "Path to Radicle to Node Home" setting,', () => {
let pathToNodeHomeSetting: Setting

before(async () => {
pathToNodeHomeSetting = await settings.findSetting(
'Path To Node Home',
'Radicle',
'Advanced',
)
})

after(async () => {
const searchBox = await getSettingsSearchBox(settings)
await clearInput(searchBox)
})

/**
* In Linux CI:
* - The extension is having issues resolving the correct node home directory (RAD_HOME).
* - Even when set explicitly in the settings, the extension incorrectly reports it as
* non-authenticated.
*/
it('logs an error in the output console if the path is invalid @skipLinuxCI', async () => {
await workbench.executeCommand('Show Everything Logged in the Output Panel')
const outputView = await workbench.getBottomBar().openOutputView()
await outputView.clearText()

await setTextSettingValue(pathToNodeHomeSetting, '/tmp')

await expectOutputToContain(outputView, '✗ Error: Radicle profile not found in')

await outputView.clearText()
await clearTextSetting(pathToNodeHomeSetting)

await expectOutputToContain(outputView, 'Using already unsealed Radicle identity')
})
})
})

async function expectRadBinaryNotFoundToBeVisible(workbench: Workbench) {
Expand Down Expand Up @@ -135,3 +178,30 @@ async function clearTextSetting(setting: Setting) {
await browser.keys([Key.Ctrl, 'a'])
await browser.keys(Key.Backspace)
}

async function getSettingsSearchBox(settings: SettingsEditor) {
return await settings.elem.$(settings.locatorMap.Editor['inputArea'] as string)
}

async function clearInput(input: WebdriverIO.Element) {
await input.setValue('')
await browser.keys([Key.Ctrl, 'a'])
await browser.keys(Key.Backspace)
}

async function expectOutputToContain(outputView: OutputView, expected: string) {
await browser.waitUntil(
async () => {
/**
* The text in the output console is split by newlines, which can be affected by the size
* of the window. To avoid this, we join the text into a single string.
*/
const joinedText = (await outputView.getText()).join('')

return joinedText.includes(expected)
},
{
timeoutMsg: `expected the output text to contain "${expected}"`,
},
)
}

0 comments on commit 110b791

Please sign in to comment.