find_test.dart 2.68 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter_driver/flutter_driver.dart';
6

7
import '../../common.dart';
8 9

void main() {
10
  final FakeDeserialize fakeDeserialize = FakeDeserialize();
11

12 13 14 15 16 17 18 19
  test('Ancestor finder serialize', () {
    const SerializableFinder of = ByType('Text');
    final SerializableFinder matching = ByValueKey('hello');

    final Ancestor a = Ancestor(
      of: of,
      matching: matching,
      matchRoot: true,
20
      firstMatchOnly: true,
21 22 23
    );
    expect(a.serialize(), <String, String>{
      'finderType': 'Ancestor',
24 25
      'of': '{"finderType":"ByType","type":"Text"}',
      'matching': '{"finderType":"ByValueKey","keyValueString":"hello","keyValueType":"String"}',
26 27
      'matchRoot': 'true',
      'firstMatchOnly': 'true',
28 29 30 31 32 33
    });
  });

  test('Ancestor finder deserialize', () {
    final Map<String, String> serialized = <String, String>{
      'finderType': 'Ancestor',
34 35
      'of': '{"finderType":"ByType","type":"Text"}',
      'matching': '{"finderType":"ByValueKey","keyValueString":"hello","keyValueType":"String"}',
36 37
      'matchRoot': 'true',
      'firstMatchOnly': 'true',
38 39
    };

40
    final Ancestor a = Ancestor.deserialize(serialized, fakeDeserialize);
41 42 43
    expect(a.of, isA<ByType>());
    expect(a.matching, isA<ByValueKey>());
    expect(a.matchRoot, isTrue);
44
    expect(a.firstMatchOnly, isTrue);
45 46 47 48 49 50 51 52 53 54
  });

  test('Descendant finder serialize', () {
    const SerializableFinder of = ByType('Text');
    final SerializableFinder matching = ByValueKey('hello');

    final Descendant a = Descendant(
      of: of,
      matching: matching,
      matchRoot: true,
55
      firstMatchOnly: true,
56 57 58
    );
    expect(a.serialize(), <String, String>{
      'finderType': 'Descendant',
59 60
      'of': '{"finderType":"ByType","type":"Text"}',
      'matching': '{"finderType":"ByValueKey","keyValueString":"hello","keyValueType":"String"}',
61 62
      'matchRoot': 'true',
      'firstMatchOnly': 'true',
63 64 65 66 67 68
    });
  });

  test('Descendant finder deserialize', () {
    final Map<String, String> serialized = <String, String>{
      'finderType': 'Descendant',
69 70
      'of': '{"finderType":"ByType","type":"Text"}',
      'matching': '{"finderType":"ByValueKey","keyValueString":"hello","keyValueType":"String"}',
71 72
      'matchRoot': 'true',
      'firstMatchOnly': 'true',
73 74
    };

75
    final Descendant a = Descendant.deserialize(serialized, fakeDeserialize);
76 77 78
    expect(a.of, isA<ByType>());
    expect(a.matching, isA<ByValueKey>());
    expect(a.matchRoot, isTrue);
79
    expect(a.firstMatchOnly, isTrue);
80 81
  });
}
82

83
class FakeDeserialize extends Fake with DeserializeFinderFactory { }