@@ -4084,6 +4084,156 @@ describe('Query class', () => {
4084
4084
docChanges : expectedChanges ,
4085
4085
} ) ;
4086
4086
} ) ;
4087
+
4088
+ describe ( 'sort unicode strings' , ( ) => {
4089
+ it ( 'snapshot listener sorts unicode strings same as server' , async ( ) => {
4090
+ const collection = await testCollectionWithDocs ( {
4091
+ a : { value : 'Łukasiewicz' } ,
4092
+ b : { value : 'Sierpiński' } ,
4093
+ c : { value : '岩澤' } ,
4094
+ d : { value : '🄟' } ,
4095
+ e : { value : 'P' } ,
4096
+ f : { value : '︒' } ,
4097
+ g : { value : '🐵' } ,
4098
+ } ) ;
4099
+
4100
+ const query = collection . orderBy ( 'value' ) ;
4101
+ const expectedDocs = [ 'b' , 'a' , 'c' , 'f' , 'e' , 'd' , 'g' ] ;
4102
+
4103
+ const getSnapshot = await query . get ( ) ;
4104
+ expect ( getSnapshot . docs . map ( d => d . id ) ) . to . deep . equal ( expectedDocs ) ;
4105
+
4106
+ const unsubscribe = query . onSnapshot ( snapshot =>
4107
+ currentDeferred . resolve ( snapshot )
4108
+ ) ;
4109
+ const watchSnapshot = await waitForSnapshot ( ) ;
4110
+ snapshotsEqual ( watchSnapshot , {
4111
+ docs : getSnapshot . docs ,
4112
+ docChanges : getSnapshot . docChanges ( ) ,
4113
+ } ) ;
4114
+ unsubscribe ( ) ;
4115
+ } ) ;
4116
+
4117
+ it ( 'snapshot listener sorts unicode strings in array same as server' , async ( ) => {
4118
+ const collection = await testCollectionWithDocs ( {
4119
+ a : { value : [ 'Łukasiewicz' ] } ,
4120
+ b : { value : [ 'Sierpiński' ] } ,
4121
+ c : { value : [ '岩澤' ] } ,
4122
+ d : { value : [ '🄟' ] } ,
4123
+ e : { value : [ 'P' ] } ,
4124
+ f : { value : [ '︒' ] } ,
4125
+ g : { value : [ '🐵' ] } ,
4126
+ } ) ;
4127
+
4128
+ const query = collection . orderBy ( 'value' ) ;
4129
+ const expectedDocs = [ 'b' , 'a' , 'c' , 'f' , 'e' , 'd' , 'g' ] ;
4130
+
4131
+ const getSnapshot = await query . get ( ) ;
4132
+ expect ( getSnapshot . docs . map ( d => d . id ) ) . to . deep . equal ( expectedDocs ) ;
4133
+
4134
+ const unsubscribe = query . onSnapshot ( snapshot =>
4135
+ currentDeferred . resolve ( snapshot )
4136
+ ) ;
4137
+ const watchSnapshot = await waitForSnapshot ( ) ;
4138
+ snapshotsEqual ( watchSnapshot , {
4139
+ docs : getSnapshot . docs ,
4140
+ docChanges : getSnapshot . docChanges ( ) ,
4141
+ } ) ;
4142
+ unsubscribe ( ) ;
4143
+ } ) ;
4144
+
4145
+ it ( 'snapshot listener sorts unicode strings in map same as server' , async ( ) => {
4146
+ const collection = await testCollectionWithDocs ( {
4147
+ a : { value : { foo : 'Łukasiewicz' } } ,
4148
+ b : { value : { foo : 'Sierpiński' } } ,
4149
+ c : { value : { foo : '岩澤' } } ,
4150
+ d : { value : { foo : '🄟' } } ,
4151
+ e : { value : { foo : 'P' } } ,
4152
+ f : { value : { foo : '︒' } } ,
4153
+ g : { value : { foo : '🐵' } } ,
4154
+ } ) ;
4155
+
4156
+ const query = collection . orderBy ( 'value' ) ;
4157
+ const expectedDocs = [ 'b' , 'a' , 'c' , 'f' , 'e' , 'd' , 'g' ] ;
4158
+
4159
+ const getSnapshot = await query . get ( ) ;
4160
+ expect ( getSnapshot . docs . map ( d => d . id ) ) . to . deep . equal ( expectedDocs ) ;
4161
+
4162
+ const unsubscribe = query . onSnapshot ( snapshot =>
4163
+ currentDeferred . resolve ( snapshot )
4164
+ ) ;
4165
+ const watchSnapshot = await waitForSnapshot ( ) ;
4166
+ snapshotsEqual ( watchSnapshot , {
4167
+ docs : getSnapshot . docs ,
4168
+ docChanges : getSnapshot . docChanges ( ) ,
4169
+ } ) ;
4170
+ unsubscribe ( ) ;
4171
+ } ) ;
4172
+
4173
+ it ( 'snapshot listener sorts unicode strings in map key same as server' , async ( ) => {
4174
+ const collection = await testCollectionWithDocs ( {
4175
+ a : { value : { Łukasiewicz : true } } ,
4176
+ b : { value : { Sierpiński : true } } ,
4177
+ c : { value : { 岩澤 : true } } ,
4178
+ d : { value : { '🄟' : true } } ,
4179
+ e : { value : { P : true } } ,
4180
+ f : { value : { '︒' : true } } ,
4181
+ g : { value : { '🐵' : true } } ,
4182
+ } ) ;
4183
+
4184
+ const query = collection . orderBy ( 'value' ) ;
4185
+ const expectedDocs = [ 'b' , 'a' , 'c' , 'f' , 'e' , 'd' , 'g' ] ;
4186
+
4187
+ const getSnapshot = await query . get ( ) ;
4188
+ expect ( getSnapshot . docs . map ( d => d . id ) ) . to . deep . equal ( expectedDocs ) ;
4189
+
4190
+ const unsubscribe = query . onSnapshot ( snapshot =>
4191
+ currentDeferred . resolve ( snapshot )
4192
+ ) ;
4193
+ const watchSnapshot = await waitForSnapshot ( ) ;
4194
+ snapshotsEqual ( watchSnapshot , {
4195
+ docs : getSnapshot . docs ,
4196
+ docChanges : getSnapshot . docChanges ( ) ,
4197
+ } ) ;
4198
+ unsubscribe ( ) ;
4199
+ } ) ;
4200
+
4201
+ it ( 'snapshot listener sorts unicode strings in document key same as server' , async ( ) => {
4202
+ const collection = await testCollectionWithDocs ( {
4203
+ Łukasiewicz : { value : true } ,
4204
+ Sierpiński : { value : true } ,
4205
+ 岩澤 : { value : true } ,
4206
+ '🄟' : { value : true } ,
4207
+ P : { value : true } ,
4208
+ '︒' : { value : true } ,
4209
+ '🐵' : { value : true } ,
4210
+ } ) ;
4211
+
4212
+ const query = collection . orderBy ( FieldPath . documentId ( ) ) ;
4213
+ const expectedDocs = [
4214
+ 'Sierpiński' ,
4215
+ 'Łukasiewicz' ,
4216
+ '岩澤' ,
4217
+ '︒' ,
4218
+ 'P' ,
4219
+ '🄟' ,
4220
+ '🐵' ,
4221
+ ] ;
4222
+
4223
+ const getSnapshot = await query . get ( ) ;
4224
+ expect ( getSnapshot . docs . map ( d => d . id ) ) . to . deep . equal ( expectedDocs ) ;
4225
+
4226
+ const unsubscribe = query . onSnapshot ( snapshot =>
4227
+ currentDeferred . resolve ( snapshot )
4228
+ ) ;
4229
+ const watchSnapshot = await waitForSnapshot ( ) ;
4230
+ snapshotsEqual ( watchSnapshot , {
4231
+ docs : getSnapshot . docs ,
4232
+ docChanges : getSnapshot . docChanges ( ) ,
4233
+ } ) ;
4234
+ unsubscribe ( ) ;
4235
+ } ) ;
4236
+ } ) ;
4087
4237
} ) ;
4088
4238
4089
4239
( process . env . FIRESTORE_EMULATOR_HOST === undefined
0 commit comments