Skip to content

Commit

Permalink
refactor: allow checkboxes as option and add rendering tests for chec…
Browse files Browse the repository at this point in the history
…kboxes enabled (#1045)

* refactor: allow checkboxes as option
  test: enable rendering test for checkboxes

* build: yarn lock

* chore: rm playwright

* test: update baseline

* chore: rm playwrgith from resolutions

* chore: put it back again

* chore: test without res again

* chore: and add resolutions back again
  • Loading branch information
johanlahti committed Jan 10, 2023
1 parent bb7f5b7 commit 4483938
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 7 deletions.
3 changes: 2 additions & 1 deletion apis/nucleus/src/components/listbox/ListBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function ListBox({
model,
selections,
direction,
checkboxes: checkboxOption,
height,
width,
listLayout = 'vertical',
Expand All @@ -35,7 +36,7 @@ export default function ListBox({
const [initScrollPosIsSet, setInitScrollPosIsSet] = useState(false);
const [layout] = useLayout(model);
const isSingleSelect = !!(layout && layout.qListObject.qDimensionInfo.qIsOneAndOnlyOne);
const { checkboxes, histogram } = layout ?? {};
const { checkboxes = checkboxOption, histogram } = layout ?? {};

const loaderRef = useRef(null);
const local = useRef({
Expand Down
2 changes: 2 additions & 0 deletions apis/nucleus/src/components/listbox/ListBoxInline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function ListBoxInline({ options = {} }) {
direction,
frequencyMode,
listLayout,
checkboxes,
search = true,
focusSearch = false,
toolbar = true,
Expand Down Expand Up @@ -268,6 +269,7 @@ export default function ListBoxInline({ options = {} }) {
listLayout={listLayout}
frequencyMode={frequencyMode}
rangeSelect={rangeSelect}
checkboxes={checkboxes}
height={height}
width={width}
update={update}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
]
},
"devDependencies": {
"@playwright/test": "1.28.1",
"@after-work.js/aw": "6.0.14",
"@babel/cli": "7.19.3",
"@babel/core": "7.20.5",
Expand Down Expand Up @@ -106,7 +107,8 @@
"**/caniuse-lite": "1.0.30001435",
"**/react": "18.2.0",
"**/react-dom": "18.2.0",
"**/react-is": "18.2.0"
"**/react-is": "18.2.0",
"@playwright/test": "1.28.1"
},
"workspaces": [
"generated/*",
Expand Down
38 changes: 35 additions & 3 deletions test/rendering/listbox/listbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
};
}

const init = async () => {
const init = async (options = {}) => {
const element = window.document.querySelector('#object');
const { app } = getMocks();
const nebbie = window.stardust.embed(app);
const listboxOptions = {
dense: false,
...options,
};
const inst = await nebbie.field('Alpha');
inst.mount(element, listboxOptions);
Expand All @@ -36,5 +36,37 @@
};
};

return init();
const getOptions = () => {
const paramStrings = document.location.search.split('?').pop().split('&');
const paramsArr = paramStrings.map((stringPair) => {
const [key, val] = stringPair.split('=');
return [key, ['true', 'false'].includes(val) ? JSON.parse(val) : val];
});
const params = Object.fromEntries(paramsArr);
return params;
};

const getScenarioOptions = (s) => {
let sc = {};
switch (s) {
case 'standard':
sc = {};
break;
case 'checkboxes':
sc = { checkboxes: true };
break;
default:
throw new Error('Invalid test scenario', s);
}
return sc;
};

const { scenario, ...options } = getOptions() || {};

const scenarioOptions = getScenarioOptions(scenario);

return init({
...scenarioOptions,
...options,
});
})();
21 changes: 19 additions & 2 deletions test/rendering/listbox/listbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test.describe('listbox mashup rendering test', () => {
test('listbox basic', async () => {
const FILE_NAME = 'listbox_basic.png';

await page.goto(`${url}/listbox/listbox.html`);
await page.goto(`${url}/listbox/listbox.html?scenario=standard`);
const selector = await page.waitForSelector(listboxSelector, { visible: true });

const image = await selector.screenshot();
Expand All @@ -37,7 +37,7 @@ test.describe('listbox mashup rendering test', () => {
test('selecting two values should result in two green rows', async () => {
const FILE_NAME = 'listbox_select_EH.png';

await page.goto(`${url}/listbox/listbox.html`);
await page.goto(`${url}/listbox/listbox.html?scenario=standard`);
const selector = await page.waitForSelector(listboxSelector, { visible: true });

const selectNumbers = [4, 7];
Expand All @@ -50,4 +50,21 @@ test.describe('listbox mashup rendering test', () => {
const image = await selector.screenshot();
return expect(image).toMatchSnapshot(FILE_NAME);
});

test('should render checkboxes and check A and I', async () => {
const FILE_NAME = 'listbox_checkboxes_select_AI.png';

await page.goto(`${url}/listbox/listbox.html?scenario=checkboxes`);
const selector = await page.waitForSelector(listboxSelector, { visible: true });

const selectNumbers = [0, 8];
const action = async (nbr) => {
const rowSelector = `${listboxSelector} [data-n="${nbr}"]`;
await page.click(rowSelector);
};
await execSequence(selectNumbers, action);

const image = await selector.screenshot();
return expect(image).toMatchSnapshot(FILE_NAME);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5071,6 +5071,14 @@
dependencies:
esquery "^1.0.1"

"@playwright/test@1.28.1":
version "1.28.1"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.28.1.tgz#e5be297e024a3256610cac2baaa9347fd57c7860"
integrity sha512-xN6spdqrNlwSn9KabIhqfZR7IWjPpFK1835tFNgjrlysaSezuX8PYUwaz38V/yI8TJLG9PkAMEXoHRXYXlpTPQ==
dependencies:
"@types/node" "*"
playwright-core "1.28.1"

"@pmmmwh/react-refresh-webpack-plugin@^0.5.3":
version "0.5.7"
resolved "https://registry.yarnpkg.com/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.7.tgz#58f8217ba70069cc6a73f5d7e05e85b458c150e2"
Expand Down Expand Up @@ -17585,6 +17593,11 @@ pkg-dir@^5.0.0:
dependencies:
find-up "^5.0.0"

playwright-core@1.28.1:
version "1.28.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.28.1.tgz#8400be9f4a8d1c0489abdb9e75a4cc0ffc3c00cb"
integrity sha512-3PixLnGPno0E8rSBJjtwqTwJe3Yw72QwBBBxNoukIj3lEeBNXwbNiKrNuB1oyQgTBw5QHUhNO3SteEtHaMK6ag==

pngjs@^3.0.0, pngjs@^3.3.3:
version "3.4.0"
resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-3.4.0.tgz#99ca7d725965fb655814eaf65f38f12bbdbf555f"
Expand Down

0 comments on commit 4483938

Please sign in to comment.