@skyux/forms 12.0.0-alpha.0 → 12.0.0-alpha.2

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.
@@ -1,5 +1,5 @@
1
1
  import { HarnessPredicate, ComponentHarness } from '@angular/cdk/testing';
2
- import { SkyComponentHarness, SkyQueryableComponentHarness, provideSkyFileReaderTesting } from '@skyux/core/testing';
2
+ import { SkyComponentHarness, SkyQueryableComponentHarness, SkyInputHarness, provideSkyFileReaderTesting } from '@skyux/core/testing';
3
3
  import { SkyHelpInlineHarness } from '@skyux/help-inline/testing';
4
4
  import { SkyStatusIndicatorHarness } from '@skyux/indicators/testing';
5
5
  import { SkyPopoverHarness } from '@skyux/popovers/testing';
@@ -953,15 +953,78 @@ class SkyFileAttachmentHarness extends SkyComponentHarness {
953
953
  }
954
954
 
955
955
  /**
956
- * Harness for interacting with a file drop component in tests.
956
+ * Harness to interact with the file drop link upload input harness.
957
+ */
958
+ class SkyFileDropLinkUploadInputHarness extends SkyInputHarness {
959
+ /**
960
+ * @internal
961
+ */
962
+ static { this.hostSelector = 'input.sky-form-control'; }
963
+ /**
964
+ * Gets the input aria-label
965
+ */
966
+ async getAriaLabel() {
967
+ return await (await this.host()).getAttribute('aria-label');
968
+ }
969
+ }
970
+
971
+ /**
972
+ * Harness for interacting with file drop component's link upload feature in tests.
957
973
  * @internal
958
974
  */
