@redrockswebdevelopment/formstack-form-testing 0.1.36 → 0.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -78,7 +78,7 @@ export const liveFormFieldTypeCoverage = {
78
78
  domInteraction: true,
79
79
  domAssertion: true,
80
80
  reason: "Email fields behave like text fields with validation-specific assertions.",
81
- recommendedHelpers: ["setLiveFormFieldValueTransaction", "fillEmail", "waitForLiveFormValidationState"],
81
+ recommendedHelpers: ["setLiveFormTextValue", "fillEmail", "waitForLiveFormValidationState"],
82
82
  },
83
83
  file: {
84
84
  kind: "file",
@@ -114,7 +114,7 @@ export const liveFormFieldTypeCoverage = {
114
114
  domInteraction: true,
115
115
  domAssertion: true,
116
116
  reason: "Number fields use simple value payloads; use validation assertions for numeric constraints.",
117
- recommendedHelpers: ["setLiveFormFieldValueTransaction", "fillNumber", "waitForLiveFormValidationState"],
117
+ recommendedHelpers: ["setLiveFormTextValue", "fillNumber", "waitForLiveFormValidationState"],
118
118
  },
119
119
  pagebreak: {
120
120
  kind: "pagebreak",
@@ -142,7 +142,7 @@ export const liveFormFieldTypeCoverage = {
142
142
  domInteraction: true,
143
143
  domAssertion: true,
144
144
  reason: "Phone fields use simple value payloads; use DOM and validation assertions for formatting behavior.",
145
- recommendedHelpers: ["setLiveFormFieldValueTransaction", "fillPhone", "waitForLiveFormValidationState"],
145
+ recommendedHelpers: ["setLiveFormTextValue", "fillPhone", "waitForLiveFormValidationState"],
146
146
  },
147
147
  product: {
148
148
  kind: "product",
@@ -205,7 +205,7 @@ export const liveFormFieldTypeCoverage = {
205
205
  domInteraction: true,
206
206
  domAssertion: true,
207
207
  reason: "Textarea fields use simple value payloads and stable DOM fill operations.",
208
- recommendedHelpers: ["setLiveFormFieldValueTransaction", "fillTextarea", "readLiveFormDomFieldState"],
208
+ recommendedHelpers: ["setLiveFormTextValue", "fillTextarea", "readLiveFormDomFieldState"],
209
209
  },
210
210
  text: {
211
211
  kind: "text",
@@ -214,7 +214,7 @@ export const liveFormFieldTypeCoverage = {
214
214
  domInteraction: true,
215
215
  domAssertion: true,
216
216
  reason: "Text fields use simple value payloads and stable DOM fill operations.",
217
- recommendedHelpers: ["setLiveFormFieldValueTransaction", "fillText", "readLiveFormDomFieldState"],
217
+ recommendedHelpers: ["setLiveFormTextValue", "fillText", "readLiveFormDomFieldState"],
218
218
  },
219
219
  unknown: {
220
220
  kind: "unknown",
@@ -4284,6 +4284,72 @@ export async function setLiveFormCheckboxValues(page, options) {
4284
4284
  (commitControl?.ready ?? true),
4285
4285
  };
4286
4286
  }
4287
+ export async function setLiveFormTextValue(page, options) {
4288
+ const value = String(options.value);
4289
+ const fieldKind = options.fieldKind ?? "text";
4290
+ const transaction = await performLiveFormFieldTransaction(page, {
4291
+ write: {
4292
+ ...(options.write ?? {}),
4293
+ target: options.target,
4294
+ value,
4295
+ notify: options.write?.notify ?? true,
4296
+ },
4297
+ fieldKind,
4298
+ waitForEvent: options.waitForEvent ?? true,
4299
+ dispatchDomEvents: options.dispatchDomEvents ?? "auto",
4300
+ afterQuiet: options.afterQuiet ?? { quietMs: 200, timeoutMs: 5_000 },
4301
+ ...(options.afterValidation === undefined ? {} : { afterValidation: options.afterValidation }),
4302
+ });
4303
+ let dom = await readLiveFormDomFieldState(page, {
4304
+ ...options.target,
4305
+ expectedValue: value,
4306
+ ...(options.controlSelector === undefined ? {} : { controlSelector: options.controlSelector }),
4307
+ });
4308
+ const domInputSelector = options.target.internalLabel
4309
+ ? formstackSelectors.fieldInputByInternalLabel(options.target.internalLabel)
4310
+ : options.target.fieldId == null
4311
+ ? null
4312
+ : formstackSelectors.fieldInputById(options.target.fieldId);
4313
+ if (!dom.matched && options.syncDomValue !== false && domInputSelector) {
4314
+ await page.locator(domInputSelector).first().fill(value);
4315
+ const dispatchOptions = resolveLiveFormDispatchOptions(options.dispatchDomEvents ?? "auto", fieldKind);
4316
+ if (dispatchOptions) {
4317
+ await dispatchLiveFormFieldDomEvents(page, {
4318
+ ...dispatchOptions,
4319
+ target: options.target,
4320
+ });
4321
+ }
4322
+ if (options.afterQuiet !== false) {
4323
+ await waitForLiveFormQuiet(page, typeof options.afterQuiet === "object" ? options.afterQuiet : { quietMs: 200, timeoutMs: 5_000 });
4324
+ }
4325
+ dom = await waitForLiveFormDomFieldState(page, {
4326
+ ...options.target,
4327
+ expectedValue: value,
4328
+ ...(options.controlSelector === undefined ? {} : { controlSelector: options.controlSelector }),
4329
+ ...(options.write?.timeoutMs === undefined ? {} : { timeoutMs: options.write.timeoutMs }),
4330
+ });
4331
+ }
4332
+ const visibilityTargets = [
4333
+ ...(options.expectVisible ?? []).map((target) => ({ ...target, visible: true })),
4334
+ ...(options.expectHidden ?? []).map((target) => ({ ...target, visible: false })),
4335
+ ];
4336
+ const visibility = visibilityTargets.length > 0
4337
+ ? await waitForLiveFormVisibility(page, { targets: visibilityTargets })
4338
+ : undefined;
4339
+ return {
4340
+ value,
4341
+ transaction,
4342
+ dom,
4343
+ ...(visibility ? { visibility } : {}),
4344
+ ok: transaction.write.valueMatched &&
4345
+ (transaction.event?.matched ?? true) &&
4346
+ (transaction.domDispatch ? transaction.domDispatch.matchedControlCount >= 1 : true) &&
4347
+ (transaction.quiet?.quiet ?? true) &&
4348
+ ((transaction.validation?.inlineErrors.length ?? 0) === 0) &&
4349
+ dom.matched &&
4350
+ (visibility?.matched ?? true),
4351
+ };
4352
+ }
4287
4353
  export async function setLiveFormChoiceValue(page, options) {
4288
4354
  const payload = normalizeLiveFormChoiceValue(options.value);
4289
4355
  const value = payload.value;
@@ -4722,6 +4788,18 @@ export async function answerProgressiveLiveFormField(page, options) {
4722
4788
  ...(validationOptions ? { afterValidation: validationOptions } : {}),
4723
4789
  })
4724
4790
  : undefined;
4791
+ const textTransaction = !checkboxTransaction && !choiceTransaction && !selectTransaction && !matrixTransaction && !nameTransaction && !addressTransaction && !productTransaction && !ratingTransaction && !dateTimeTransaction && ["text", "textarea", "email", "phone", "number"].includes(options.fieldKind ?? "")
4792
+ ? await setLiveFormTextValue(page, {
4793
+ target: options.target,
4794
+ value: options.value,
4795
+ fieldKind: options.fieldKind,
4796
+ ...(options.write === undefined ? {} : { write: options.write }),
4797
+ waitForEvent: options.waitForEvent ?? true,
4798
+ dispatchDomEvents: options.dispatchDomEvents ?? "auto",
4799
+ afterQuiet: options.afterQuiet ?? true,
4800
+ ...(validationOptions ? { afterValidation: validationOptions } : {}),
4801
+ })
4802
+ : undefined;
4725
4803
  const transaction = checkboxTransaction
4726
4804
  ? checkboxTransaction.transaction
4727
4805
  : choiceTransaction
@@ -4740,19 +4818,21 @@ export async function answerProgressiveLiveFormField(page, options) {
4740
4818
  ? ratingTransaction.transaction
4741
4819
  : dateTimeTransaction
4742
4820
  ? dateTimeTransaction.transaction
4743
- : await performLiveFormFieldTransaction(page, {
4744
- write: {
4745
- ...(options.write ?? {}),
4746
- target: options.target,
4747
- value: options.value,
4748
- notify: options.write?.notify ?? true,
4749
- },
4750
- ...(options.fieldKind ? { fieldKind: options.fieldKind } : {}),
4751
- waitForEvent: options.waitForEvent ?? true,
4752
- dispatchDomEvents: options.dispatchDomEvents ?? "auto",
4753
- afterQuiet: options.afterQuiet ?? true,
4754
- ...(validationOptions ? { afterValidation: validationOptions } : {}),
4755
- });
4821
+ : textTransaction
4822
+ ? textTransaction.transaction
4823
+ : await performLiveFormFieldTransaction(page, {
4824
+ write: {
4825
+ ...(options.write ?? {}),
4826
+ target: options.target,
4827
+ value: options.value,
4828
+ notify: options.write?.notify ?? true,
4829
+ },
4830
+ ...(options.fieldKind ? { fieldKind: options.fieldKind } : {}),
4831
+ waitForEvent: options.waitForEvent ?? true,
4832
+ dispatchDomEvents: options.dispatchDomEvents ?? "auto",
4833
+ afterQuiet: options.afterQuiet ?? true,
4834
+ ...(validationOptions ? { afterValidation: validationOptions } : {}),
4835
+ });
4756
4836
  const visibilityTargets = [
4757
4837
  ...(options.expectVisible ?? []),
4758
4838
  ...(options.expectHidden ?? []).map((target) => ({ ...target, visible: false })),
@@ -6482,6 +6562,26 @@ export const liveFormFieldRecipes = {
6482
6562
  });
6483
6563
  },
6484
6564
  }),
6565
+ setTextApi: (name, internalLabel, value, options = {}) => ({
6566
+ name,
6567
+ run: async (harness) => {
6568
+ await setLiveFormTextValue(harness.page, {
6569
+ target: { internalLabel },
6570
+ value,
6571
+ fieldKind: options.fieldKind && ["text", "textarea", "email", "phone", "number"].includes(options.fieldKind)
6572
+ ? options.fieldKind
6573
+ : "text",
6574
+ write: { notify: options.notify ?? true },
6575
+ waitForEvent: options.waitForEvent ?? (options.notify ?? true),
6576
+ dispatchDomEvents: options.dispatchDomEvents ?? "auto",
6577
+ afterQuiet: options.waitForQuiet ?? true,
6578
+ });
6579
+ },
6580
+ }),
6581
+ setTextareaApi: (name, internalLabel, value, options = {}) => liveFormFieldRecipes.setTextApi(name, internalLabel, value, { ...options, fieldKind: "textarea" }),
6582
+ setEmailApi: (name, internalLabel, value, options = {}) => liveFormFieldRecipes.setTextApi(name, internalLabel, value, { ...options, fieldKind: "email" }),
6583
+ setPhoneApi: (name, internalLabel, value, options = {}) => liveFormFieldRecipes.setTextApi(name, internalLabel, value, { ...options, fieldKind: "phone" }),
6584
+ setNumberApi: (name, internalLabel, value, options = {}) => liveFormFieldRecipes.setTextApi(name, internalLabel, value, { ...options, fieldKind: "number" }),
6485
6585
  setChoiceApi: (name, internalLabel, value, options = {}) => ({
6486
6586
  name,
6487
6587
  run: async (harness) => {