Skip to content

Commit 817c005

Browse files
committed
test: added simple View test
1 parent 9c7c7e8 commit 817c005

File tree

9 files changed

+65
-27
lines changed

9 files changed

+65
-27
lines changed

karma-mock-annotations.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11

22
// TODO: Remove these annotations in the JS traceur build as they are only needed in Dart
3-
window.FIELD = function() {};
3+
window.FIELD = function() {};
4+
window.IMPLEMENTS = function() {};
5+
window.CONST = function() {};
6+
window.List = Array;

modules/change_detection/src/record.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ProtoWatchGroup, WatchGroup} from './watch_group';
1+
//import {ProtoWatchGroup, WatchGroup} from './watch_group';
22

33
export class ProtoRecord {
44

@@ -20,7 +20,7 @@ export class ProtoRecord {
2020
// May be removed if we don't support coelsence.
2121
@FIELD('_updateContextNext:ProtoRecord')
2222
@FIELD('_clone')
23-
constructor(watchGroup:ProtoWatchGroup, fieldName:String) {
23+
constructor(watchGroup/*:ProtoWatchGroup*/, fieldName:String) {
2424
this.watchGroup = watchGroup;
2525
this.fieldName = fieldName;
2626
this.next = null;
@@ -34,7 +34,7 @@ export class ProtoRecord {
3434
this._clone = null;
3535
}
3636

37-
instantiate(watchGroup:WatchGroup):Record {
37+
instantiate(watchGroup/*:WatchGroup*/):Record {
3838
var record = this._clone = new Record(watchGroup, this);
3939
record.prev = this.prev._clone;
4040
record._checkPrev = this._checkPrev._clone;
@@ -94,7 +94,7 @@ export class Record {
9494
@FIELD('_arguments')
9595
@FIELD('currentValue')
9696
@FIELD('previousValue')
97-
constructor(watchGroup:WatchGroup, protoRecord:ProtoRecord) {
97+
constructor(watchGroup/*:WatchGroup*/, protoRecord:ProtoRecord) {
9898
this.protoRecord = protoRecord;
9999
this.watchGroup = watchGroup;
100100
this.next = null;

modules/core/src/compiler/view.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,6 @@ import {Module} from 'di/di';
66
import {ProtoElementInjector, ElementInjector} from './element_injector';
77
import {SetterFn} from 'change_detection/facade';
88

9-
export class ProtoView {
10-
@FIELD('final _template:TemplateElement')
11-
@FIELD('final _module:Module')
12-
@FIELD('final _protoElementInjectors:List<ProtoElementInjector>')
13-
@FIELD('final _protoWatchGroup:ProtoWatchGroup')
14-
constructor(
15-
template:TemplateElement,
16-
module:Module,
17-
protoElementInjector:ProtoElementInjector,
18-
protoWatchGroup:ProtoWatchGroup)
19-
{
20-
this._template = template;
21-
this._module = module;
22-
this._protoElementInjectors = protoElementInjector;
23-
this._protoWatchGroup = protoWatchGroup;
24-
}
25-
}
26-
279
@IMPLEMENTS(WatchGroupDispatcher)
2810
export class View {
2911
@FIELD('final _fragment:DocumentFragment')
@@ -59,6 +41,28 @@ export class View {
5941
}
6042
}
6143

44+
export class ProtoView {
45+
@FIELD('final _template:TemplateElement')
46+
@FIELD('final _module:Module')
47+
@FIELD('final _protoElementInjectors:List<ProtoElementInjector>')
48+
@FIELD('final _protoWatchGroup:ProtoWatchGroup')
49+
constructor(
50+
template:TemplateElement,
51+
module:Module,
52+
protoElementInjector:ProtoElementInjector,
53+
protoWatchGroup:ProtoWatchGroup)
54+
{
55+
this._template = template;
56+
this._module = module;
57+
this._protoElementInjectors = protoElementInjector;
58+
this._protoWatchGroup = protoWatchGroup;
59+
}
60+
61+
instantiate():View {
62+
return new View(DOM.clone(this._template.content));
63+
}
64+
}
65+
6266

6367
export class ElementInjectorTarget {
6468
@FIELD('final _elementInjectorIndex:int')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {describe, id} from 'test_lib/test_lib';
2+
import {ProtoView, View} from './view';
3+
import {DOM} from 'facade/dom';
4+
5+
export function main() {
6+
describe('view', () => {
7+
describe('ProtoView', () => {
8+
it('should create an instance of view', () => {
9+
var template = DOM.createTemplate('Hello <b>world</b>!');
10+
var pv = new ProtoView(template, null, null, null);
11+
var view:View = pv.instantiate();
12+
expect(view instanceof View).toBe(true);
13+
});
14+
});
15+
});
16+
}

modules/facade/src/collection.es6

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ export class MapWrapper {
1111
export class ListWrapper {
1212
static create():List { return new List(); }
1313
static get(m, k) { return m[k]; }
14-
static set(m, k, v) { m[k] = v; }
15-
}
14+
static set(m, k, v) { m[k] = v; }
15+
static clone(array) {
16+
return Array.prototype.slice.call(array, 0);
17+
}
18+
}

modules/facade/src/dom.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ class DOM {
2020
static setText(Text text, String value) {
2121
text.text = value;
2222
}
23+
static clone(Node node) {
24+
return node.clone(true);
25+
}
2326
}

modules/facade/src/dom.es6

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ export class DOM {
2020
static setText(text:Text, value:String) {
2121
text.nodeValue = value;
2222
}
23+
static createTemplate(html) {
24+
var t = document.createElement('template');
25+
t.innerHTML = html;
26+
return t;
27+
}
28+
static clone(node:Node) {
29+
return node.cloneNode(true);
30+
}
2331
}

modules/rtts_assert/src/rtts_assert.es6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ function type(actual, T) {
162162

163163
throw new Error(msg);
164164
}
165+
return actual;
165166
}
166167

167168
function returnType(actual, T) {

modules/rtts_assert/test/rtts_assert_spec.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ describe('primitive value check', function() {
147147
describe('boolean', function() {
148148

149149
it('should pass', function() {
150-
assert.type(true, primitive.boolean);
151-
assert.type(false, primitive.boolean);
150+
expect(assert.type(true, primitive.boolean)).toBe(true);
151+
expect(assert.type(false, primitive.boolean)).toBe(false);
152152
});
153153

154154

0 commit comments

Comments
 (0)