975
+ class SkyFileDropLinkUploadHarness extends SkyComponentHarness {
976
+ /**
977
+ * @internal
978
+ */
979
+ static { this.hostSelector = '.sky-file-drop-link'; }
980
+ #input = this.locatorFor(SkyFileDropLinkUploadInputHarness);
981
+ #inputBoxHarness = this.locatorFor(SkyInputBoxHarness);
982
+ #button = this.locatorFor('button.sky-btn-primary');
983
+ /**
984
+ * Clicks the `Done` button
985
+ */
986
+ async clickDoneButton() {
987
+ if (await this.#isDoneDisabled()) {
988
+ throw new Error('Done button is disabled and cannot be clicked. Enter text to enable link upload.');
989
+ }
990
+ return await (await this.#button()).click();
991
+ }
992
+ /**
993
+ * Enters text into the link upload input.
994
+ */
995
+ async enterText(link) {
996
+ return await (await this.#input()).setValue(link);
997
+ }
998
+ /**
999
+ * Gets the link upload aria-label.
1000
+ */
1001
+ async getAriaLabel() {
1002
+ return await (await this.#input()).getAriaLabel();
1003
+ }
1004
+ /**
1005
+ * Gets the hint text.
1006
+ */
1007
+ async getHintText() {
1008
+ return await (await this.#inputBoxHarness()).getHintText();
1009
+ }
1010
+ async #isDoneDisabled() {
1011
+ return (await (await this.#button()).getAttribute('disabled')) !== null;
1012
+ }
1013
+ }
1014
+
1015
+ /**
1016
+ * Harness for interacting with a file drop component in tests.
1017
+ */
959
1018
  class SkyFileDropHarness extends SkyComponentHarness {
960
1019
  /**
961
1020
  * @internal
962
1021
  */
963
1022
  static { this.hostSelector = 'sky-file-drop'; }
964
1023
  #getDropTarget = this.locatorFor('.sky-file-drop-target');
1024
+ #input = this.locatorFor('input[type="file"]');
1025
+ #fileUploadButton = this.locatorFor('button.sky-file-drop-target');
1026
+ #label = this.locatorFor('.sky-file-drop-label-text');
1027
+ #formErrors = this.locatorForAll(SkyFormErrorsHarness);
965
1028
  /**
966
1029
  * Gets a `HarnessPredicate` that can be used to search for a
967
1030
  * `SkyFileDropHarness` that meets certain criteria.
@@ -970,24 +1033,171 @@ class SkyFileDropHarness extends SkyComponentHarness {
970
1033
  return SkyFileDropHarness.getDataSkyIdPredicate(filters);
971
1034
  }
972
1035
  /**
973
- * Drops a file onto the component's drop target.
1036
+ * Clicks the file drop target.
974
1037
  */
975
- async dropFile(file) {
1038
+ async clickFileDropTarget() {
1039
+ return await (await this.#fileUploadButton()).click();
1040
+ }
1041
+ /**
1042
+ * Clicks the help inline button.
1043
+ */
1044
+ async clickHelpInline() {
1045
+ return await (await this.#getHelpInline()).click();
1046
+ }
1047
+ /**
1048
+ * Clicks the link upload `Done` button'.
1049
+ */
1050
+ async clickLinkUploadDoneButton() {
1051
+ return await (await this.#getLinkUpload()).clickDoneButton();
1052
+ }
1053
+ /**
1054
+ * Enters text into the link upload input.
1055
+ */
1056
+ async enterLinkUploadText(link) {
1057
+ return await (await this.#getLinkUpload()).enterText(link);
1058
+ }
1059
+ /**
1060
+ * Gets the accepted file types.
1061
+ */
1062
+ async getAcceptedTypes() {
1063
+ return await (await this.#input()).getAttribute('accept');
1064
+ }
1065
+ /**
1066
+ * Gets the aria-label for the file upload button.
1067
+ */
1068
+ async getFileUploadAriaLabel() {
1069
+ return await (await this.#fileUploadButton()).getAttribute('aria-label');
1070
+ }
1071
+ /**
1072
+ * Gets the help inline popover content.
1073
+ */
1074
+ async getHelpPopoverContent() {
1075
+ const content = await (await this.#getHelpInline()).getPopoverContent();
1076
+ return content;
1077
+ }
1078
+ /**
1079
+ * Gets the help inline popover title.
1080
+ */
1081
+ async getHelpPopoverTitle() {
1082
+ return await (await this.#getHelpInline()).getPopoverTitle();
1083
+ }
1084
+ /**
1085
+ * Gets the hint text.
1086
+ */
1087
+ async getHintText() {
1088
+ return (await (await this.locatorFor('.sky-file-drop-hint-text')()).text()).trim();
1089
+ }
1090
+ /**
1091
+ * Gets the label text.
1092
+ */
1093
+ async getLabelText() {
1094
+ return (await (await this.#label()).text()).trim();
1095
+ }
1096
+ /**
1097
+ * Gets the link upload aria-label.
1098
+ */
1099
+ async getLinkUploadAriaLabel() {
1100
+ return await (await this.#getLinkUpload()).getAriaLabel();
1101
+ }
1102
+ /**
1103
+ * Gets the link upload hint text.
1104
+ */
1105
+ async getLinkUploadHintText() {
1106
+ return await (await this.#getLinkUpload()).getHintText();
1107
+ }
1108
+ /**
1109
+ * Whether a custom form error has fired.
1110
+ */
1111
+ async hasCustomError(errorName) {
1112
+ return await (await this.#getFormErrors()).hasError(errorName);
1113
+ }
1114
+ /**
1115
+ * Whether the file type error has fired.
1116
+ */
1117
+ async hasFileTypeError() {
1118
+ return await (await this.#getFormErrors()).hasError('fileType');
1119
+ }
1120
+ /**
1121
+ * Whether the max file size error has fired.
1122
+ */
1123
+ async hasMaxFileSizeError() {
1124
+ return await (await this.#getFormErrors()).hasError('maxFileSize');
1125
+ }
1126
+ /**
1127
+ * Whether the min file size error has fired.
1128
+ */
1129
+ async hasMinFileSizeError() {
1130
+ return await (await this.#getFormErrors()).hasError('minFileSize');
1131
+ }
1132
+ /**
1133
+ * Whether the required error has fired.
1134
+ */
1135
+ async hasRequiredError() {
1136
+ return await (await this.#getFormErrors()).hasError('required');
1137
+ }
1138
+ /**
1139
+ * Whether the validate error from the customer validation has fired.
1140
+ */
1141
+ async hasValidateFnError() {
1142
+ return await (await this.#getFormErrors()).hasError('validate');
1143
+ }
1144
+ /**
1145
+ * Whether label text is hidden.
1146
+ */
1147
+ async isLabelHidden() {
1148
+ return await (await this.locatorFor('legend.sky-control-label')()).hasClass('sky-screen-reader-only');
1149
+ }
1150
+ /**
1151
+ * Whether file drop is required.
1152
+ */
1153
+ async isRequired() {
1154
+ return await (await this.#label()).hasClass('sky-control-label-required');
1155
+ }
1156
+ /**
1157
+ * Whether file drop has stacked enabled.
1158
+ */
1159
+ async isStacked() {
1160
+ return await (await this.host()).hasClass('sky-form-field-stacked');
1161
+ }
1162
+ /**
1163
+ * Loads a single file.
1164
+ */
1165
+ async loadFile(file) {
976
1166
  await this.#dropFiles([file]);
977
1167
  }
978
- // Consider making this public when we finalize this harness's public API.
1168
+ /**
1169
+ * Loads multiple files.
1170
+ */
1171
+ async loadFiles(files) {
1172
+ return await this.#dropFiles(files);
1173
+ }
979
1174
  async #dropFiles(files) {
980
1175
  const dropTarget = await this.#getDropTarget();
981
- const fileList = {
982
- item: (index) => files[index],
983
- length: files.length,
984
- };
1176
+ const dataTransfer = new DataTransfer();
1177
+ files?.forEach((file) => {
1178
+ dataTransfer.items.add(file);
1179
+ });
985
1180
  await dropTarget.dispatchEvent('drop', {
986
- dataTransfer: {
987
- files: fileList,
988
- },
1181
+ dataTransfer,
989
1182
  });
990
1183
  }
1184
+ async #getFormErrors() {
1185
+ return (await this.#formErrors())[1];
1186
+ }
1187
+ async #getHelpInline() {
1188
+ const harness = await this.locatorForOptional(SkyHelpInlineHarness)();
1189
+ if (harness) {
1190
+ return harness;
1191
+ }
1192
+ throw Error('No help inline found.');
1193
+ }
1194
+ async #getLinkUpload() {
1195
+ const linkUpload = await this.locatorForOptional(SkyFileDropLinkUploadHarness)();
1196
+ if (linkUpload) {
1197
+ return linkUpload;
1198
+ }
1199
+ throw new Error('Link upload cannot be found. Set `allowLinks` property to `true`.');
1200
+ }
991
1201
  }
992
1202
 
993
1203
  /**
@@ -1003,6 +1213,45 @@ function provideSkyFileAttachmentTesting() {
1003
1213
  return [provideSkyFileReaderTesting()];
1004
1214
  }
1005
1215
 
1216
+ /**
1217
+ * Harness for interacting with a file item component in tests.
1218
+ */
1219
+ class SkyFileItemHarness extends ComponentHarness {
1220
+ /**
1221
+ * @internal
1222
+ */
1223
+ static { this.hostSelector = 'sky-file-item'; }
1224
+ /**
1225
+ * Gets a `HarnessPredicate` that can be used to search for a
1226
+ * `SkyFileItemHarness` that meets certain criteria.
1227
+ */
1228
+ static with(filters) {
1229
+ return new HarnessPredicate(SkyFileItemHarness, filters).addOption('fileName', filters.fileName, async (harness, fileName) => {
1230
+ const harnessFileName = await harness.getFileName();
1231
+ return await HarnessPredicate.stringMatches(harnessFileName, fileName);
1232
+ });
1233
+ }
1234
+ /**
1235
+ * Clicks the delete button.
1236
+ */
1237
+ async clickDeleteButton() {
1238
+ return await (await this.locatorFor('.sky-file-item-btn-delete')()).click();
1239
+ }
1240
+ /**
1241
+ * Gets the file name.
1242
+ */
1243
+ async getFileName() {
1244
+ return await (await this.locatorFor('.sky-file-item-name')()).text();
1245
+ }
1246
+ /**
1247
+ * Gets the file size.
1248
+ */
1249
+ async getFileSize() {
1250
+ const size = await (await this.locatorFor('.sky-file-item-size')()).text();
1251
+ return size.substring(1, size.length - 1);
1252
+ }
1253
+ }
1254
+
1006
1255
  /**
1007
1256
  * Harness for interacting with a field group component in tests.
1008
1257
  */
@@ -1494,5 +1743,5 @@ class SkyRadioGroupHarness extends SkyComponentHarness {
1494
1743
  * Generated bundle index. Do not edit.
1495
1744
  */
1496
1745
 
1497
- export { SkyCharacterCounterIndicatorHarness, SkyCheckboxFixture, SkyCheckboxGroupHarness, SkyCheckboxHarness, SkyCheckboxLabelHarness, SkyFieldGroupHarness, SkyFileAttachmentHarness, SkyFileDropHarness, SkyFormErrorHarness, SkyFormErrorsHarness, SkyInputBoxHarness, SkyRadioFixture, SkyRadioGroupHarness, SkyRadioHarness, SkyRadioLabelHarness, provideSkyFileAttachmentTesting };
1746
+ export { SkyCharacterCounterIndicatorHarness, SkyCheckboxFixture, SkyCheckboxGroupHarness, SkyCheckboxHarness, SkyCheckboxLabelHarness, SkyFieldGroupHarness, SkyFileAttachmentHarness, SkyFileDropHarness, SkyFileItemHarness, SkyFormErrorHarness, SkyFormErrorsHarness, SkyInputBoxHarness, SkyRadioFixture, SkyRadioGroupHarness, SkyRadioHarness, SkyRadioLabelHarness, provideSkyFileAttachmentTesting };
1498
1747
  //# sourceMappingURL=skyux-forms-testing.mjs.map