Skip to content

Commit

Permalink
test: added simple View test
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Sep 29, 2014
1 parent 9c7c7e8 commit 817c005
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 27 deletions.
5 changes: 4 additions & 1 deletion karma-mock-annotations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

// TODO: Remove these annotations in the JS traceur build as they are only needed in Dart
window.FIELD = function() {};
window.FIELD = function() {};
window.IMPLEMENTS = function() {};
window.CONST = function() {};
window.List = Array;
8 changes: 4 additions & 4 deletions modules/change_detection/src/record.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ProtoWatchGroup, WatchGroup} from './watch_group';
//import {ProtoWatchGroup, WatchGroup} from './watch_group';

export class ProtoRecord {

Expand All @@ -20,7 +20,7 @@ export class ProtoRecord {
// May be removed if we don't support coelsence.
@FIELD('_updateContextNext:ProtoRecord')
@FIELD('_clone')
constructor(watchGroup:ProtoWatchGroup, fieldName:String) {
constructor(watchGroup/*:ProtoWatchGroup*/, fieldName:String) {
this.watchGroup = watchGroup;
this.fieldName = fieldName;
this.next = null;
Expand All @@ -34,7 +34,7 @@ export class ProtoRecord {
this._clone = null;
}

instantiate(watchGroup:WatchGroup):Record {
instantiate(watchGroup/*:WatchGroup*/):Record {
var record = this._clone = new Record(watchGroup, this);
record.prev = this.prev._clone;
record._checkPrev = this._checkPrev._clone;
Expand Down Expand Up @@ -94,7 +94,7 @@ export class Record {
@FIELD('_arguments')
@FIELD('currentValue')
@FIELD('previousValue')
constructor(watchGroup:WatchGroup, protoRecord:ProtoRecord) {
constructor(watchGroup/*:WatchGroup*/, protoRecord:ProtoRecord) {
this.protoRecord = protoRecord;
this.watchGroup = watchGroup;
this.next = null;
Expand Down
40 changes: 22 additions & 18 deletions modules/core/src/compiler/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@ import {Module} from 'di/di';
import {ProtoElementInjector, ElementInjector} from './element_injector';
import {SetterFn} from 'change_detection/facade';

export class ProtoView {
@FIELD('final _template:TemplateElement')
@FIELD('final _module:Module')
@FIELD('final _protoElementInjectors:List<ProtoElementInjector>')
@FIELD('final _protoWatchGroup:ProtoWatchGroup')
constructor(
template:TemplateElement,
module:Module,
protoElementInjector:ProtoElementInjector,
protoWatchGroup:ProtoWatchGroup)
{
this._template = template;
this._module = module;
this._protoElementInjectors = protoElementInjector;
this._protoWatchGroup = protoWatchGroup;
}
}

@IMPLEMENTS(WatchGroupDispatcher)
export class View {
@FIELD('final _fragment:DocumentFragment')
Expand Down Expand Up @@ -59,6 +41,28 @@ export class View {
}
}

export class ProtoView {
@FIELD('final _template:TemplateElement')
@FIELD('final _module:Module')
@FIELD('final _protoElementInjectors:List<ProtoElementInjector>')
@FIELD('final _protoWatchGroup:ProtoWatchGroup')
constructor(
template:TemplateElement,
module:Module,
protoElementInjector:ProtoElementInjector,
protoWatchGroup:ProtoWatchGroup)
{
this._template = template;
this._module = module;
this._protoElementInjectors = protoElementInjector;
this._protoWatchGroup = protoWatchGroup;
}

instantiate():View {
return new View(DOM.clone(this._template.content));
}
}


export class ElementInjectorTarget {
@FIELD('final _elementInjectorIndex:int')
Expand Down
16 changes: 16 additions & 0 deletions modules/core/test/compiler/view_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {describe, id} from 'test_lib/test_lib';
import {ProtoView, View} from './view';
import {DOM} from 'facade/dom';

export function main() {
describe('view', () => {
describe('ProtoView', () => {
it('should create an instance of view', () => {
var template = DOM.createTemplate('Hello <b>world</b>!');
var pv = new ProtoView(template, null, null, null);
var view:View = pv.instantiate();
expect(view instanceof View).toBe(true);
});
});
});
}
7 changes: 5 additions & 2 deletions modules/facade/src/collection.es6
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ export class MapWrapper {
export class ListWrapper {
static create():List { return new List(); }
static get(m, k) { return m[k]; }
static set(m, k, v) { m[k] = v; }
}
static set(m, k, v) { m[k] = v; }
static clone(array) {
return Array.prototype.slice.call(array, 0);
}
}
3 changes: 3 additions & 0 deletions modules/facade/src/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ class DOM {
static setText(Text text, String value) {
text.text = value;
}
static clone(Node node) {
return node.clone(true);
}
}
8 changes: 8 additions & 0 deletions modules/facade/src/dom.es6
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ export class DOM {
static setText(text:Text, value:String) {
text.nodeValue = value;
}
static createTemplate(html) {
var t = document.createElement('template');
t.innerHTML = html;
return t;
}
static clone(node:Node) {
return node.cloneNode(true);
}
}
1 change: 1 addition & 0 deletions modules/rtts_assert/src/rtts_assert.es6
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function type(actual, T) {

throw new Error(msg);
}
return actual;
}

function returnType(actual, T) {
Expand Down
4 changes: 2 additions & 2 deletions modules/rtts_assert/test/rtts_assert_spec.es6
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ describe('primitive value check', function() {
describe('boolean', function() {

it('should pass', function() {
assert.type(true, primitive.boolean);
assert.type(false, primitive.boolean);
expect(assert.type(true, primitive.boolean)).toBe(true);
expect(assert.type(false, primitive.boolean)).toBe(false);
});


Expand Down

0 comments on commit 817c005

Please sign in to comment.