7
7
// TODO(nurhan): https://github.com/flutter/flutter/issues/51169
8
8
9
9
import 'dart:async' ;
10
+ import 'dart:html' as html;
10
11
import 'dart:typed_data' ;
11
12
12
13
import 'package:test/test.dart' ;
@@ -28,7 +29,7 @@ const MethodCodec codec = JSONMethodCodec();
28
29
void emptyCallback (ByteData date) {}
29
30
30
31
void main () {
31
- group ('BrowserHistory' , () {
32
+ group ('$ BrowserHistory ' , () {
32
33
final PlatformMessagesSpy spy = PlatformMessagesSpy ();
33
34
34
35
setUp (() {
@@ -229,6 +230,41 @@ void main() {
229
230
// TODO(nurhan): https://github.com/flutter/flutter/issues/50836
230
231
skip: browserEngine == BrowserEngine .edge);
231
232
});
233
+
234
+ group ('$HashLocationStrategy ' , () {
235
+ TestPlatformLocation location;
236
+
237
+ setUp (() {
238
+ location = TestPlatformLocation ();
239
+ });
240
+
241
+ tearDown (() {
242
+ location = null ;
243
+ });
244
+
245
+ test ('leading slash is optional' , () {
246
+ final HashLocationStrategy strategy = HashLocationStrategy (location);
247
+
248
+ location.hash = '#/' ;
249
+ expect (strategy.path, '/' );
250
+
251
+ location.hash = '#/foo' ;
252
+ expect (strategy.path, '/foo' );
253
+
254
+ location.hash = '#foo' ;
255
+ expect (strategy.path, 'foo' );
256
+ });
257
+
258
+ test ('path should not be empty' , () {
259
+ final HashLocationStrategy strategy = HashLocationStrategy (location);
260
+
261
+ location.hash = '' ;
262
+ expect (strategy.path, '/' );
263
+
264
+ location.hash = '#' ;
265
+ expect (strategy.path, '/' );
266
+ });
267
+ });
232
268
}
233
269
234
270
void pushRoute (String routeName) {
@@ -276,3 +312,38 @@ Future<void> systemNavigatorPop() {
276
312
);
277
313
return completer.future;
278
314
}
315
+
316
+ /// A mock implementation of [PlatformLocation] that doesn't access the browser.
317
+ class TestPlatformLocation extends PlatformLocation {
318
+ String pathname;
319
+ String search;
320
+ String hash;
321
+
322
+ void onPopState (html.EventListener fn) {
323
+ throw UnimplementedError ();
324
+ }
325
+
326
+ void offPopState (html.EventListener fn) {
327
+ throw UnimplementedError ();
328
+ }
329
+
330
+ void onHashChange (html.EventListener fn) {
331
+ throw UnimplementedError ();
332
+ }
333
+
334
+ void offHashChange (html.EventListener fn) {
335
+ throw UnimplementedError ();
336
+ }
337
+
338
+ void pushState (dynamic state, String title, String url) {
339
+ throw UnimplementedError ();
340
+ }
341
+
342
+ void replaceState (dynamic state, String title, String url) {
343
+ throw UnimplementedError ();
344
+ }
345
+
346
+ void back () {
347
+ throw UnimplementedError ();
348
+ }
349
+ }
0 commit comments