Files
nebula.js/test/rendering/listbox/listbox.js
Johan Lahti 448393868d refactor: allow checkboxes as option and add rendering tests for checkboxes 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
2023-01-10 14:56:38 +01:00

73 lines
1.8 KiB
JavaScript

(() => {
function getMocks() {
const { getMockData, getListboxLayout } = window.getFuncs();
const obj = {
id: `listbox-${+new Date()}`,
getListObjectData: async () => getMockData(),
getLayout: async () => getListboxLayout(),
on() {},
once() {},
};
const app = {
id: `${+new Date()}`,
session: {},
createSessionObject: async () => obj,
getObject: async () => obj,
getAppLayout: async () => ({ qTitle: '', qLocaleInfo: {} }),
};
return {
obj,
app,
};
}
const init = async (options = {}) => {
const element = window.document.querySelector('#object');
const { app } = getMocks();
const nebbie = window.stardust.embed(app);
const listboxOptions = {
...options,
};
const inst = await nebbie.field('Alpha');
inst.mount(element, listboxOptions);
return () => {
inst?.unmount(element);
};
};
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,
});
})();