Skip to content

Commit de490f6

Browse files
committed
Add browser tests
1 parent 10819ab commit de490f6

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/browser/browser.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,45 @@ async function getLocationObject (page) {
168168
})
169169
return JSON.parse(location)
170170
}
171+
172+
describe('platform specific content', () => {
173+
// from tests/javascripts/user-agent.js
174+
const userAgents = [
175+
{ name: 'Mac', id: 'mac', ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9' },
176+
{ 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' },
177+
{ name: 'Linux', id: 'linux', ua: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1' },
178+
]
179+
const userAgentLinux = userAgents[2]
180+
181+
it('should have a platform switcher', async () => {
182+
await page.goto('http://localhost:4001/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service')
183+
const nav = await page.$$('nav.UnderlineNav')
184+
const switches = await page.$$('a.platform-switcher')
185+
const selectedSwitch = await page.$$('a.platform-switcher.selected')
186+
expect(nav.length).toEqual(1)
187+
expect(switches.length).toBeGreaterThan(1)
188+
expect(selectedSwitch.length).toEqual(1)
189+
})
190+
191+
it('should detect platform from user agent', async () => {
192+
for (const agent of userAgents) {
193+
await page.setUserAgent(agent.ua)
194+
await page.goto('http://localhost:4001/en/actions/hosting-your-own-runners/monitoring-and-troubleshooting-self-hosted-runners')
195+
const selectedPlatformElement = await page.waitForSelector('a.platform-switcher.selected')
196+
const selectedPlatform = await page.evaluate( el => el.textContent, selectedPlatformElement)
197+
expect(selectedPlatform).toBe(agent.name)
198+
}
199+
})
200+
201+
it('should prefer defaultPlatform from frontmatter', async () => {
202+
for (const agent of userAgents) {
203+
await page.setUserAgent(agent.ua)
204+
await page.goto('http://localhost:4001/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service')
205+
const defaultPlatform = await page.$eval('[data-default-platform]', el => el.dataset.defaultPlatform)
206+
const selectedPlatformElement = await page.waitForSelector('a.platform-switcher.selected')
207+
const selectedPlatform = await page.evaluate( el => el.textContent, selectedPlatformElement)
208+
expect(defaultPlatform).toBe(userAgentLinux.id)
209+
expect(selectedPlatform).toBe(userAgentLinux.name)
210+
}
211+
})
212+
})

0 commit comments

Comments
 (0)