@@ -16,7 +16,7 @@ it("a mixture of otherSearchTerms and special parts", () => {
1616 ] ) ;
1717 expect ( otherSearchTerms ) . toEqual ( "dogs cats" ) ;
1818 expect ( specialParts . length ) . toBe ( 1 ) ;
19- expect ( specialParts [ 0 ] ) . toBe ( "topic:Animals" ) ;
19+ expect ( specialParts . includes ( "topic:Animals" ) ) ;
2020} ) ;
2121
2222it ( "topic at start" , ( ) => {
@@ -30,7 +30,7 @@ it("topic at start", () => {
3030 ] ) ;
3131 expect ( otherSearchTerms ) . toEqual ( "dogs cats" ) ;
3232 expect ( specialParts . length ) . toBe ( 1 ) ;
33- expect ( specialParts [ 0 ] ) . toBe ( "topic:Animals" ) ;
33+ expect ( specialParts . includes ( "topic:Animals" ) ) ;
3434} ) ;
3535
3636it ( "topic at end" , ( ) => {
@@ -44,7 +44,7 @@ it("topic at end", () => {
4444 ] ) ;
4545 expect ( otherSearchTerms ) . toEqual ( "dogs cats" ) ;
4646 expect ( specialParts . length ) . toBe ( 1 ) ;
47- expect ( specialParts [ 0 ] ) . toBe ( "topic:Animals" ) ;
47+ expect ( specialParts . includes ( "topic:Animals" ) ) ;
4848} ) ;
4949
5050it ( "topic and bookshelf name and otherSearchTerms in quotes" , ( ) => {
@@ -61,8 +61,8 @@ it("topic and bookshelf name and otherSearchTerms in quotes", () => {
6161 ) ;
6262 expect ( otherSearchTerms ) . toEqual ( 'dogs "black birds"' ) ;
6363 expect ( specialParts . length ) . toBe ( 2 ) ;
64- expect ( specialParts [ 0 ] ) . toBe ( "topic:Animal stories" ) ;
65- expect ( specialParts [ 1 ] ) . toBe ( "bookshelf:enabling writers workshop" ) ;
64+ expect ( specialParts . includes ( "topic:Animal stories" ) ) ;
65+ expect ( specialParts . includes ( "bookshelf:enabling writers workshop" ) ) ;
6666} ) ;
6767
6868it ( "ignores various unhelpful spaces" , ( ) => {
@@ -75,10 +75,8 @@ it("ignores various unhelpful spaces", () => {
7575 ) ;
7676 expect ( otherSearchTerms ) . toEqual ( 'dogs "black birds"' ) ;
7777 expect ( specialParts . length ) . toBe ( 2 ) ;
78- // Note that the order in which the parts are extracted depends on their order
79- // in the topic list, not in the input string.
80- expect ( specialParts [ 0 ] ) . toBe ( "topic:Math" ) ;
81- expect ( specialParts [ 1 ] ) . toBe ( "bookshelf:enabling writers workshop" ) ;
78+ expect ( specialParts . includes ( "topic:Math" ) ) ;
79+ expect ( specialParts . includes ( "bookshelf:enabling writers workshop" ) ) ;
8280} ) ;
8381
8482it ( "finds uploader and copyright" , ( ) => {
@@ -92,10 +90,8 @@ it("finds uploader and copyright", () => {
9290 ] ) ;
9391 expect ( otherSearchTerms ) . toEqual ( "dogs" ) ;
9492 expect ( specialParts . length ) . toBe ( 2 ) ;
95- // Note that the order in which the parts are extracted depends on their order
96- // in the topic list, not in the input string.
97- expect ( specialParts [ 0 ] ) . toBe ( "uploader:fred@example" ) ;
98- expect ( specialParts [ 1 ] ) . toBe ( "copyright:sil.org" ) ;
93+ expect ( specialParts . includes ( "uploader:fred@example" ) ) ;
94+ expect ( specialParts . includes ( "copyright:sil.org" ) ) ;
9995} ) ;
10096
10197it ( "corrects case, but not if both cases are valid" , ( ) => {
@@ -111,7 +107,110 @@ it("corrects case, but not if both cases are valid", () => {
111107 ] ) ;
112108 expect ( otherSearchTerms ) . toEqual ( "cats" ) ;
113109 expect ( specialParts . length ) . toBe ( 3 ) ;
114- expect ( specialParts [ 0 ] ) . toBe ( "topic:Health" ) ;
115- expect ( specialParts [ 1 ] ) . toBe ( "topic:math" ) ;
116- expect ( specialParts [ 2 ] ) . toBe ( "topic:Math" ) ;
110+ expect ( specialParts . includes ( "topic:Health" ) ) ;
111+ expect ( specialParts . includes ( "topic:math" ) ) ;
112+ expect ( specialParts . includes ( "topic:Math" ) ) ;
113+ } ) ;
114+
115+ it ( "handles publisher and original publisher" , ( ) => {
116+ const {
117+ otherSearchTerms,
118+ specialParts,
119+ } = splitString ( "frogs publisher: Pratham originalPublisher:Bob" , [
120+ "something irrelevant" ,
121+ "topic:Math" ,
122+ ] ) ;
123+ expect ( otherSearchTerms ) . toEqual ( "frogs" ) ;
124+ expect ( specialParts . length ) . toBe ( 2 ) ;
125+ expect ( specialParts . includes ( "originalPublisher:Bob" ) ) ;
126+ expect ( specialParts . includes ( "publisher:Pratham" ) ) ;
127+ } ) ;
128+
129+ it ( "handles publisher and original publisher with spaces" , ( ) => {
130+ const {
131+ otherSearchTerms,
132+ specialParts,
133+ } = splitString (
134+ 'frogs publisher: "African Storybook Project" originalPublisher:"Book Dash"' ,
135+ [ "something irrelevant" , "topic:Math" ]
136+ ) ;
137+ expect ( otherSearchTerms ) . toEqual ( "frogs" ) ;
138+ expect ( specialParts . length ) . toBe ( 2 ) ;
139+ expect ( specialParts . includes ( "originalPublisher:Book Dash" ) ) ;
140+ expect ( specialParts . includes ( "publisher:African Storybook Project" ) ) ;
141+ } ) ;
142+
143+ it ( "handles corner case of facet with no content" , ( ) => {
144+ const { otherSearchTerms, specialParts } = splitString ( "frogs publisher:" , [
145+ "something irrelevant" ,
146+ "topic:Math" ,
147+ ] ) ;
148+ expect ( otherSearchTerms ) . toEqual ( "frogs" ) ;
149+ expect ( specialParts . length ) . toBe ( 1 ) ;
150+ expect ( specialParts . includes ( "publisher:" ) ) ;
151+ } ) ;
152+
153+ it ( "handles facet corner case with quotes, but no space" , ( ) => {
154+ const {
155+ otherSearchTerms,
156+ specialParts,
157+ } = splitString ( 'frogs publisher:"Pratham"' , [
158+ "something irrelevant" ,
159+ "topic:Math" ,
160+ ] ) ;
161+ expect ( otherSearchTerms ) . toEqual ( "frogs" ) ;
162+ expect ( specialParts . length ) . toBe ( 1 ) ;
163+ expect ( specialParts . includes ( "publisher:Pratham" ) ) ;
164+ } ) ;
165+
166+ it ( "doesn't crash on missing facet final quote" , ( ) => {
167+ const {
168+ otherSearchTerms,
169+ specialParts,
170+ } = splitString ( 'frogs publisher: "Book Dash' , [
171+ "something irrelevant" ,
172+ "topic:Math" ,
173+ ] ) ;
174+ expect ( otherSearchTerms ) . toEqual ( "frogs" ) ;
175+ expect ( specialParts . length ) . toBe ( 1 ) ;
176+ expect ( specialParts . includes ( "publisher:Book Dash" ) ) ;
177+ } ) ;
178+
179+ it ( "doesn't crash on missing facet leading quote" , ( ) => {
180+ const {
181+ otherSearchTerms,
182+ specialParts,
183+ } = splitString ( 'frogs publisher: Book Dash"' , [
184+ "something irrelevant" ,
185+ "topic:Math" ,
186+ ] ) ;
187+ expect ( otherSearchTerms ) . toEqual ( 'frogs Dash"' ) ;
188+ expect ( specialParts . length ) . toBe ( 1 ) ;
189+ expect ( specialParts . includes ( "publisher:Book" ) ) ;
190+ } ) ;
191+
192+ it ( "doesn't crash on mismatched facet quotes" , ( ) => {
193+ const {
194+ otherSearchTerms,
195+ specialParts,
196+ } = splitString ( 'frogs publisher: "Book Dash" "another' , [
197+ "something irrelevant" ,
198+ "topic:Math" ,
199+ ] ) ;
200+ expect ( otherSearchTerms ) . toEqual ( 'frogs "another' ) ;
201+ expect ( specialParts . length ) . toBe ( 1 ) ;
202+ expect ( specialParts . includes ( "publisher:Book Dash" ) ) ;
203+ } ) ;
204+
205+ it ( "doesn't crash with facet empry string search" , ( ) => {
206+ const {
207+ otherSearchTerms,
208+ specialParts,
209+ } = splitString ( 'frogs publisher: ""' , [
210+ "something irrelevant" ,
211+ "topic:Math" ,
212+ ] ) ;
213+ expect ( otherSearchTerms ) . toEqual ( "frogs" ) ;
214+ expect ( specialParts . length ) . toBe ( 1 ) ;
215+ expect ( specialParts . includes ( "publisher:" ) ) ;
117216} ) ;
0 commit comments