|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright CERN and copyright holders of ALICE O2. This software is |
| 4 | + * distributed under the terms of the GNU General Public License v3 (GPL |
| 5 | + * Version 3), copied verbatim in the file "COPYING". |
| 6 | + * |
| 7 | + * See http://alice-o2.web.cern.ch/license for full licensing information. |
| 8 | + * |
| 9 | + * In applying this license CERN does not waive the privileges and immunities |
| 10 | + * granted to it by virtue of its status as an Intergovernmental Organization |
| 11 | + * or submit itself to any jurisdiction. |
| 12 | + */ |
| 13 | + |
| 14 | +const { expect } = require('chai'); |
| 15 | +const { defaultBefore, defaultAfter, pressElement, takeScreenshot, expectInputValue } = require('../defaults.js'); |
| 16 | + |
| 17 | +module.exports = () => { |
| 18 | + let page; |
| 19 | + let browser; |
| 20 | + let context; |
| 21 | + let url; |
| 22 | + |
| 23 | + before(async () => { |
| 24 | + [page, browser, url] = await defaultBefore(page, browser); |
| 25 | + context = browser.defaultBrowserContext(); |
| 26 | + context.overridePermissions(url, ['clipboard-read', 'clipboard-write', 'clipboard-sanitized-write']); |
| 27 | + }); |
| 28 | + |
| 29 | + it('Should copy url when clicking filer copy button', async () => { |
| 30 | + const url = 'http://localhost:4000/?page=lhc-period-overview&filter[names][]=name&filter[years][]=100&filter[pdpBeamTypes][]=PbPb'; |
| 31 | + await page.goto(url, { waitUntil: 'load' }); |
| 32 | + await takeScreenshot(page, 'test'); |
| 33 | + await pressElement(page, '#copy-filter', true); |
| 34 | + |
| 35 | + const clipboardContents = await page.evaluate(async () => decodeURI(await navigator.clipboard.readText())); |
| 36 | + expect(clipboardContents).to.equal(url); |
| 37 | + }); |
| 38 | + |
| 39 | + it('Should set filters when pressing paste active filters button', async () => { |
| 40 | + const url = 'http://localhost:4000/?page=lhc-period-overview&filter[names][]=name&filter[years][]=100&filter[pdpBeamTypes][]=PbPb'; |
| 41 | + |
| 42 | + await page.evaluate(async (url) => await navigator.clipboard.writeText(url), url); |
| 43 | + await pressElement(page, '#paste-filter', true); |
| 44 | + |
| 45 | + const actualUrl = page.url(); |
| 46 | + expect(actualUrl).to.equal(url); |
| 47 | + |
| 48 | + await expectInputValue(page, 'div.flex-row.items-baseline:nth-of-type(1) input[type=text]', 'name'); |
| 49 | + await expectInputValue(page, 'div.flex-row.items-baseline:nth-of-type(2) input[type=text]', '100'); |
| 50 | + await expectInputValue(page, 'div.flex-row.items-baseline:nth-of-type(3) input[type=text]', 'PbPb'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('Should set filters when pressing paste active filters button', async () => { |
| 54 | + const url = 'http://localhost:4000/?page=lhc-period-overview&filter[names][]=name&filter[years][]=100&filter[pdpBeamTypes][]=PbPb'; |
| 55 | + |
| 56 | + await page.evaluate(async (url) => await navigator.clipboard.writeText(url), url); |
| 57 | + await pressElement(page, '#paste-filter', true); |
| 58 | + |
| 59 | + const actualUrl = page.url(); |
| 60 | + expect(actualUrl).to.equal(url); |
| 61 | + |
| 62 | + await expectInputValue(page, 'div.flex-row.items-baseline:nth-of-type(1) input[type=text]', 'name'); |
| 63 | + await expectInputValue(page, 'div.flex-row.items-baseline:nth-of-type(2) input[type=text]', '100'); |
| 64 | + await expectInputValue(page, 'div.flex-row.items-baseline:nth-of-type(3) input[type=text]', 'PbPb'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('Should reset filters when pressing the reset all filters button', async () => { |
| 68 | + const url = 'http://localhost:4000/?page=lhc-period-overview&filter[names][]=name&filter[years][]=100&filter[pdpBeamTypes][]=PbPb'; |
| 69 | + |
| 70 | + await page.goto(url, { waitUntil: 'load' }); |
| 71 | + |
| 72 | + await page.evaluate(async (url) => await navigator.clipboard.writeText(url), url); |
| 73 | + await pressElement(page, '.dropdown #reset-filters', true); |
| 74 | + |
| 75 | + const actualUrl = page.url(); |
| 76 | + expect(actualUrl).to.equal('http://localhost:4000/?page=lhc-period-overview'); |
| 77 | + |
| 78 | + await expectInputValue(page, '.name-filter input', ''); |
| 79 | + await expectInputValue(page, '.year-filter input', ''); |
| 80 | + await expectInputValue(page, '.pdpBeamTypes-filter input', ''); |
| 81 | + }); |
| 82 | + |
| 83 | + after(async () => { |
| 84 | + await defaultAfter(page, browser); |
| 85 | + }); |
| 86 | +}; |
0 commit comments