Lines 168-173
function get_licenses_additional_fields() {
Link Here
|
168 |
]; |
168 |
]; |
169 |
} |
169 |
} |
170 |
|
170 |
|
|
|
171 |
function get_no_additional_fields_agreement() { |
172 |
return { |
173 |
agreement_id: 1, |
174 |
name: "agreement 1", |
175 |
description: "my first agreement", |
176 |
agreement_licenses: [], |
177 |
agreement_packages: [], |
178 |
agreement_relationships: [], |
179 |
closure_reason: "", |
180 |
is_perpetual: false, |
181 |
license_info: "", |
182 |
periods: [], |
183 |
renewal_priority: "", |
184 |
status: "active", |
185 |
user_roles: [], |
186 |
vendor_id: 1, |
187 |
vendor: [cy.get_vendors_to_relate()[0]], |
188 |
documents: [ |
189 |
{ |
190 |
agreement_id: 1, |
191 |
file_description: "file description", |
192 |
file_name: "file.json", |
193 |
notes: "file notes", |
194 |
physical_location: "file physical location", |
195 |
uri: "file uri", |
196 |
uploaded_on: "2022-10-27T11:57:02+00:00", |
197 |
}, |
198 |
], |
199 |
extended_attributes: [], |
200 |
_strings: { |
201 |
"additional_field_values": [] |
202 |
}, |
203 |
}; |
204 |
} |
205 |
function get_agreement() { |
206 |
return { |
207 |
agreement_id: 1, |
208 |
name: "agreement 1", |
209 |
description: "my first agreement", |
210 |
agreement_licenses: [], |
211 |
agreement_packages: [], |
212 |
agreement_relationships: [], |
213 |
closure_reason: "", |
214 |
is_perpetual: false, |
215 |
license_info: "", |
216 |
periods: [], |
217 |
renewal_priority: "", |
218 |
status: "active", |
219 |
user_roles: [], |
220 |
vendor_id: 1, |
221 |
vendor: [cy.get_vendors_to_relate()[0]], |
222 |
documents: [ |
223 |
{ |
224 |
agreement_id: 1, |
225 |
file_description: "file description", |
226 |
file_name: "file.json", |
227 |
notes: "file notes", |
228 |
physical_location: "file physical location", |
229 |
uri: "file uri", |
230 |
uploaded_on: "2022-10-27T11:57:02+00:00", |
231 |
}, |
232 |
], |
233 |
extended_attributes: [ |
234 |
{ |
235 |
field_id: 1, |
236 |
id: "1", |
237 |
record_id: "1", |
238 |
value: "REF", |
239 |
}, |
240 |
{ |
241 |
field_id: 1, |
242 |
id: "2", |
243 |
record_id: "1", |
244 |
value: "NFIC", |
245 |
}, |
246 |
{ |
247 |
field_id: 2, |
248 |
id: "3", |
249 |
record_id: "1", |
250 |
value: "some text", |
251 |
}, |
252 |
{ |
253 |
field_id: 3, |
254 |
id: "4", |
255 |
record_id: "1", |
256 |
value: "some repeatable text", |
257 |
}, |
258 |
{ |
259 |
field_id: 4, |
260 |
id: "5", |
261 |
record_id: "1", |
262 |
value: "AF", |
263 |
}, |
264 |
], |
265 |
_strings: { |
266 |
additional_field_values: [ |
267 |
{ |
268 |
field_id: 1, |
269 |
field_label: "AV Repeatable", |
270 |
type: "av", |
271 |
value_str: "Reference, Non-fiction", |
272 |
}, |
273 |
{ |
274 |
field_id: 2, |
275 |
field_label: "Text non-repeatable", |
276 |
type: "text", |
277 |
value_str: "some text", |
278 |
}, |
279 |
{ |
280 |
field_id: 3, |
281 |
field_label: "Text repeatable", |
282 |
type: "text", |
283 |
value_str: "some repeatable text", |
284 |
}, |
285 |
{ |
286 |
field_id: 4, |
287 |
field_label: "AV Searchable", |
288 |
type: "av", |
289 |
value_str: "Afghanistan", |
290 |
}, |
291 |
], |
292 |
}, |
293 |
}; |
294 |
} |
295 |
|
296 |
function get_agreements_additional_fields() { |
297 |
return [ |
298 |
{ |
299 |
authorised_value_category_name: "CCODE", |
300 |
extended_attribute_type_id: 1, |
301 |
marcfield: "", |
302 |
marcfield_mode: "get", |
303 |
name: "AV Repeatable", |
304 |
repeatable: true, |
305 |
searchable: true, |
306 |
resource_type: "agreement", |
307 |
}, |
308 |
{ |
309 |
authorised_value_category_name: null, |
310 |
extended_attribute_type_id: 2, |
311 |
marcfield: "", |
312 |
marcfield_mode: "get", |
313 |
name: "Text non-repeatable", |
314 |
repeatable: false, |
315 |
searchable: false, |
316 |
resource_type: "agreement", |
317 |
}, |
318 |
{ |
319 |
authorised_value_category_name: null, |
320 |
extended_attribute_type_id: 3, |
321 |
marcfield: "", |
322 |
marcfield_mode: "get", |
323 |
name: "Text repeatable", |
324 |
repeatable: true, |
325 |
searchable: false, |
326 |
resource_type: "agreement", |
327 |
}, |
328 |
{ |
329 |
authorised_value_category_name: "COUNTRY", |
330 |
extended_attribute_type_id: 4, |
331 |
marcfield: "", |
332 |
marcfield_mode: "get", |
333 |
name: "AV Searchable", |
334 |
repeatable: false, |
335 |
searchable: true, |
336 |
resource_type: "agreement", |
337 |
}, |
338 |
]; |
339 |
} |
340 |
|
171 |
function get_av_cats() { |
341 |
function get_av_cats() { |
172 |
return [ |
342 |
return [ |
173 |
{ |
343 |
{ |
Lines 252-257
describe("Additional Fields operations", () => {
Link Here
|
252 |
); |
422 |
); |
253 |
}); |
423 |
}); |
254 |
|
424 |
|
|
|
425 |
// |
426 |
// for licenses |
427 |
// |
428 |
|
255 |
it("Additional Fields display - Table (licenses)", () => { |
429 |
it("Additional Fields display - Table (licenses)", () => { |
256 |
let license = get_license(); |
430 |
let license = get_license(); |
257 |
let licenses = [license]; |
431 |
let licenses = [license]; |
Lines 640-643
describe("Additional Fields operations", () => {
Link Here
|
640 |
"#licenses_add form #additional_fields label[for='additional_field_3']" |
814 |
"#licenses_add form #additional_fields label[for='additional_field_3']" |
641 |
).should("have.length", 2); |
815 |
).should("have.length", 2); |
642 |
}); |
816 |
}); |
|
|
817 |
|
818 |
// |
819 |
// for agreements |
820 |
// |
821 |
|
822 |
it("Additional Fields display - Table (agreements)", () => { |
823 |
let agreement = get_agreement(); |
824 |
let agreements = [agreement]; |
825 |
let agreement_additional_fields = get_agreements_additional_fields(); |
826 |
let av_cats = get_av_cats(); |
827 |
|
828 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
829 |
body: agreement_additional_fields, |
830 |
statusCode: 200, |
831 |
}); |
832 |
|
833 |
cy.intercept("GET", "/api/v1/erm/agreements*", { |
834 |
statusCode: 200, |
835 |
body: agreements, |
836 |
headers: { |
837 |
"X-Base-Total-Count": "1", |
838 |
"X-Total-Count": "1", |
839 |
}, |
840 |
}); |
841 |
cy.intercept("GET", "/api/v1/erm/agreements/*", agreement); |
842 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
843 |
cy.get("#agreements_list").contains("Showing 1 to 1 of 1 entries"); |
844 |
|
845 |
cy.get("#agreements_list table tbody tr:first").contains( |
846 |
get_description_from_av_value( |
847 |
av_cats, |
848 |
agreement.extended_attributes[4] |
849 |
) |
850 |
); |
851 |
cy.get("#agreements_list table tbody tr:first").contains( |
852 |
get_description_from_av_value( |
853 |
av_cats, |
854 |
agreement.extended_attributes[0] |
855 |
) + |
856 |
", " + |
857 |
get_description_from_av_value( |
858 |
av_cats, |
859 |
agreement.extended_attributes[1] |
860 |
) |
861 |
); |
862 |
}); |
863 |
|
864 |
it("Additional Fields display - Show (agreements)", () => { |
865 |
let empty_agreement = get_no_additional_fields_agreement(); |
866 |
let agreement = get_agreement(); |
867 |
let agreements = [agreement]; |
868 |
let vendors = cy.get_vendors_to_relate(); |
869 |
let agreement_additional_fields = get_agreements_additional_fields(); |
870 |
let av_cats = get_av_cats(); |
871 |
|
872 |
// Click the 'Edit' button from the list |
873 |
cy.intercept("GET", "/api/v1/erm/agreements*", { |
874 |
statusCode: 200, |
875 |
body: agreements, |
876 |
headers: { |
877 |
"X-Base-Total-Count": "1", |
878 |
"X-Total-Count": "1", |
879 |
}, |
880 |
}); |
881 |
cy.intercept("GET", "/api/v1/erm/agreements/*", empty_agreement).as( |
882 |
"get-empty-agreement" |
883 |
); |
884 |
|
885 |
//Intercept vendors request |
886 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
887 |
statusCode: 200, |
888 |
body: vendors, |
889 |
}); |
890 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
891 |
body: [], |
892 |
statusCode: 200, |
893 |
}).as("empty-additional-fields"); |
894 |
|
895 |
//Empty additional fields, should not display |
896 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
897 |
cy.get("#agreements_list table tbody tr:first td:first a").click(); |
898 |
cy.wait("@get-empty-agreement"); |
899 |
cy.get("#agreements_show #additional_fields").should("not.exist"); |
900 |
|
901 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
902 |
body: agreement_additional_fields, |
903 |
statusCode: 200, |
904 |
}).as("existing-additional-fields"); |
905 |
|
906 |
cy.intercept( |
907 |
{ |
908 |
pathname: "/api/v1/authorised_value_categories", |
909 |
query: { |
910 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
911 |
}, |
912 |
}, |
913 |
{ |
914 |
body: av_cats, |
915 |
statusCode: 200, |
916 |
} |
917 |
).as("avcategories"); |
918 |
|
919 |
cy.intercept("GET", "/api/v1/erm/agreements/*", agreement).as( |
920 |
"get-agreement" |
921 |
); |
922 |
|
923 |
// There are additional fields, fieldset should exist |
924 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
925 |
cy.get("#agreements_list table tbody tr:first td:first a").click(); |
926 |
cy.wait("@get-agreement"); |
927 |
cy.get("#agreements_show #additional_fields").should("exist"); |
928 |
|
929 |
// All fields are presented correctly |
930 |
cy.get( |
931 |
"#agreements_show #additional_fields label[for='additional_field_1']" |
932 |
).contains(agreement_additional_fields[0].name); |
933 |
cy.get( |
934 |
"#agreements_show #additional_fields label[for='additional_field_1']" |
935 |
) |
936 |
.parent() |
937 |
.children("span") |
938 |
.contains( |
939 |
get_description_from_av_value( |
940 |
av_cats, |
941 |
agreement.extended_attributes[0] |
942 |
) + |
943 |
", " + |
944 |
get_description_from_av_value( |
945 |
av_cats, |
946 |
agreement.extended_attributes[1] |
947 |
) |
948 |
); |
949 |
|
950 |
cy.get( |
951 |
"#agreements_show #additional_fields label[for='additional_field_2']" |
952 |
).contains(agreement_additional_fields[1].name); |
953 |
cy.get( |
954 |
"#agreements_show #additional_fields label[for='additional_field_2']" |
955 |
) |
956 |
.parent() |
957 |
.children("span") |
958 |
.contains(agreement.extended_attributes[2].value); |
959 |
|
960 |
cy.get( |
961 |
"#agreements_show #additional_fields label[for='additional_field_3']" |
962 |
).contains(agreement_additional_fields[2].name); |
963 |
cy.get( |
964 |
"#agreements_show #additional_fields label[for='additional_field_3']" |
965 |
) |
966 |
.parent() |
967 |
.children("span") |
968 |
.contains(agreement.extended_attributes[3].value); |
969 |
|
970 |
cy.get( |
971 |
"#agreements_show #additional_fields label[for='additional_field_4']" |
972 |
).contains(agreement_additional_fields[3].name); |
973 |
cy.get( |
974 |
"#agreements_show #additional_fields label[for='additional_field_4']" |
975 |
) |
976 |
.parent() |
977 |
.children("span") |
978 |
.contains( |
979 |
get_description_from_av_value( |
980 |
av_cats, |
981 |
agreement.extended_attributes[4] |
982 |
) |
983 |
); |
984 |
}); |
985 |
|
986 |
it("Additional Fields entry - Add (agreements)", () => { |
987 |
let vendors = cy.get_vendors_to_relate(); |
988 |
let agreement_additional_fields = get_licenses_additional_fields(); |
989 |
let av_cats = get_av_cats(); |
990 |
|
991 |
//Intercept vendors request |
992 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
993 |
statusCode: 200, |
994 |
body: vendors, |
995 |
}); |
996 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
997 |
body: [], |
998 |
statusCode: 200, |
999 |
}).as("empty-additional-fields"); |
1000 |
|
1001 |
// No additional fields, fieldset should not exist |
1002 |
cy.visit("/cgi-bin/koha/erm/agreements/add"); |
1003 |
cy.get("#agreements_add form #additional_fields").should("not.exist"); |
1004 |
|
1005 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1006 |
body: agreement_additional_fields, |
1007 |
statusCode: 200, |
1008 |
}).as("existing-additional-fields"); |
1009 |
|
1010 |
cy.intercept( |
1011 |
{ |
1012 |
pathname: "/api/v1/authorised_value_categories", |
1013 |
query: { |
1014 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1015 |
}, |
1016 |
}, |
1017 |
{ |
1018 |
body: av_cats, |
1019 |
statusCode: 200, |
1020 |
} |
1021 |
).as("avcategories"); |
1022 |
// There are additional fields, fieldset should exist |
1023 |
cy.visit("/cgi-bin/koha/erm/agreements/add"); |
1024 |
cy.get("#agreements_add form #additional_fields").should("exist"); |
1025 |
|
1026 |
// All additional fields should be listed |
1027 |
cy.get( |
1028 |
"#agreements_add form #additional_fields label[for='additional_field_1']" |
1029 |
).contains(agreement_additional_fields[0].name); |
1030 |
cy.get( |
1031 |
"#agreements_add form #additional_fields label[for='additional_field_2']" |
1032 |
).contains(agreement_additional_fields[1].name); |
1033 |
cy.get( |
1034 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1035 |
).contains(agreement_additional_fields[2].name); |
1036 |
cy.get( |
1037 |
"#agreements_add form #additional_fields label[for='additional_field_4']" |
1038 |
).contains(agreement_additional_fields[3].name); |
1039 |
|
1040 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1041 |
"not.exist" |
1042 |
); //new agreement, no pre-selected value |
1043 |
|
1044 |
// Pick one value |
1045 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1046 |
cy.get( |
1047 |
"#additional_fields #additional_field_1 #vs5__option-0" |
1048 |
).contains(av_cats[0].authorised_values[0].description); |
1049 |
cy.get("#additional_fields #additional_field_1 #vs5__option-0").click(); |
1050 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1051 |
av_cats[0].authorised_values[0].description |
1052 |
); |
1053 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1054 |
"have.length", |
1055 |
1 |
1056 |
); |
1057 |
|
1058 |
// Pick a second value for the same repeatable AV field |
1059 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1060 |
cy.get( |
1061 |
"#additional_fields #additional_field_1 #vs5__option-1" |
1062 |
).contains(av_cats[0].authorised_values[1].description); |
1063 |
cy.get("#additional_fields #additional_field_1 #vs5__option-1").click(); |
1064 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1065 |
av_cats[0].authorised_values[1].description |
1066 |
); |
1067 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1068 |
"have.length", |
1069 |
2 |
1070 |
); |
1071 |
|
1072 |
// Attempt to pick the same value again - should not be possible |
1073 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
1074 |
cy.get( |
1075 |
"#additional_fields #additional_field_1 #vs5__option-1" |
1076 |
).contains(av_cats[0].authorised_values[1].description); |
1077 |
cy.get("#additional_fields #additional_field_1 #vs5__option-1").click(); |
1078 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1079 |
"have.length", |
1080 |
2 |
1081 |
); |
1082 |
|
1083 |
// Remove the second selected value |
1084 |
cy.get( |
1085 |
"#additional_fields #additional_field_1 .vs__selected button[title='Deselect " + |
1086 |
av_cats[0].authorised_values[1].description + |
1087 |
"'" |
1088 |
).click(); |
1089 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1090 |
"have.length", |
1091 |
1 |
1092 |
); |
1093 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1094 |
av_cats[0].authorised_values[0].description |
1095 |
); |
1096 |
}); |
1097 |
|
1098 |
it("Additional Fields entry - Edit (agreements)", () => { |
1099 |
let agreement = get_agreement(); |
1100 |
let agreements = [agreement]; |
1101 |
let vendors = cy.get_vendors_to_relate(); |
1102 |
let agreement_additional_fields = get_agreements_additional_fields(); |
1103 |
let av_cats = get_av_cats(); |
1104 |
|
1105 |
// Click the 'Edit' button from the list |
1106 |
cy.intercept("GET", "/api/v1/erm/agreements*", { |
1107 |
statusCode: 200, |
1108 |
body: agreements, |
1109 |
headers: { |
1110 |
"X-Base-Total-Count": "1", |
1111 |
"X-Total-Count": "1", |
1112 |
}, |
1113 |
}); |
1114 |
cy.intercept("GET", "/api/v1/erm/agreements/*", agreement).as( |
1115 |
"get-agreement" |
1116 |
); |
1117 |
|
1118 |
//Intercept vendors request |
1119 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1120 |
statusCode: 200, |
1121 |
body: vendors, |
1122 |
}); |
1123 |
|
1124 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1125 |
body: agreement_additional_fields, |
1126 |
statusCode: 200, |
1127 |
}).as("existing-additional-fields"); |
1128 |
|
1129 |
cy.intercept( |
1130 |
{ |
1131 |
pathname: "/api/v1/authorised_value_categories", |
1132 |
query: { |
1133 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1134 |
}, |
1135 |
}, |
1136 |
{ |
1137 |
body: av_cats, |
1138 |
statusCode: 200, |
1139 |
} |
1140 |
).as("avcategories"); |
1141 |
|
1142 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
1143 |
cy.get("#agreements_list table tbody tr:first").contains("Edit").click(); |
1144 |
cy.wait("@get-agreement"); |
1145 |
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! |
1146 |
|
1147 |
// All additional fields should be pre-populated |
1148 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1149 |
get_description_from_av_value( |
1150 |
av_cats, |
1151 |
agreement.extended_attributes[0] |
1152 |
) |
1153 |
); |
1154 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1155 |
get_description_from_av_value( |
1156 |
av_cats, |
1157 |
agreement.extended_attributes[1] |
1158 |
) |
1159 |
); |
1160 |
|
1161 |
cy.get( |
1162 |
"#agreements_add form #additional_fields label[for='additional_field_2']" |
1163 |
) |
1164 |
.parent() |
1165 |
.children("input") |
1166 |
.should("have.value", agreement.extended_attributes[2].value); |
1167 |
|
1168 |
cy.get( |
1169 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1170 |
) |
1171 |
.parent() |
1172 |
.children("input") |
1173 |
.should("have.value", agreement.extended_attributes[3].value); |
1174 |
|
1175 |
cy.get("#additional_fields #additional_field_4 .vs__selected").contains( |
1176 |
get_description_from_av_value( |
1177 |
av_cats, |
1178 |
agreement.extended_attributes[4] |
1179 |
) |
1180 |
); |
1181 |
|
1182 |
// Clear text field works |
1183 |
cy.get( |
1184 |
"#agreements_add form #additional_fields label[for='additional_field_2']" |
1185 |
) |
1186 |
.parent() |
1187 |
.children(".clear_attribute") |
1188 |
.click(); |
1189 |
cy.get( |
1190 |
"#agreements_add form #additional_fields label[for='additional_field_2']" |
1191 |
) |
1192 |
.parent() |
1193 |
.children("input") |
1194 |
.should("have.value", ""); |
1195 |
|
1196 |
// "+New" text field works |
1197 |
cy.get( |
1198 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1199 |
).should("have.length", 1); |
1200 |
cy.get( |
1201 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1202 |
) |
1203 |
.parent() |
1204 |
.children(".clone_attribute") |
1205 |
.click(); |
1206 |
cy.get( |
1207 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1208 |
).should("have.length", 2); |
1209 |
}); |
1210 |
|
643 |
}); |
1211 |
}); |
644 |
- |
|
|