Skip to content

Commit 7f6ffd7

Browse files
committed
setup test -> eula.e2e
1 parent 5390b48 commit 7f6ffd7

File tree

4 files changed

+196
-190
lines changed

4 files changed

+196
-190
lines changed

tests/e2e/src/helpers/navigation.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
ActivityBar,
3+
WebView,
4+
SideBarView,
5+
VSBrowser,
6+
} from 'vscode-extension-tester'
7+
8+
export const openRedisView = async (): Promise<WebView> => {
9+
const browser = VSBrowser.instance
10+
await browser.waitForWorkbench(10000)
11+
12+
const viewControl = await new ActivityBar().getViewControl(
13+
'Redis for VS Code',
14+
)
15+
if (!viewControl) {
16+
throw new Error('Redis for VS Code view not found in the Activity Bar')
17+
}
18+
19+
const sidebarView: SideBarView = await viewControl.openView()
20+
const webview = new WebView(sidebarView)
21+
22+
await new Promise(resolve => setTimeout(resolve, 1000))
23+
24+
return webview
25+
}

tests/e2e/src/tests/eula.e2e.ts

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import { openRedisView } from '../helpers/navigation'
2+
import { expect } from 'chai'
3+
import {
4+
By,
5+
EditorView,
6+
until,
7+
WebDriver,
8+
WebElement,
9+
WebView,
10+
} from 'vscode-extension-tester'
11+
12+
const EULA_TAB_TITLE = 'Redis for VS Code - EULA'
13+
const WELCOME_TAB_TITLE = 'Redis for VS Code - Welcome'
14+
15+
const getWebViewFromTab = async (tabTitle: string): Promise<WebView> => {
16+
const editorView = new EditorView()
17+
18+
const activeEditor = await editorView.openEditor(tabTitle)
19+
20+
if (!(activeEditor instanceof WebView)) {
21+
throw new Error('Expected a WebView, but got a different editor type')
22+
}
23+
24+
return activeEditor
25+
}
26+
27+
export async function getLink(
28+
driver: WebDriver,
29+
title: string,
30+
): Promise<string> {
31+
const anchors = await driver.findElements(By.css('a'))
32+
for (const anchor of anchors) {
33+
const text = (await anchor.getText()).trim()
34+
if (text.includes(title)) {
35+
return await anchor.getAttribute('href')
36+
}
37+
}
38+
throw new Error(`Link with title "${title}" not found`)
39+
}
40+
41+
const getSubmitButton = async (driver: WebDriver): Promise<WebElement> =>
42+
driver.findElement(By.css('[data-testid="btn-submit"]'))
43+
44+
describe('EULA', () => {
45+
before(async () => {
46+
await openRedisView()
47+
await new Promise(r => setTimeout(r, 1000))
48+
})
49+
50+
it('render EULA page elements', async () => {
51+
const eulaWebView = await getWebViewFromTab(EULA_TAB_TITLE)
52+
const driver = eulaWebView.getDriver()
53+
await eulaWebView.switchToFrame()
54+
55+
const bodyElement = await driver.wait(
56+
until.elementLocated(By.css('body')),
57+
10000,
58+
'Timeout: body not found in EULA WebView',
59+
)
60+
61+
const rawText = await bodyElement.getText()
62+
63+
// Page title
64+
expect(rawText).to.include('EULA and Privacy settings')
65+
66+
// Checkboxes
67+
expect(rawText).to.include('Use recommended settings')
68+
expect(rawText).to.include('Usage Data')
69+
expect(rawText).to.include('Encrypt sensitive information')
70+
expect(rawText).to.include('I have read and understood the Terms')
71+
72+
// Sections
73+
expect(rawText).to.include('Privacy Settings')
74+
75+
// Buttons
76+
expect(rawText).to.include('Submit')
77+
78+
// Links
79+
const serverSidePublicLicense = await getLink(
80+
driver,
81+
'Server Side Public License',
82+
)
83+
expect(serverSidePublicLicense).to.equal(
84+
'https://github.com/RedisInsight/Redis-for-VS-Code/blob/main/LICENSE',
85+
)
86+
87+
eulaWebView.switchBack()
88+
})
89+
90+
it('should enable Submit button when terms are accepted', async () => {
91+
const eulaWebView = await getWebViewFromTab(EULA_TAB_TITLE)
92+
await eulaWebView.switchToFrame()
93+
94+
const driver = eulaWebView.getDriver()
95+
96+
// Disabled by default
97+
expect(
98+
await (await getSubmitButton(driver)).getAttribute('disabled'),
99+
).to.eq('true')
100+
101+
// Recommended settings
102+
const useRecommendedSettings = await driver.findElement(
103+
By.xpath("//label[contains(., 'Use recommended settings')]"),
104+
)
105+
await useRecommendedSettings.click()
106+
expect(
107+
await (await getSubmitButton(driver)).getAttribute('disabled'),
108+
).to.eq('true')
109+
110+
// Terms and conditions
111+
const acceptTermsCheckbox = await driver.findElement(
112+
By.xpath("//label[contains(., 'I have read and understood the Terms')]"),
113+
)
114+
await acceptTermsCheckbox.click()
115+
expect(await (await getSubmitButton(driver)).getAttribute('disabled')).to.be
116+
.null
117+
118+
eulaWebView.switchBack()
119+
})
120+
121+
it('should hide EULA and display other extension controls', async () => {
122+
const eulaWebView = await getWebViewFromTab(EULA_TAB_TITLE)
123+
await eulaWebView.switchToFrame()
124+
125+
const driver = eulaWebView.getDriver()
126+
127+
const acceptTermsCheckbox = await driver.findElement(
128+
By.xpath("//label[contains(., 'I have read and understood the Terms')]"),
129+
)
130+
await acceptTermsCheckbox.click()
131+
const submitButton = await getSubmitButton(driver)
132+
await submitButton.click()
133+
134+
await eulaWebView.switchBack()
135+
136+
await new Promise(r => setTimeout(r, 5000)) // wait for the EULA to close
137+
138+
const welcomeView = await getWebViewFromTab(WELCOME_TAB_TITLE)
139+
await welcomeView.switchToFrame()
140+
const rawText = await (
141+
await eulaWebView.findWebElement(By.css('body'))
142+
).getText()
143+
144+
expect(rawText).to.include('Start')
145+
expect(rawText).to.include('Create new database')
146+
147+
// TODO: add asserts for the side bar items
148+
149+
await welcomeView.switchBack()
150+
})
151+
})

tests/e2e/src/tests/setup.ts

Lines changed: 0 additions & 173 deletions
This file was deleted.

0 commit comments

Comments
 (0)