test: added simple View test
This commit is contained in:
parent
9c7c7e8acf
commit
817c005845
|
@ -1,3 +1,6 @@
|
|||
|
||||
// TODO: Remove these annotations in the JS traceur build as they are only needed in Dart
|
||||
window.FIELD = function() {};
|
||||
window.IMPLEMENTS = function() {};
|
||||
window.CONST = function() {};
|
||||
window.List = Array;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {ProtoWatchGroup, WatchGroup} from './watch_group';
|
||||
//import {ProtoWatchGroup, WatchGroup} from './watch_group';
|
||||
|
||||
export class ProtoRecord {
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -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')
|
||||
|
@ -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')
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
|
@ -12,4 +12,7 @@ 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 clone(array) {
|
||||
return Array.prototype.slice.call(array, 0);
|
||||
}
|
||||
}
|
|
@ -20,4 +20,7 @@ class DOM {
|
|||
static setText(Text text, String value) {
|
||||
text.text = value;
|
||||
}
|
||||
static clone(Node node) {
|
||||
return node.clone(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,6 +162,7 @@ function type(actual, T) {
|
|||
|
||||
throw new Error(msg);
|
||||
}
|
||||
return actual;
|
||||
}
|
||||
|
||||
function returnType(actual, T) {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue