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