chore: fix tests

This commit is contained in:
Thijs Louisse 2022-03-16 12:37:02 +01:00
parent 9434a2fae7
commit b45f340aba
8 changed files with 22 additions and 26 deletions

View file

@ -345,9 +345,18 @@ const FormatMixinImplementation = superclass =>
*/ */
__handlePreprocessor() { __handlePreprocessor() {
const unprocessedValue = this.value; const unprocessedValue = this.value;
let currentCaretIndex = this.value.length;
// Be gentle with Safari
if (
this._inputNode &&
'selectionStart' in this._inputNode &&
/** @type {HTMLInputElement} */ (this._inputNode)?.type !== 'range'
) {
currentCaretIndex = /** @type {number} */ (this._inputNode.selectionStart);
}
const preprocessedValue = this.preprocessor(this.value, { const preprocessedValue = this.preprocessor(this.value, {
...this.formatOptions, ...this.formatOptions,
currentCaretIndex: this._inputNode?.selectionStart || this.value.length, currentCaretIndex,
prevViewValue: this.__prevViewValue, prevViewValue: this.__prevViewValue,
}); });

View file

@ -61,10 +61,8 @@ describe('Validator', () => {
} }
} }
const vali = new MyValidator( // @ts-ignore needed for test
{}, const vali = new MyValidator({}, { getMessage: 'This is the custom error message' });
{ getMessage: async () => 'This is the custom error message' },
);
const { getMessage } = getProtectedMembers(vali); const { getMessage } = getProtectedMembers(vali);
await expectThrowsAsync( await expectThrowsAsync(
@ -98,7 +96,7 @@ describe('Validator', () => {
name: 'MyValidator', name: 'MyValidator',
type: 'error', type: 'error',
params: 'myParam', params: 'myParam',
config: { my: 'config', getMessage: configSpy }, config: { fieldName: 'X', getMessage: configSpy },
}); });
}); });
@ -125,7 +123,7 @@ describe('Validator', () => {
name: 'MyValidator', name: 'MyValidator',
type: 'error', type: 'error',
params: 'myParam', params: 'myParam',
config: { my: 'config' }, config: { fieldName: 'X' },
}); });
}); });

View file

@ -48,7 +48,6 @@
"access": "public" "access": "public"
}, },
"customElements": "custom-elements.json", "customElements": "custom-elements.json",
"customElementsManifest": "custom-elements.json",
"exports": { "exports": {
".": "./index.js", ".": "./index.js",
"./define": "./define.js", "./define": "./define.js",

View file

@ -209,18 +209,5 @@ export function runInputTelDropdownSuite({ klass = LionInputTelDropdown } = {})
); );
}); });
}); });
describe('When refs.dropdown is a FormControl (LionSelectRich/LionCombobox)', () => {
it('updates dropdown value ', async () => {
const el = await fixture(html` <${tag} .modelValue="${'+31612345678'}"></${tag}> `);
expect(el.activeRegion).to.equal('NL');
// @ts-expect-error [allow protected]
el._setActiveRegion('BE');
await el.updateComplete;
expect(getDropdownValue(/** @type {DropdownElement} */ (el.refs.dropdown.value))).to.equal(
'BE',
);
});
});
}); });
} }

View file

@ -44,6 +44,9 @@ class WithFormControlInputTelDropdown extends LionInputTelDropdown {
// @ts-expect-error // @ts-expect-error
runInputTelSuite({ klass: LionInputTelDropdown }); runInputTelSuite({ klass: LionInputTelDropdown });
runInputTelDropdownSuite(); runInputTelDropdownSuite();
describe('WithFormControlInputTelDropdown', () => {
// @ts-expect-error // @ts-expect-error
// Runs it for LionSelectRich, which uses .modelValue/@model-value-changed instead of .value/@change // Runs it for LionSelectRich, which uses .modelValue/@model-value-changed instead of .value/@change
runInputTelDropdownSuite({ klass: WithFormControlInputTelDropdown }); runInputTelDropdownSuite({ klass: WithFormControlInputTelDropdown });
});

View file

@ -52,7 +52,6 @@
"access": "public" "access": "public"
}, },
"customElements": "custom-elements.json", "customElements": "custom-elements.json",
"customElementsManifest": "custom-elements.json",
"exports": { "exports": {
".": "./index.js", ".": "./index.js",
"./define": "./define.js", "./define": "./define.js",

View file

@ -6,6 +6,7 @@ const packages = fs
.filter( .filter(
dir => fs.statSync(`packages/${dir}`).isDirectory() && fs.existsSync(`packages/${dir}/test`), dir => fs.statSync(`packages/${dir}`).isDirectory() && fs.existsSync(`packages/${dir}/test`),
) )
// .filter(x => x.endsWith('-dropdown'))
.concat( .concat(
fs fs
.readdirSync('packages/helpers') .readdirSync('packages/helpers')