Skip to content

Commit 854e744

Browse files
authored
Add browser tests for discovery page (#825)
1 parent 6169110 commit 854e744

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
class Discovery {
2+
get pagination () { return $('.pagination') }
3+
get sortDropdown () { return $('.options .v-select') }
4+
get sortValue () { return $('.options .v-select__selection') }
5+
get excludeEmptyCheckbox () { return $('.options .v-input--checkbox input') }
6+
get cards () { return $('.grid.cards') }
7+
get firstCard () { return $('.card:first-child') }
8+
get lastCard () { return $('.card:last-child') }
9+
get footer () { return $('.footer') }
10+
get header () { return $('.intro .text-h4.title') }
11+
12+
async getCardDetails (card) {
13+
await card.waitForDisplayed({ timeout: 5000 })
14+
return {
15+
name: await (await card.$('.text-h5')).getText(),
16+
pages: await (await card.$('.pages')).getText()
17+
}
18+
}
19+
20+
async getFirstCard () {
21+
return await this.getCardDetails(await this.firstCard)
22+
}
23+
24+
async getLastCard () {
25+
return await this.getCardDetails(await this.lastCard)
26+
}
27+
28+
getCardByWikiName (name) {
29+
return $('//div[contains(text(), "' + name + '")]')
30+
}
31+
32+
getCardByPageCount (count) {
33+
return $('//div[contains(text(), "No. of pages: ' + count + '")]')
34+
}
35+
36+
async setSortValue (value) {
37+
const sortDropdown = await this.sortDropdown
38+
await sortDropdown.waitForClickable({ timeout: 5000 })
39+
await sortDropdown.click()
40+
41+
const dropdownOption = await $(
42+
'//div[contains(@class, "v-list-item__title") and contains(text(), "' + value + '")]'
43+
)
44+
await dropdownOption.waitForDisplayed({ timeout: 5000 })
45+
await dropdownOption.click()
46+
}
47+
48+
async open (path = '/discovery') {
49+
await browser.url(path)
50+
}
51+
}
52+
53+
module.exports = new Discovery()

tests/e2e/specs/discovery.spec.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
const Discovery = require('../pageobjects/discovery.page')
2+
3+
describe('Discovery page', () => {
4+
beforeEach(async () => {
5+
await Discovery.open()
6+
await browser.setWindowSize(1360, 973)
7+
})
8+
9+
it('should render header and footer', async () => {
10+
const header = await Discovery.header
11+
const footer = await Discovery.footer
12+
13+
expect(await header.isDisplayed()).toBe(true)
14+
expect(await header.getText()).toStrictEqual('A tour of Wikibases in the cloud')
15+
expect(await footer.isDisplayed()).toBe(true)
16+
})
17+
18+
it('should paginate results', async () => {
19+
const page = await Discovery.pagination
20+
expect(await page.isDisplayed()).toBe(true)
21+
})
22+
23+
it('should filter by descending page count by default', async () => {
24+
const sortValue = await Discovery.sortValue
25+
const cardWithMostPages = await Discovery.getCardByPageCount(49)
26+
const cardWithLeastPages = await Discovery.getCardByPageCount(0)
27+
28+
expect(await sortValue.getText()).toStrictEqual('No. of pages ↓')
29+
expect(await cardWithMostPages.isDisplayed()).toBe(true)
30+
expect(await cardWithLeastPages.isDisplayed()).toBe(false)
31+
})
32+
33+
describe('should support filtering', () => {
34+
const cases = [
35+
{
36+
description: 'in descending alphabetical order',
37+
order: 'Alphabetically ↓',
38+
cards: {
39+
first: 'seededsite-9',
40+
last: 'seededsite-32'
41+
}
42+
},
43+
{
44+
description: 'in ascending alphabetical order',
45+
order: 'Alphabetically ↑',
46+
cards: {
47+
first: 'seededsite-10',
48+
last: 'seededsite-31'
49+
}
50+
},
51+
{
52+
description: 'by descending page count',
53+
order: 'No. of pages ↓',
54+
cards: {
55+
first: 'seededsite-49',
56+
last: 'seededsite-26'
57+
}
58+
}
59+
]
60+
61+
cases.forEach(async ({ description, order, cards }) => {
62+
await it(description, async () => {
63+
await Discovery.setSortValue(order)
64+
65+
const firstCard = await Discovery.getFirstCard()
66+
const lastCard = await Discovery.getLastCard()
67+
68+
expect(await firstCard.name).toStrictEqual(cards.first)
69+
expect(await lastCard.name).toStrictEqual(cards.last)
70+
})
71+
})
72+
})
73+
74+
it('should filter out empty instances by default', async () => {
75+
await Discovery.setSortValue('Alphabetically ↑')
76+
77+
const excludeEmptyCheckbox = await Discovery.excludeEmptyCheckbox
78+
const cards = await Discovery.cards
79+
await cards.waitForDisplayed({ timeout: 5000 })
80+
const cardWithLeastPages = await Discovery.getCardByPageCount(0)
81+
82+
expect(await excludeEmptyCheckbox.isSelected()).toBe(true)
83+
expect(await cardWithLeastPages.isDisplayed()).toBe(false)
84+
})
85+
86+
it('should support including empty instances', async () => {
87+
await Discovery.setSortValue('Alphabetically ↑')
88+
89+
const excludeEmptyCheckbox = await Discovery.excludeEmptyCheckbox
90+
await excludeEmptyCheckbox.waitForExist({ timeout: 5000 })
91+
const excludeEmptyCheckboxWrapper = await excludeEmptyCheckbox.parentElement()
92+
await excludeEmptyCheckboxWrapper.click()
93+
94+
const cards = await Discovery.cards
95+
await cards.waitForDisplayed({ timeout: 5000 })
96+
const cardWithLeastPages = await Discovery.getCardByPageCount(0)
97+
98+
expect(await excludeEmptyCheckbox.isSelected()).toBe(false)
99+
expect(await cardWithLeastPages.isDisplayed()).toBe(true)
100+
})
101+
102+
it('should render card details', async () => {
103+
const { name, pages } = await Discovery.getFirstCard()
104+
105+
expect(name).toStrictEqual('seededsite-49')
106+
expect(pages).toStrictEqual('No. of pages: 49')
107+
})
108+
109+
it('should open new tab when card is clicked', async () => {
110+
const firstCard = await Discovery.firstCard
111+
await firstCard.click()
112+
113+
const url = 'https://seededsite-49.nodomain.example/'
114+
await browser.switchWindow(url)
115+
await expect(browser).toHaveUrlContaining(url, { wait: 5000 })
116+
})
117+
})

0 commit comments

Comments
 (0)