Lines 83-88
function get_licenses_additional_fields() {
Link Here
|
83 |
]; |
83 |
]; |
84 |
} |
84 |
} |
85 |
|
85 |
|
|
|
86 |
function get_no_additional_fields_agreement() { |
87 |
return { |
88 |
agreement_id: 1, |
89 |
name: "agreement 1", |
90 |
description: "my first agreement", |
91 |
agreement_licenses: [], |
92 |
agreement_packages: [], |
93 |
agreement_relationships: [], |
94 |
closure_reason: "", |
95 |
is_perpetual: false, |
96 |
license_info: "", |
97 |
periods: [], |
98 |
renewal_priority: "", |
99 |
status: "active", |
100 |
user_roles: [], |
101 |
vendor_id: 1, |
102 |
vendor: [cy.get_vendors_to_relate()[0]], |
103 |
documents: [ |
104 |
{ |
105 |
agreement_id: 1, |
106 |
file_description: "file description", |
107 |
file_name: "file.json", |
108 |
notes: "file notes", |
109 |
physical_location: "file physical location", |
110 |
uri: "file uri", |
111 |
uploaded_on: "2022-10-27T11:57:02+00:00", |
112 |
}, |
113 |
], |
114 |
extended_attributes: [], |
115 |
_strings: { |
116 |
"additional_field_values": [] |
117 |
}, |
118 |
}; |
119 |
} |
120 |
function get_agreement() { |
121 |
return { |
122 |
agreement_id: 1, |
123 |
name: "agreement 1", |
124 |
description: "my first agreement", |
125 |
agreement_licenses: [], |
126 |
agreement_packages: [], |
127 |
agreement_relationships: [], |
128 |
closure_reason: "", |
129 |
is_perpetual: false, |
130 |
license_info: "", |
131 |
periods: [], |
132 |
renewal_priority: "", |
133 |
status: "active", |
134 |
user_roles: [], |
135 |
vendor_id: 1, |
136 |
vendor: [cy.get_vendors_to_relate()[0]], |
137 |
documents: [ |
138 |
{ |
139 |
agreement_id: 1, |
140 |
file_description: "file description", |
141 |
file_name: "file.json", |
142 |
notes: "file notes", |
143 |
physical_location: "file physical location", |
144 |
uri: "file uri", |
145 |
uploaded_on: "2022-10-27T11:57:02+00:00", |
146 |
}, |
147 |
], |
148 |
extended_attributes: [ |
149 |
{ |
150 |
field_id: 1, |
151 |
id: "1", |
152 |
record_id: "1", |
153 |
value: "REF", |
154 |
}, |
155 |
{ |
156 |
field_id: 1, |
157 |
id: "2", |
158 |
record_id: "1", |
159 |
value: "NFIC", |
160 |
}, |
161 |
{ |
162 |
field_id: 2, |
163 |
id: "3", |
164 |
record_id: "1", |
165 |
value: "some text", |
166 |
}, |
167 |
{ |
168 |
field_id: 3, |
169 |
id: "4", |
170 |
record_id: "1", |
171 |
value: "some repeatable text", |
172 |
}, |
173 |
{ |
174 |
field_id: 4, |
175 |
id: "5", |
176 |
record_id: "1", |
177 |
value: "AF", |
178 |
}, |
179 |
], |
180 |
_strings: { |
181 |
additional_field_values: [ |
182 |
{ |
183 |
field_id: 1, |
184 |
field_label: "AV Repeatable", |
185 |
type: "av", |
186 |
value_str: "Reference, Non-fiction", |
187 |
}, |
188 |
{ |
189 |
field_id: 2, |
190 |
field_label: "Text non-repeatable", |
191 |
type: "text", |
192 |
value_str: "some text", |
193 |
}, |
194 |
{ |
195 |
field_id: 3, |
196 |
field_label: "Text repeatable", |
197 |
type: "text", |
198 |
value_str: "some repeatable text", |
199 |
}, |
200 |
{ |
201 |
field_id: 4, |
202 |
field_label: "AV Searchable", |
203 |
type: "av", |
204 |
value_str: "Afghanistan", |
205 |
}, |
206 |
], |
207 |
}, |
208 |
}; |
209 |
} |
210 |
|
211 |
function get_agreements_additional_fields() { |
212 |
return [ |
213 |
{ |
214 |
authorised_value_category_name: "CCODE", |
215 |
extended_attribute_type_id: 1, |
216 |
marcfield: "", |
217 |
marcfield_mode: "get", |
218 |
name: "AV Repeatable", |
219 |
repeatable: true, |
220 |
searchable: true, |
221 |
resource_type: "agreement", |
222 |
}, |
223 |
{ |
224 |
authorised_value_category_name: null, |
225 |
extended_attribute_type_id: 2, |
226 |
marcfield: "", |
227 |
marcfield_mode: "get", |
228 |
name: "Text non-repeatable", |
229 |
repeatable: false, |
230 |
searchable: false, |
231 |
resource_type: "agreement", |
232 |
}, |
233 |
{ |
234 |
authorised_value_category_name: null, |
235 |
extended_attribute_type_id: 3, |
236 |
marcfield: "", |
237 |
marcfield_mode: "get", |
238 |
name: "Text repeatable", |
239 |
repeatable: true, |
240 |
searchable: false, |
241 |
resource_type: "agreement", |
242 |
}, |
243 |
{ |
244 |
authorised_value_category_name: "COUNTRY", |
245 |
extended_attribute_type_id: 4, |
246 |
marcfield: "", |
247 |
marcfield_mode: "get", |
248 |
name: "AV Searchable", |
249 |
repeatable: false, |
250 |
searchable: true, |
251 |
resource_type: "agreement", |
252 |
}, |
253 |
]; |
254 |
} |
255 |
|
86 |
function get_av_cats() { |
256 |
function get_av_cats() { |
87 |
return [ |
257 |
return [ |
88 |
{ |
258 |
{ |
Lines 167-172
describe("Additional Fields operations", () => {
Link Here
|
167 |
); |
337 |
); |
168 |
}); |
338 |
}); |
169 |
|
339 |
|
|
|
340 |
// |
341 |
// for licenses |
342 |
// |
343 |
|
170 |
it("Additional Fields display - Table (licenses)", () => { |
344 |
it("Additional Fields display - Table (licenses)", () => { |
171 |
let license = cy.get_license(); |
345 |
let license = cy.get_license(); |
172 |
let licenses = [license]; |
346 |
let licenses = [license]; |
Lines 555-558
describe("Additional Fields operations", () => {
Link Here
|
555 |
"#licenses_add form #additional_fields label[for='additional_field_3']" |
729 |
"#licenses_add form #additional_fields label[for='additional_field_3']" |
556 |
).should("have.length", 2); |
730 |
).should("have.length", 2); |
557 |
}); |
731 |
}); |
|
|
732 |
|
733 |
// |
734 |
// for agreements |
735 |
// |
736 |
|
737 |
it("Additional Fields display - Table (agreements)", () => { |
738 |
let agreement = get_agreement(); |
739 |
let agreements = [agreement]; |
740 |
let agreement_additional_fields = get_agreements_additional_fields(); |
741 |
let av_cats = get_av_cats(); |
742 |
|
743 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
744 |
body: agreement_additional_fields, |
745 |
statusCode: 200, |
746 |
}); |
747 |
|
748 |
cy.intercept("GET", "/api/v1/erm/agreements*", { |
749 |
statusCode: 200, |
750 |
body: agreements, |
751 |
headers: { |
752 |
"X-Base-Total-Count": "1", |
753 |
"X-Total-Count": "1", |
754 |
}, |
755 |
}); |
756 |
cy.intercept("GET", "/api/v1/erm/agreements/*", agreement); |
757 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
758 |
cy.get("#agreements_list").contains("Showing 1 to 1 of 1 entries"); |
759 |
|
760 |
cy.get("#agreements_list table tbody tr:first").contains( |
761 |
get_description_from_av_value( |
762 |
av_cats, |
763 |
agreement.extended_attributes[4] |
764 |
) |
765 |
); |
766 |
cy.get("#agreements_list table tbody tr:first").contains( |
767 |
get_description_from_av_value( |
768 |
av_cats, |
769 |
agreement.extended_attributes[0] |
770 |
) + |
771 |
", " + |
772 |
get_description_from_av_value( |
773 |
av_cats, |
774 |
agreement.extended_attributes[1] |
775 |
) |
776 |
); |
777 |
}); |
778 |
|
779 |
it("Additional Fields display - Show (agreements)", () => { |
780 |
let empty_agreement = get_no_additional_fields_agreement(); |
781 |
let agreement = get_agreement(); |
782 |
let agreements = [agreement]; |
783 |
let vendors = cy.get_vendors_to_relate(); |
784 |
let agreement_additional_fields = get_agreements_additional_fields(); |
785 |
let av_cats = get_av_cats(); |
786 |
|
787 |
// Click the 'Edit' button from the list |
788 |
cy.intercept("GET", "/api/v1/erm/agreements*", { |
789 |
statusCode: 200, |
790 |
body: agreements, |
791 |
headers: { |
792 |
"X-Base-Total-Count": "1", |
793 |
"X-Total-Count": "1", |
794 |
}, |
795 |
}); |
796 |
cy.intercept("GET", "/api/v1/erm/agreements/*", empty_agreement).as( |
797 |
"get-empty-agreement" |
798 |
); |
799 |
|
800 |
//Intercept vendors request |
801 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
802 |
statusCode: 200, |
803 |
body: vendors, |
804 |
}); |
805 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
806 |
body: [], |
807 |
statusCode: 200, |
808 |
}).as("empty-additional-fields"); |
809 |
|
810 |
//Empty additional fields, should not display |
811 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
812 |
cy.get("#agreements_list table tbody tr:first td:first a").click(); |
813 |
cy.wait("@get-empty-agreement"); |
814 |
cy.get("#agreements_show #additional_fields").should("not.exist"); |
815 |
|
816 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
817 |
body: agreement_additional_fields, |
818 |
statusCode: 200, |
819 |
}).as("existing-additional-fields"); |
820 |
|
821 |
cy.intercept( |
822 |
{ |
823 |
pathname: "/api/v1/authorised_value_categories", |
824 |
query: { |
825 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
826 |
}, |
827 |
}, |
828 |
{ |
829 |
body: av_cats, |
830 |
statusCode: 200, |
831 |
} |
832 |
).as("avcategories"); |
833 |
|
834 |
cy.intercept("GET", "/api/v1/erm/agreements/*", agreement).as( |
835 |
"get-agreement" |
836 |
); |
837 |
|
838 |
// There are additional fields, fieldset should exist |
839 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
840 |
cy.get("#agreements_list table tbody tr:first td:first a").click(); |
841 |
cy.wait("@get-agreement"); |
842 |
cy.get("#agreements_show #additional_fields").should("exist"); |
843 |
|
844 |
// All fields are presented correctly |
845 |
cy.get( |
846 |
"#agreements_show #additional_fields label[for='additional_field_1']" |
847 |
).contains(agreement_additional_fields[0].name); |
848 |
cy.get( |
849 |
"#agreements_show #additional_fields label[for='additional_field_1']" |
850 |
) |
851 |
.parent() |
852 |
.children("span") |
853 |
.contains( |
854 |
get_description_from_av_value( |
855 |
av_cats, |
856 |
agreement.extended_attributes[0] |
857 |
) + |
858 |
", " + |
859 |
get_description_from_av_value( |
860 |
av_cats, |
861 |
agreement.extended_attributes[1] |
862 |
) |
863 |
); |
864 |
|
865 |
cy.get( |
866 |
"#agreements_show #additional_fields label[for='additional_field_2']" |
867 |
).contains(agreement_additional_fields[1].name); |
868 |
cy.get( |
869 |
"#agreements_show #additional_fields label[for='additional_field_2']" |
870 |
) |
871 |
.parent() |
872 |
.children("span") |
873 |
.contains(agreement.extended_attributes[2].value); |
874 |
|
875 |
cy.get( |
876 |
"#agreements_show #additional_fields label[for='additional_field_3']" |
877 |
).contains(agreement_additional_fields[2].name); |
878 |
cy.get( |
879 |
"#agreements_show #additional_fields label[for='additional_field_3']" |
880 |
) |
881 |
.parent() |
882 |
.children("span") |
883 |
.contains(agreement.extended_attributes[3].value); |
884 |
|
885 |
cy.get( |
886 |
"#agreements_show #additional_fields label[for='additional_field_4']" |
887 |
).contains(agreement_additional_fields[3].name); |
888 |
cy.get( |
889 |
"#agreements_show #additional_fields label[for='additional_field_4']" |
890 |
) |
891 |
.parent() |
892 |
.children("span") |
893 |
.contains( |
894 |
get_description_from_av_value( |
895 |
av_cats, |
896 |
agreement.extended_attributes[4] |
897 |
) |
898 |
); |
899 |
}); |
900 |
|
901 |
it("Additional Fields entry - Add (agreements)", () => { |
902 |
let vendors = cy.get_vendors_to_relate(); |
903 |
let agreement_additional_fields = get_licenses_additional_fields(); |
904 |
let av_cats = get_av_cats(); |
905 |
|
906 |
//Intercept vendors request |
907 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
908 |
statusCode: 200, |
909 |
body: vendors, |
910 |
}); |
911 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
912 |
body: [], |
913 |
statusCode: 200, |
914 |
}).as("empty-additional-fields"); |
915 |
|
916 |
// No additional fields, fieldset should not exist |
917 |
cy.visit("/cgi-bin/koha/erm/agreements/add"); |
918 |
cy.get("#agreements_add form #additional_fields").should("not.exist"); |
919 |
|
920 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
921 |
body: agreement_additional_fields, |
922 |
statusCode: 200, |
923 |
}).as("existing-additional-fields"); |
924 |
|
925 |
cy.intercept( |
926 |
{ |
927 |
pathname: "/api/v1/authorised_value_categories", |
928 |
query: { |
929 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
930 |
}, |
931 |
}, |
932 |
{ |
933 |
body: av_cats, |
934 |
statusCode: 200, |
935 |
} |
936 |
).as("avcategories"); |
937 |
// There are additional fields, fieldset should exist |
938 |
cy.visit("/cgi-bin/koha/erm/agreements/add"); |
939 |
cy.get("#agreements_add form #additional_fields").should("exist"); |
940 |
|
941 |
// All additional fields should be listed |
942 |
cy.get( |
943 |
"#agreements_add form #additional_fields label[for='additional_field_1']" |
944 |
).contains(agreement_additional_fields[0].name); |
945 |
cy.get( |
946 |
"#agreements_add form #additional_fields label[for='additional_field_2']" |
947 |
).contains(agreement_additional_fields[1].name); |
948 |
cy.get( |
949 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
950 |
).contains(agreement_additional_fields[2].name); |
951 |
cy.get( |
952 |
"#agreements_add form #additional_fields label[for='additional_field_4']" |
953 |
).contains(agreement_additional_fields[3].name); |
954 |
|
955 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
956 |
"not.exist" |
957 |
); //new agreement, no pre-selected value |
958 |
|
959 |
// Pick one value |
960 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
961 |
cy.get( |
962 |
"#additional_fields #additional_field_1 #vs5__option-0" |
963 |
).contains(av_cats[0].authorised_values[0].description); |
964 |
cy.get("#additional_fields #additional_field_1 #vs5__option-0").click(); |
965 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
966 |
av_cats[0].authorised_values[0].description |
967 |
); |
968 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
969 |
"have.length", |
970 |
1 |
971 |
); |
972 |
|
973 |
// Pick a second value for the same repeatable AV field |
974 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
975 |
cy.get( |
976 |
"#additional_fields #additional_field_1 #vs5__option-1" |
977 |
).contains(av_cats[0].authorised_values[1].description); |
978 |
cy.get("#additional_fields #additional_field_1 #vs5__option-1").click(); |
979 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
980 |
av_cats[0].authorised_values[1].description |
981 |
); |
982 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
983 |
"have.length", |
984 |
2 |
985 |
); |
986 |
|
987 |
// Attempt to pick the same value again - should not be possible |
988 |
cy.get("#additional_fields #additional_field_1 .vs__search").click(); |
989 |
cy.get( |
990 |
"#additional_fields #additional_field_1 #vs5__option-1" |
991 |
).contains(av_cats[0].authorised_values[1].description); |
992 |
cy.get("#additional_fields #additional_field_1 #vs5__option-1").click(); |
993 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
994 |
"have.length", |
995 |
2 |
996 |
); |
997 |
|
998 |
// Remove the second selected value |
999 |
cy.get( |
1000 |
"#additional_fields #additional_field_1 .vs__selected button[title='Deselect " + |
1001 |
av_cats[0].authorised_values[1].description + |
1002 |
"'" |
1003 |
).click(); |
1004 |
cy.get("#additional_fields #additional_field_1 .vs__selected").should( |
1005 |
"have.length", |
1006 |
1 |
1007 |
); |
1008 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1009 |
av_cats[0].authorised_values[0].description |
1010 |
); |
1011 |
}); |
1012 |
|
1013 |
it("Additional Fields entry - Edit (agreements)", () => { |
1014 |
let agreement = get_agreement(); |
1015 |
let agreements = [agreement]; |
1016 |
let vendors = cy.get_vendors_to_relate(); |
1017 |
let agreement_additional_fields = get_agreements_additional_fields(); |
1018 |
let av_cats = get_av_cats(); |
1019 |
|
1020 |
// Click the 'Edit' button from the list |
1021 |
cy.intercept("GET", "/api/v1/erm/agreements*", { |
1022 |
statusCode: 200, |
1023 |
body: agreements, |
1024 |
headers: { |
1025 |
"X-Base-Total-Count": "1", |
1026 |
"X-Total-Count": "1", |
1027 |
}, |
1028 |
}); |
1029 |
cy.intercept("GET", "/api/v1/erm/agreements/*", agreement).as( |
1030 |
"get-agreement" |
1031 |
); |
1032 |
|
1033 |
//Intercept vendors request |
1034 |
cy.intercept("GET", "/api/v1/acquisitions/vendors*", { |
1035 |
statusCode: 200, |
1036 |
body: vendors, |
1037 |
}); |
1038 |
|
1039 |
cy.intercept("GET", "/api/v1/extended_attribute_types*", { |
1040 |
body: agreement_additional_fields, |
1041 |
statusCode: 200, |
1042 |
}).as("existing-additional-fields"); |
1043 |
|
1044 |
cy.intercept( |
1045 |
{ |
1046 |
pathname: "/api/v1/authorised_value_categories", |
1047 |
query: { |
1048 |
q: '{"me.category_name":["CCODE", "COUNTRY"]}', |
1049 |
}, |
1050 |
}, |
1051 |
{ |
1052 |
body: av_cats, |
1053 |
statusCode: 200, |
1054 |
} |
1055 |
).as("avcategories"); |
1056 |
|
1057 |
cy.visit("/cgi-bin/koha/erm/agreements"); |
1058 |
cy.get("#agreements_list table tbody tr:first").contains("Edit").click(); |
1059 |
cy.wait("@get-agreement"); |
1060 |
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! |
1061 |
|
1062 |
// All additional fields should be pre-populated |
1063 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1064 |
get_description_from_av_value( |
1065 |
av_cats, |
1066 |
agreement.extended_attributes[0] |
1067 |
) |
1068 |
); |
1069 |
cy.get("#additional_fields #additional_field_1 .vs__selected").contains( |
1070 |
get_description_from_av_value( |
1071 |
av_cats, |
1072 |
agreement.extended_attributes[1] |
1073 |
) |
1074 |
); |
1075 |
|
1076 |
cy.get( |
1077 |
"#agreements_add form #additional_fields label[for='additional_field_2']" |
1078 |
) |
1079 |
.parent() |
1080 |
.children("input") |
1081 |
.should("have.value", agreement.extended_attributes[2].value); |
1082 |
|
1083 |
cy.get( |
1084 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1085 |
) |
1086 |
.parent() |
1087 |
.children("input") |
1088 |
.should("have.value", agreement.extended_attributes[3].value); |
1089 |
|
1090 |
cy.get("#additional_fields #additional_field_4 .vs__selected").contains( |
1091 |
get_description_from_av_value( |
1092 |
av_cats, |
1093 |
agreement.extended_attributes[4] |
1094 |
) |
1095 |
); |
1096 |
|
1097 |
// Clear text field works |
1098 |
cy.get( |
1099 |
"#agreements_add form #additional_fields label[for='additional_field_2']" |
1100 |
) |
1101 |
.parent() |
1102 |
.children(".clear_attribute") |
1103 |
.click(); |
1104 |
cy.get( |
1105 |
"#agreements_add form #additional_fields label[for='additional_field_2']" |
1106 |
) |
1107 |
.parent() |
1108 |
.children("input") |
1109 |
.should("have.value", ""); |
1110 |
|
1111 |
// "+New" text field works |
1112 |
cy.get( |
1113 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1114 |
).should("have.length", 1); |
1115 |
cy.get( |
1116 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1117 |
) |
1118 |
.parent() |
1119 |
.children(".clone_attribute") |
1120 |
.click(); |
1121 |
cy.get( |
1122 |
"#agreements_add form #additional_fields label[for='additional_field_3']" |
1123 |
).should("have.length", 2); |
1124 |
}); |
1125 |
|
558 |
}); |
1126 |
}); |
559 |
- |
|
|