Skip to content

Commit 1462d23

Browse files
author
NarrowsProjects
committed
chore: add tests for new buttons
1 parent 439bcf7 commit 1462d23

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

lib/public/components/Filters/common/filtersPanelPopover.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ const pasteButtonOption = (model) => {
164164
filteringModel.setFilterFromURL(url);
165165
},
166166
disabled: !clipboardSupported,
167+
id: 'paste-filter',
167168
}, 'Paste filters');
168169
};
169170

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
};

test/public/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
const NavBarSuite = require('./navBar.test')
1515
const WarningSuite = require('./warnings.test')
16+
const FiltersPanelSuite = require('./filtersPopoverPanel.test')
1617

1718
module.exports = () => {
1819
describe('Navbar component', NavBarSuite);
1920
describe('Warning component', WarningSuite)
21+
describe('FiltersPanelPopover component', FiltersPanelSuite)
2022
};

0 commit comments

Comments
 (0)