|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +test.describe('Options 36 - Infinite Scroll', () => { |
| 4 | + test('select should use infinite scroll', async ({ page }) => { |
| 5 | + await page.goto('#/options36'); |
| 6 | + |
| 7 | + // -- 1st Select |
| 8 | + await page.locator('[data-test="select1"].ms-parent').click(); |
| 9 | + |
| 10 | + const ulElm1 = await page.locator('[data-test="select1"] .ms-drop ul'); |
| 11 | + const liElms1 = await page.locator('[data-test="select1"] .ms-drop ul li'); |
| 12 | + await expect(liElms1.nth(0)).toContainText('Title 0'); |
| 13 | + await liElms1.nth(0).click(); |
| 14 | + await expect(page.locator('[data-test=select1].ms-parent .ms-choice span')).toHaveText('Title 0'); |
| 15 | + |
| 16 | + // scroll near the end of the list |
| 17 | + await page.locator('[data-test="select1"].ms-parent').click(); |
| 18 | + await ulElm1.evaluate(e => (e.scrollTop = e.scrollHeight - 10)); |
| 19 | + await page.locator('[data-test="select1"] .ms-drop label').filter({ hasText: 'Title 24' }).click(); |
| 20 | + |
| 21 | + // scroll completely to the end of the list & expect scrolling back to top |
| 22 | + await page.locator('[data-test="select1"].ms-parent').click(); |
| 23 | + await ulElm1.evaluate(e => (e.scrollTop = e.scrollHeight)); |
| 24 | + const firstTitleLoc = await page.locator('div[data-test=select1] .ms-drop li:nth-of-type(1)'); |
| 25 | + await expect(firstTitleLoc).toContainText('Title 0'); |
| 26 | + await expect(firstTitleLoc).toHaveClass('hide-radio highlighted'); |
| 27 | + await page.keyboard.press('Enter'); |
| 28 | + |
| 29 | + // -- 2nd Select |
| 30 | + await page.locator('[data-test=select2].ms-parent').click(); |
| 31 | + const ulElm2 = await page.locator('[data-test="select2"] .ms-drop ul'); |
| 32 | + const liElms2 = await page.locator('[data-test="select2"] .ms-drop ul li'); |
| 33 | + await expect(await liElms2.nth(4).locator('span').innerHTML()).toBe('<i class="fa fa-star"></i> Task 4'); |
| 34 | + await liElms2.nth(4).click(); |
| 35 | + await expect(await liElms2.nth(5).locator('span').innerHTML()).toBe('<i class="fa fa-star"></i> Task 5'); |
| 36 | + await liElms2.nth(5).click(); |
| 37 | + await page.getByRole('button', { name: '4, 5' }).click(); |
| 38 | + |
| 39 | + // scroll to the middle and click 1003 |
| 40 | + await page.locator('[data-test="select2"].ms-parent').click(); |
| 41 | + await ulElm2.evaluate(e => (e.scrollTop = e.scrollHeight / 2)); |
| 42 | + await page.locator('[data-test="select2"] .ms-drop label').filter({ hasText: '1003' }).click(); |
| 43 | + await page.getByRole('button', { name: '4, 5, 1003' }); |
| 44 | + |
| 45 | + // scroll to near the end and select last 2 labels |
| 46 | + await ulElm2.evaluate(e => (e.scrollTop = e.scrollHeight - 300)); |
| 47 | + await expect(await page.locator('[data-test="select2"] .ms-drop li[data-key=option_1995] label span').innerHTML()).toBe( |
| 48 | + '<i class="fa fa-star"></i> Task 1995', |
| 49 | + ); |
| 50 | + await expect(await page.locator('[data-test="select2"] .ms-drop li[data-key=option_1996] label span').innerHTML()).toBe( |
| 51 | + '<i class="fa fa-star"></i> Task 1996', |
| 52 | + ); |
| 53 | + await page.locator('[data-test="select2"] .ms-drop label').filter({ hasText: '1995' }).click(); |
| 54 | + await page.locator('[data-test="select2"] .ms-drop label').filter({ hasText: '1996' }).click(); |
| 55 | + await page.getByRole('button', { name: '5 of 2000 selected' }); |
| 56 | + |
| 57 | + // pressing arrow down until we reach the end will scroll back to top of the list |
| 58 | + page.keyboard.press('ArrowDown'); |
| 59 | + page.keyboard.press('ArrowDown'); |
| 60 | + page.keyboard.press('ArrowDown'); |
| 61 | + await expect(await page.locator('[data-test="select2"] .ms-drop li[data-key=option_1999]')).toHaveClass('highlighted'); |
| 62 | + |
| 63 | + page.keyboard.press('ArrowDown'); // Task 0 (scrolled back to top) |
| 64 | + |
| 65 | + const firstTaskLoc = await page.locator('div[data-test=select2] .ms-drop li:nth-of-type(1)'); |
| 66 | + await expect(firstTaskLoc).toContainText('Task 0'); |
| 67 | + // await expect(await page.locator('[data-test="select2"] .ms-drop li[data-key=option_0]')).toHaveClass('highlighted'); |
| 68 | + }); |
| 69 | +}); |
0 commit comments