OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
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.md file. | |
4 | |
5 import 'package:expect/expect.dart'; | |
6 | |
7 import 'package:immi/immi.dart'; | |
8 import 'package:immi_samples/sliding_window.dart'; | |
9 import 'package:service/struct.dart'; | |
10 | |
11 import 'package:immi_gen/dart/immi_service.dart'; | |
12 | |
13 import '../../github_immi.dart'; | |
14 import '../github_services.dart'; | |
15 import '../github_mock.dart'; | |
16 import '../commit_list_presenter.dart'; | |
17 import '../commit_presenter.dart'; | |
18 | |
19 void main() { | |
20 var mock = new GithubMock()..spawn(); | |
21 var server = new Server(mock.host, mock.port); | |
22 var user = server.getUser('dartino'); | |
23 var repo = user.getRepository('sdk'); | |
24 testPresent(repo); | |
25 server.close(); | |
26 mock.close(); | |
27 } | |
28 | |
29 void testPresent(Repository repo) { | |
30 var presenter = new CommitListPresenter(repo); | |
31 SlidingWindowNode previous = null; | |
32 SlidingWindowNode current = null; | |
33 CommitNode commitNode = null; | |
34 | |
35 // Initial rendering (don't assume much about this). | |
36 current = presenter.present(previous); | |
37 testDiff(previous, current); | |
38 | |
39 // Provide screen-size and re-render. | |
40 (current.display)(0, 5); | |
41 previous = current; | |
42 current = presenter.present(previous); | |
43 Expect.equals(0, current.startOffset); | |
44 Expect.equals(5, current.window.length); | |
45 commitNode = current.window[0]; | |
46 Expect.stringEquals("Ian Zerny", commitNode.author); | |
47 testDiff(previous, current); | |
48 | |
49 (current.display)(0, 6); | |
50 previous = current; | |
51 current = presenter.present(previous); | |
52 Expect.equals(0, current.startOffset); | |
53 Expect.isTrue(current.window.length >= 6); | |
54 commitNode = current.window[0]; | |
55 Expect.stringEquals("Ian Zerny", commitNode.author); | |
56 testDiff(previous, current); | |
57 | |
58 (current.display)(1, 6); | |
59 previous = current; | |
60 current = presenter.present(previous); | |
61 Expect.equals(1, current.startOffset); | |
62 Expect.equals(1, current.windowOffset); | |
63 Expect.isTrue(current.window.length >= 5); | |
64 commitNode = current.window[1]; | |
65 Expect.stringEquals("Anders Johnsen", commitNode.author); | |
66 testDiff(previous, current); | |
67 | |
68 (current.display)(100, 105); | |
69 previous = current; | |
70 current = presenter.present(previous); | |
71 Expect.equals(100, current.startOffset); | |
72 Expect.equals(0, current.windowOffset); | |
73 | |
74 (current.display)(99, 104); | |
75 previous = current; | |
76 current = presenter.present(previous); | |
77 Expect.equals(99, current.startOffset); | |
78 Expect.equals(4, current.windowOffset); | |
79 } | |
80 | |
81 testDiff(Node previous, Node current) { | |
82 NodePatch patch = current.diff(previous); | |
83 Expect.isNotNull(patch); | |
84 | |
85 // Check that we can successfully serialize the data. | |
86 var manager = new ResourceManager(); | |
87 var mb = new MessageBuilder(24); | |
88 PatchDataBuilder builder = mb.initRoot(new PatchDataBuilder(), 16); | |
89 patch.serializeNode(builder.initNode(), manager); | |
90 } | |
OLD | NEW |