From 110b7918bb0068a2e931f2510868183912909feb Mon Sep 17 00:00:00 2001 From: Zacharias Fragkiadakis Date: Tue, 31 Dec 2024 11:07:52 +0200 Subject: [PATCH] test(e2e): write test for setting an invalid node home path Signed-off-by: Zacharias Fragkiadakis --- test/e2e/specs/settings.spec.ts | 82 ++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/test/e2e/specs/settings.spec.ts b/test/e2e/specs/settings.spec.ts index 3cecb5a1..68286f3a 100644 --- a/test/e2e/specs/settings.spec.ts +++ b/test/e2e/specs/settings.spec.ts @@ -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' @@ -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 () => { @@ -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 () => { @@ -57,7 +62,7 @@ describe('Settings', () => { await setTextSettingValue(pathToRadBinarySetting, `${tempNodeHomePath}/bin/rad`) - await expectCliCommandsAndPatchesToBeVisible(workbench) + await expectStandardSidebarViewsToBeVisible(workbench) await $`rm -rf ${tempNodeHomePath}` }) @@ -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) { @@ -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}"`, + }, + ) +}