test-autotest-strict-vlid-fill.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { TestRunner } from './src/tools/autotest/test-runner.js';
  2. function assert(condition, message) {
  3. if (!condition) throw new Error(message);
  4. }
  5. class MissingLocator {
  6. async count() {
  7. return 0;
  8. }
  9. async waitFor() {
  10. throw new Error('not attached');
  11. }
  12. async fill() {
  13. throw new Error('should not fill missing locator');
  14. }
  15. async click() {
  16. throw new Error('should not click missing locator');
  17. }
  18. locator() {
  19. return this;
  20. }
  21. first() {
  22. return this;
  23. }
  24. }
  25. console.log('\n── AutoTest Strict vlid Fill ──');
  26. const runner = new TestRunner({ baseUrl: 'https://example.test/app' });
  27. let typed = false;
  28. runner.page = {
  29. keyboard: {
  30. async type() {
  31. typed = true;
  32. },
  33. },
  34. };
  35. runner._resolveSelector = async () => new MissingLocator();
  36. let err = null;
  37. try {
  38. await runner._executeAction({
  39. action: 'fill',
  40. selector: 'vlid:formDescInput input',
  41. value: 'abc',
  42. });
  43. } catch (error) {
  44. err = error;
  45. }
  46. assert(err, 'strict vlid fill should fail when component id is missing');
  47. assert(
  48. String(err.message).includes('component id not found'),
  49. 'strict vlid fill should report missing component id'
  50. );
  51. assert(!typed, 'strict vlid fill must not fall back to keyboard typing on the active element');
  52. console.log('PASS test-autotest-strict-vlid-fill.js');