Skip to content

Commit b08584e

Browse files
committed
Improve and extend browser tests
1 parent e7406b7 commit b08584e

1 file changed

Lines changed: 43 additions & 8 deletions

File tree

tests/browser/browser.js

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,35 @@ describe('platform specific content', () => {
180180
{ name: 'Windows', id: 'windows', ua: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36' },
181181
{ name: 'Linux', id: 'linux', ua: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1' }
182182
]
183-
const userAgentLinux = userAgents[2]
183+
const linuxUserAgent = userAgents[2]
184+
const pageWithSwitcher = 'http://localhost:4001/en/actions/hosting-your-own-runners/monitoring-and-troubleshooting-self-hosted-runners'
185+
const pageWithoutSwitcher = 'http://localhost:4001/en/github/using-git'
186+
const pageWithDefaultPlatform = 'http://localhost:4001/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service'
184187

185188
it('should have a platform switcher', async () => {
186-
await page.goto('http://localhost:4001/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service')
189+
await page.goto(pageWithSwitcher)
187190
const nav = await page.$$('nav.UnderlineNav')
188191
const switches = await page.$$('a.platform-switcher')
189192
const selectedSwitch = await page.$$('a.platform-switcher.selected')
190-
expect(nav.length).toEqual(1)
193+
expect(nav).toHaveLength(1)
191194
expect(switches.length).toBeGreaterThan(1)
192-
expect(selectedSwitch.length).toEqual(1)
195+
expect(selectedSwitch).toHaveLength(1)
196+
})
197+
198+
it('should NOT have a platform switcher', async () => {
199+
await page.goto(pageWithoutSwitcher)
200+
const nav = await page.$$('nav.UnderlineNav')
201+
const switches = await page.$$('a.platform-switcher')
202+
const selectedSwitch = await page.$$('a.platform-switcher.selected')
203+
expect(nav).toHaveLength(0)
204+
expect(switches).toHaveLength(0)
205+
expect(selectedSwitch).toHaveLength(0)
193206
})
194207

195208
it('should detect platform from user agent', async () => {
196209
for (const agent of userAgents) {
197210
await page.setUserAgent(agent.ua)
198-
await page.goto('http://localhost:4001/en/actions/hosting-your-own-runners/monitoring-and-troubleshooting-self-hosted-runners')
211+
await page.goto(pageWithSwitcher)
199212
const selectedPlatformElement = await page.waitForSelector('a.platform-switcher.selected')
200213
const selectedPlatform = await page.evaluate(el => el.textContent, selectedPlatformElement)
201214
expect(selectedPlatform).toBe(agent.name)
@@ -205,12 +218,34 @@ describe('platform specific content', () => {
205218
it('should prefer defaultPlatform from frontmatter', async () => {
206219
for (const agent of userAgents) {
207220
await page.setUserAgent(agent.ua)
208-
await page.goto('http://localhost:4001/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service')
221+
await page.goto(pageWithDefaultPlatform)
209222
const defaultPlatform = await page.$eval('[data-default-platform]', el => el.dataset.defaultPlatform)
210223
const selectedPlatformElement = await page.waitForSelector('a.platform-switcher.selected')
211224
const selectedPlatform = await page.evaluate(el => el.textContent, selectedPlatformElement)
212-
expect(defaultPlatform).toBe(userAgentLinux.id)
213-
expect(selectedPlatform).toBe(userAgentLinux.name)
225+
expect(defaultPlatform).toBe(linuxUserAgent.id)
226+
expect(selectedPlatform).toBe(linuxUserAgent.name)
227+
}
228+
})
229+
230+
it('should show the content for the selected platform only', async () => {
231+
await page.goto(pageWithSwitcher)
232+
233+
const platforms = ['mac', 'windows', 'linux']
234+
for (const platform of platforms) {
235+
await page.click(`.platform-switcher[data-platform="${platform}"]`)
236+
237+
// content for selected platform is expected to become visible
238+
await page.waitForSelector(`.extended-markdown.${platform}`, { visible: true, timeout: 3000 })
239+
240+
// only a single tab should be selected
241+
const selectedSwitch = await page.$$('a.platform-switcher.selected')
242+
expect(selectedSwitch).toHaveLength(1)
243+
244+
// content for NOT selected platforms is expected to become hidden
245+
const otherPlatforms = platforms.filter(e => e !== platform)
246+
for (const other of otherPlatforms) {
247+
await page.waitForSelector(`.extended-markdown.${other}`, { hidden: true, timeout: 3000 })
248+
}
214249
}
215250
})
216251
})

0 commit comments

Comments
 (0)