This repository was archived by the owner on Oct 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathpage_object_data_test.dart
More file actions
125 lines (111 loc) · 4.76 KB
/
Copy pathpage_object_data_test.dart
File metadata and controls
125 lines (111 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2017 Google Inc.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
import 'package:angular_cli/src/page_object_data.dart';
import 'package:test/test.dart';
void main() {
group('PageObjectData', () {
test('should generate items.', () {
var po = new PageObjectData(
'<action-button class="good"></action-button>',
);
expect(po.variables.first.getterString,
'Future<PageLoaderElement> get good => _getGood();');
expect(po.variables.first.internalString,
"@ByClass('good')\n Lazy<PageLoaderElement> _getGood;");
expect(po.variables.first.type.uri, 'package:pageloader/objects.dart');
});
test('should generate items in list', () {
var po = new PageObjectData(
'<action-button class="good" *ngFor="xxx"></action-button>',
);
expect(po.variables.first.getterString,
'Future<List<PageLoaderElement>> get good => _getGood();');
expect(po.variables.first.internalString,
"@ByClass('good')\n Lazy<List<PageLoaderElement>> _getGood;");
});
test('should generate items in parents list', () {
var po = new PageObjectData(
'<p *ngFor="xxx"><action-button class="good">'
'</action-button></p>',
);
expect(po.variables.first.getterString,
'Future<List<PageLoaderElement>> get good => _getGood();');
expect(po.variables.first.internalString,
"@ByClass('good')\n Lazy<List<PageLoaderElement>> _getGood;");
});
test('should generate items with default type', () {
var po = new PageObjectData('<some-widget class="cool"></some-widget>');
expect(po.variables.first.getterString,
'Future<PageLoaderElement> get cool => _getCool();');
expect(po.variables.first.internalString,
"@ByClass('cool')\n Lazy<PageLoaderElement> _getCool;");
expect(po.variables.first.type.uri, 'package:pageloader/objects.dart');
});
test('should sort generated items', () {
var po1 = new PageObjectData(
'<action-button class="good"></action-button>'
'<action-button class="bad"></action-button>',
);
expect(po1.variables.first.name, 'Bad');
expect(po1.variables.last.name, 'Good');
var po2 = new PageObjectData(
'<action-button class="good"></action-button>'
'<action-button class="bad"></action-button>',
);
expect(po2.variables.first.name, 'Bad');
expect(po2.variables.last.name, 'Good');
});
test('should ignore some tags.', () {
var po = new PageObjectData('<p>123</p>');
expect(po.variables.isEmpty, true);
});
test('should add optional annotation.', () {
var po = new PageObjectData('<some-widget *ngIf="1"></some-widget>');
expect(po.variables[0].internalString, startsWith('@optional'));
});
test('should add optional annotation when parent is optional.', () {
var po = new PageObjectData(
'<div *ngIf="1"><some-widget></some-widget></div>');
expect(po.variables[0].internalString, startsWith('@optional'));
});
test('should add optional annotation when in <template [ngIf]>', () {
var po = new PageObjectData(
'<template [ngIf]="1"><some-widget></some-widget></template>',
);
expect(po.variables[0].internalString, startsWith('@optional'));
});
test('should choose correct selector.', () {
var po = new PageObjectData(
'<some-widget class="cool"></some-widget>'
'<some-widget class="cool" id="cooler"></some-widget>'
'<some-widget></some-widget>',
);
expect(po.variables.length, 3);
expect(po.variables[0].selector.toString(), "@ByClass('cool')");
expect(po.variables[1].selector.toString(), "@ById('cooler')");
expect(po.variables[2].selector.toString(), "@ByTagName('some-widget')");
});
test('should work with selectors with attributes', () {
var po = new PageObjectData(
'<some-cell class="field-class"></some-cell>'
'<some-cell id="fieldWithId"></some-cell>',
);
expect(po.variables[0].selector.toString(), "@ByClass('field-class')");
expect(po.variables[1].selector.toString(), "@ById('fieldWithId')");
expect(po.variables[0].name, 'FieldClass');
expect(po.variables[1].name, 'FieldWithId');
});
test('should produce correct commonDependencies.', () {
var po1 = new PageObjectData('');
expect(po1.commonDependencies, [PageObjectData.pageLoaderDependency]);
var po3 = new PageObjectData('<some-widget></some-widget>');
expect(po3.commonDependencies, [
PageObjectData.pageLoaderDependency,
PageObjectData.asyncDependency
]);
});
});
}