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

import 'package:flutter_driver/src/common/find.dart';

7
import '../../common.dart';
8 9 10 11 12 13 14 15 16 17

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

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

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

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

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

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

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

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