Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: test/iron_list_mutations_test.dart

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/iron_list_hidden_test.dart ('k') | test/iron_list_physical_count_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 @TestOn('browser') 4 @TestOn('browser')
5 library polymer_elements.test.iron_list_mutations_test; 5 library polymer_elements.test.iron_list_mutations_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:js'; 8 import 'dart:js';
9 import 'dart:math';
9 import 'package:polymer_elements/iron_list.dart'; 10 import 'package:polymer_elements/iron_list.dart';
10 import 'package:polymer/polymer.dart'; 11 import 'package:polymer/polymer.dart';
11 import 'package:test/test.dart'; 12 import 'package:test/test.dart';
12 import 'package:web_components/web_components.dart'; 13 import 'package:web_components/web_components.dart';
13 import 'common.dart'; 14 import 'common.dart';
14 import 'iron_list_test_helpers.dart'; 15 import 'iron_list_test_helpers.dart';
15 import 'fixtures/x_list.dart'; 16 import 'fixtures/x_list.dart';
16 17
18 var rand = new Random();
19
17 main() async { 20 main() async {
18 await initPolymer(); 21 await initPolymer();
19 22
20 group('mutations to items', () { 23 group('mutations to items', () {
21 IronList list; 24 IronList list;
22 XList container; 25 XList container;
23 26
24 setUp(() { 27 setUp(() {
25 container = fixture('trivialList'); 28 container = fixture('trivialList');
26 list = container.list; 29 list = container.list;
27 }); 30 });
28 31
29 test('update physical item', () { 32 test('update physical item', () {
30 var setSize = 100; 33 var setSize = 100;
31 var phrase = 'It works!'; 34 var phrase = 'It works!';
32 list.items = buildDataSet(setSize); 35 list.items = buildDataSet(setSize);
33 // TODO(jakemac): Update once we resolve 36 list.set('items.0.index', phrase);
34 // https://github.com/dart-lang/polymer_interop/issues/6
35 list.jsElement.callMethod('set', ['items.0.index', phrase]);
36 return new Future(() {}).then((_) { 37 return new Future(() {}).then((_) {
37 expect(getFirstItemFromList(list).text, phrase); 38 expect(getFirstItemFromList(list).text, phrase);
38 }); 39 });
39 }); 40 });
40 41
41 test('update virtual item', () { 42 test('update virtual item', () {
42 var done = new Completer(); 43 var done = new Completer();
43 var setSize = 100; 44 var setSize = 100;
44 var phrase = 'It works!'; 45 var phrase = 'It works!';
45 list.items = buildDataSet(setSize); 46 list.items = buildDataSet(setSize);
46 47
47 scrollBackUp([_]) { 48 scrollBackUp([_]) {
48 simulateScroll({'list': list, 'contribution': 100, 'target': 0}, ([_]) { 49 simulateScroll({'list': list, 'contribution': 100, 'target': 0}, ([_]) {
49 new Future(() {}).then((_) { 50 new Future(() {}).then((_) {
50 expect(getFirstItemFromList(list).text, phrase); 51 expect(getFirstItemFromList(list).text, phrase);
51 done.complete(); 52 done.complete();
52 }); 53 });
53 }); 54 });
54 } 55 }
55 56
56 new Future(() {}).then((_) { 57 new Future(() {}).then((_) {
57 var rowHeight = list.jsElement['_physicalItems'][0].offsetHeight; 58 var rowHeight = list.jsElement['_physicalItems'][0].offsetHeight;
58 // scroll down 59 // scroll down
59 simulateScroll({ 60 simulateScroll(
60 'list': list, 61 {'list': list, 'contribution': 100, 'target': setSize * rowHeight},
61 'contribution': 100, 62 ([_]) {
62 'target': setSize * rowHeight 63 list.set('items.0.index', phrase);
63 }, ([_]) {
64 // TODO(jakemac): Update once we resolve
65 // https://github.com/dart-lang/polymer_interop/issues/6
66 list.jsElement.callMethod('set', ['items.0.index', phrase]);
67 new Future(() {}).then(scrollBackUp); 64 new Future(() {}).then(scrollBackUp);
68 }); 65 });
69 }); 66 });
70 67
71 return done.future; 68 return done.future;
72 }); 69 });
73 70
74 test('push', () { 71 test('push', () {
75 var done = new Completer(); 72 var done = new Completer();
76 var setSize = 100; 73 var setSize = 100;
77 list.items = buildDataSet(setSize); 74 list.items = buildDataSet(setSize);
78 setSize = list.items.length; 75 setSize = list.items.length;
79 // TODO(jakemac): Update once we resolve 76 list.add('items', buildItem(setSize));
80 // https://github.com/dart-lang/polymer_interop/issues/6
81 list.jsElement.callMethod('push', ['items', buildItem(setSize)]);
82 expect(list.items.length, setSize + 1); 77 expect(list.items.length, setSize + 1);
83 new Future(() {}).then((_) { 78 new Future(() {}).then((_) {
84 var rowHeight = list.jsElement['_physicalItems'][0].offsetHeight; 79 var rowHeight = list.jsElement['_physicalItems'][0].offsetHeight;
85 var viewportHeight = list.offsetHeight; 80 var viewportHeight = list.offsetHeight;
86 var itemsPerViewport = (viewportHeight / rowHeight).floor(); 81 var itemsPerViewport = (viewportHeight / rowHeight).floor();
87 expect(getFirstItemFromList(list).text, '0'); 82 expect(getFirstItemFromList(list).text, '0');
88 simulateScroll({ 83 simulateScroll({
89 'list': list, 84 'list': list,
90 'contribution': rowHeight, 85 'contribution': rowHeight,
91 'target': list.items.length * rowHeight 86 'target': list.items.length * rowHeight
(...skipping 14 matching lines...) Expand all
106 var rowHeight = list.jsElement['_physicalItems'][0].offsetHeight; 101 var rowHeight = list.jsElement['_physicalItems'][0].offsetHeight;
107 simulateScroll({ 102 simulateScroll({
108 'list': list, 103 'list': list,
109 'contribution': rowHeight, 104 'contribution': rowHeight,
110 'target': setSize * rowHeight 105 'target': setSize * rowHeight
111 }, ([_]) { 106 }, ([_]) {
112 var viewportHeight = list.offsetHeight; 107 var viewportHeight = list.offsetHeight;
113 var itemsPerViewport = (viewportHeight / rowHeight).floor(); 108 var itemsPerViewport = (viewportHeight / rowHeight).floor();
114 // TODO(jakemac): Update once we resolve 109 // TODO(jakemac): Update once we resolve
115 // https://github.com/dart-lang/polymer_interop/issues/6 110 // https://github.com/dart-lang/polymer_interop/issues/6
116 list.jsElement.callMethod('pop', ['items']); 111 list.removeLast('items');
117 new Future(() {}).then((_) { 112 new Future(() {}).then((_) {
118 expect(list.items.length, setSize - 1); 113 expect(list.items.length, setSize - 1);
119 expect(getFirstItemFromList(list).text, '${setSize - 3 - 1}'); 114 expect(getFirstItemFromList(list).text, '${setSize - 3 - 1}');
120 done.complete(); 115 done.complete();
121 }); 116 });
122 }); 117 });
123 }); 118 });
124 return done.future; 119 return done.future;
125 }); 120 });
126 121
127 test('splice', () { 122 test('splice', () {
128 var setSize = 45; 123 var setSize = 45;
129 var phrase = 'It works!'; 124 var phrase = 'It works!';
130 list.items = buildDataSet(setSize); 125 list.items = buildDataSet(setSize);
131 // TODO(jakemac): Update once we resolve 126 list.removeRange('items', 0, setSize);
132 // https://github.com/dart-lang/polymer_interop/issues/6 127 list.add('items', buildItem(phrase));
133 list.jsElement.callMethod(
134 'splice', ['items', 0, setSize, buildItem(phrase)]);
135 return new Future(() {}).then((_) { 128 return new Future(() {}).then((_) {
136 expect(list.items.length, 1); 129 expect(list.items.length, 1);
137 expect(getFirstItemFromList(list).text, phrase); 130 expect(getFirstItemFromList(list).text, phrase);
138 }); 131 });
139 }); 132 });
133
134 test('delete item and scroll to bottom', () {
135 var setSize = 100, index;
136
137 list.items = buildDataSet(setSize);
138
139 while (list.items.length > 10) {
140 index = (list.items.length * rand.nextDouble()).floor();
141 list.removeItem('items', list.items[index]);
142 list.scrollToIndex(list.items.length - 1);
143 expect(
144 new RegExp(r'^[0-9]*$').hasMatch(getFirstItemFromList(list).text),
145 isTrue);
146 }
147 });
140 }); 148 });
141 } 149 }
OLDNEW
« no previous file with comments | « test/iron_list_hidden_test.dart ('k') | test/iron_list_physical_count_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698