Skip to content

Commit

Permalink
refactor(e2e): extract expectOutputToContain into assertions helpers
Browse files Browse the repository at this point in the history
Signed-off-by: Zacharias Fragkiadakis <zacfragkiadakis@gmail.com>
  • Loading branch information
QZera committed Jan 6, 2025
1 parent e71e6cd commit 98822c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
22 changes: 21 additions & 1 deletion test/e2e/helpers/assertions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import { browser } from '@wdio/globals'
import type { Workbench } from 'wdio-vscode-service'
import type { OutputView, Workbench } from 'wdio-vscode-service'

/**
* Asserts the output view contains the expected text.
*/
export 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}"`,
},
)
}

/**
* Asserts that the CLI Commands and Patches sections are visible in the sidebar. This is
Expand Down
40 changes: 17 additions & 23 deletions test/e2e/specs/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import isEqual from 'lodash/isEqual'
import { Key } from 'webdriverio'
import { $ } from 'zx'
import { getFirstWelcomeViewText } from '../helpers/queries'
import { expectStandardSidebarViewsToBeVisible } from '../helpers/assertions'
import {
expectOutputToContain,
expectStandardSidebarViewsToBeVisible,
} from '../helpers/assertions'
import {
clearInput,
closeRadicleViewContainer,
Expand Down Expand Up @@ -107,7 +110,7 @@ describe('Settings', () => {
await outputView.clearText()
await clearTextSetting(pathToNodeHomeSetting)

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

/**
Expand All @@ -121,7 +124,7 @@ describe('Settings', () => {

await setTextSettingValue(pathToNodeHomeSetting, '/tmp')

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

it('recognizes when a valid path is specified @skipLinuxCI', async () => {
Expand All @@ -130,7 +133,7 @@ describe('Settings', () => {

await setTextSettingValue(pathToNodeHomeSetting, tempNodeHomePath)

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

await $`rm -rf ${tempNodeHomePath}`
})
Expand All @@ -142,11 +145,11 @@ describe('Settings', () => {

await setTextSettingValue(pathToNodeHomeSetting, tempNodeHomePath)

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

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

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

await $`rm -rf ${tempNodeHomePath}`
})
Expand All @@ -170,6 +173,14 @@ async function expectRadBinaryNotFoundToBeVisible(workbench: Workbench) {
)
}

async function expectRadicleIdentityToBeFound(outputView: OutputView) {
await expectOutputToContain(outputView, 'Using already unsealed Radicle identity')
}

async function expectRadicleProfileNotToBeFound(outputView: OutputView) {
await expectOutputToContain(outputView, '✗ Error: Radicle profile not found in')
}

/**
* Workaround to get the value of a `TextSetting`.
* The `getValue` method of a `TextSetting` seems to be wrongly implemented and returns null.
Expand Down Expand Up @@ -203,20 +214,3 @@ async function clearTextSetting(setting: Setting) {
async function getSettingsSearchBox(settings: SettingsEditor) {
return await settings.elem.$(settings.locatorMap.Editor['inputArea'] as string)
}

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 98822c8

Please sign in to comment.