Skip to content

Commit b3a9439

Browse files
committed
WIP NEWER PACKAGES
1 parent 9830c6f commit b3a9439

File tree

10 files changed

+272
-144
lines changed

10 files changed

+272
-144
lines changed

angular-cli-build.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = function(defaults) {
2525

2626
const ngTree = angularAppTree.toTree();
2727
const ngNewPackagesRelease = new Funnel('node_modules/@angular', {destDir: '@angular'});
28+
const rxjs = new Funnel('node_modules/rxjs', {destDir: 'rxjs'});
2829
const cssAutoprefixed = autoPrefixerTree(new Funnel(ngTree, {
2930
include: [ '**/*.css' ]
3031
}));
@@ -34,5 +35,6 @@ module.exports = function(defaults) {
3435
angularAppTree.toTree(),
3536
cssAutoprefixed,
3637
ngNewPackagesRelease,
38+
rxjs,
3739
], { overwrite: true });
3840
};

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
"dependencies": {
2828
"angular2": "2.0.0-beta.17",
2929

30-
"@angular/common": "0.0.0-2",
31-
"@angular/compiler": "0.0.0-2",
32-
"@angular/core": "0.0.0-2",
30+
"@angular/common": "0.0.0-3",
31+
"@angular/compiler": "0.0.0-3",
32+
"@angular/core": "0.0.0-3",
3333
"@angular/router": "0.0.0-0",
34-
"@angular/http": "0.0.0-0",
35-
"@angular/platform-browser": "0.0.0-2",
36-
"@angular/platform-browser-dynamic": "0.0.0-2",
34+
"@angular/http": "0.0.0-3",
35+
"@angular/platform-browser": "0.0.0-3",
36+
"@angular/platform-browser-dynamic": "0.0.0-3",
3737

3838
"es6-promise": "^3.0.2",
3939
"es6-shim": "^0.35.0",

src/components/checkbox/check.spec.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {it, ddescribe, beforeEach, inject, async} from '@angular/core/testing';
2+
import {FORM_DIRECTIVES, NgModel, NgControlName, NgControlStatus, NgControl} from '@angular/common';
3+
import {TestComponentBuilder} from '@angular/compiler/testing';
4+
import {Component} from '@angular/core';
5+
import {By} from '@angular/platform-browser';
6+
import {MdCheckbox} from './checkbox';
7+
8+
ddescribe('MdCheckbox', () => {
9+
let builder: TestComponentBuilder;
10+
11+
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
12+
builder = tcb;
13+
}));
14+
15+
it('should apply appriate ngModel css classes', async(() => {
16+
builder.createAsync(CheckboxWithFormDirectives).then(fixture => {
17+
fixture.detectChanges();
18+
19+
let checkboxElement = fixture.debugElement.query(By.directive(MdCheckbox));
20+
let ngControl = <NgControl> checkboxElement.injector.get(NgControl);
21+
let testComponent = <CheckboxWithFormDirectives> fixture.debugElement.componentInstance;
22+
23+
fixture.whenStable().then(() => {
24+
expect(ngControl.valid).toBe(true);
25+
expect(ngControl.pristine).toBe(true);
26+
expect(ngControl.touched).toBe(false);
27+
}).then(() => {
28+
testComponent.isGood = true;
29+
fixture.detectChanges();
30+
return fixture.whenStable();
31+
}).then(() => {
32+
fixture.detectChanges();
33+
return fixture.whenStable();
34+
}).then(() => {
35+
console.log(ngControl.pristine);
36+
fixture.whenStable().then(() => {
37+
console.log(ngControl.pristine);
38+
});
39+
});
40+
});
41+
}));
42+
});
43+
44+
45+
/** Simple component for testing an MdCheckbox with ngModel and ngControl. */
46+
@Component({
47+
selector: 'checkbox-with-form-directives',
48+
directives: [MdCheckbox, FORM_DIRECTIVES, NgModel],
49+
template: `
50+
<form>
51+
<md-checkbox ngControl="cb" [(ngModel)]="isGood">Be good</md-checkbox>
52+
</form>
53+
`,
54+
})
55+
class CheckboxWithFormDirectives {
56+
isGood: boolean = false;
57+
}

src/components/checkbox/checkbox.spec.ts

Lines changed: 135 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
import {
2-
it,
2+
it, iit, xit,
33
describe,
44
expect,
55
beforeEach,
66
fakeAsync,
7+
async,
78
inject,
89
tick,
10+
flushMicrotasks,
911
} from '@angular/core/testing';
1012
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
1113
import {Component, DebugElement, EventEmitter} from '@angular/core';
1214
import {By} from '@angular/platform-browser';
1315

1416
import {MdCheckbox} from './checkbox';
1517

16-
// IE11 does not support event constructors, so we need to perform this check.
17-
var BROWSER_SUPPORTS_EVENT_CONSTRUCTORS: boolean = (function() {
18-
// See: https://github.com/rauschma/event_constructors_check/blob/gh-pages/index.html#L39
19-
try {
20-
return new Event('submit', { bubbles: false }).bubbles === false &&
21-
new Event('submit', { bubbles: true }).bubbles === true;
22-
} catch (e) {
23-
return false;
24-
}
25-
})();
26-
2718
export function main() {
2819
describe('MdCheckbox', function() {
2920
var builder: TestComponentBuilder;
@@ -477,63 +468,130 @@ export function main() {
477468
});
478469
});
479470

471+
describe('normal', () => {
472+
xit('should support ngModel and ngControl', fakeAsync(() => {
473+
let fixture: ComponentFixture;
474+
builder.createAsync(CheckboxWithFormDirectives).then(f => {
475+
console.log('HERE');
476+
fixture = f;
477+
});
478+
479+
flushMicrotasks();
480+
flushMicrotasks();
481+
482+
console.log('FIX ', fixture);
483+
}));
484+
485+
xit('should support ngModel and ngControl', () => {
486+
return builder.createAsync(CheckboxWithFormDirectives).then(fixture => {
487+
debugger;
488+
let testComponentInstance = fixture.debugElement.componentInstance;
489+
let checkboxElement = fixture.debugElement.query(By.directive(MdCheckbox));
490+
let invalidMsg = checkboxElement.query(By.css('#invalid-msg'));
491+
fixture.detectChanges();
492+
493+
return fixture.whenStable().then(() => {
494+
console.log('making assertions');
495+
expect(checkboxElement.nativeElement.className).toContain('ng-untouched');
496+
expect(checkboxElement.nativeElement.className).toContain('ng-pristine');
497+
expect(invalidMsg.nativeElement.hidden).toBe(true);
498+
});
499+
500+
// expect(checkboxElement.nativeElement.className).toContain('ng-untouched');
501+
// expect(checkboxElement.nativeElement.className).toContain('ng-pristine');
502+
// expect(invalidMsg.nativeElement.hidden).toBe(true);
503+
504+
// testComponentInstance.model.isChecked = true;
505+
// fixture.detectChanges();
506+
507+
// expect(checkboxElement.nativeElement.className).toContain('md-checkbox-checked');
508+
// expect(checkboxElement.nativeElement.className).toContain('ng-dirty');
509+
// expect(checkboxElement.nativeElement.className).toContain('ng-valid');
510+
511+
// dispatchBlurEvent(checkboxElement.nativeElement);
512+
});
513+
});
514+
515+
});
516+
480517
describe('usage as a form control', function() {
481518
var fixture: ComponentFixture;
482-
var controller: CheckboxFormcontrolController;
519+
var controller: CheckboxWithFormDirectives;
483520

484-
beforeEach(function(done: () => void) {
485-
builder.createAsync(CheckboxFormcontrolController).then(function(f) {
521+
beforeEach(async(() => {
522+
builder.createAsync(CheckboxWithFormDirectives).then(function(f) {
486523
fixture = f;
487524
controller = fixture.componentInstance;
488525
fixture.detectChanges();
489-
}).then(done).catch(done);
490-
});
526+
});
527+
}));
491528

492529
// NOTE(traviskaufman): This test is not that elegant, but I have not found a better way
493530
// to test through ngModel as of now.
494531
// See: https://github.com/angular/angular/issues/7409
495-
it('supports ngModel/ngControl', function(done: () => void) {
532+
xit('supports ngModel/ngControl', fakeAsync(() => {
533+
debugger;
496534
var el: DebugElement;
497535
var invalidMsg: DebugElement;
498536

499-
fakeAsync(function() {
500-
el = fixture.debugElement.query(By.css('.md-checkbox'));
501-
invalidMsg = fixture.debugElement.query(By.css('#invalid-msg'));
537+
el = fixture.debugElement.query(By.css('.md-checkbox'));
538+
invalidMsg = fixture.debugElement.query(By.css('#invalid-msg'));
502539

503-
fixture.detectChanges();
504-
tick();
505-
expect(el.nativeElement.className).toContain('ng-untouched');
506-
expect(el.nativeElement.className).toContain('ng-pristine');
507-
expect(invalidMsg.nativeElement.hidden).toBe(true);
540+
fixture.detectChanges();
541+
flushMicrotasks();
508542

509-
controller.model.isChecked = true;
510-
fixture.detectChanges();
511-
tick();
512-
fixture.detectChanges();
543+
flushMicrotasks();
544+
fixture.detectChanges();
513545

514-
expect(el.nativeElement.className).toContain('md-checkbox-checked');
515-
expect(el.nativeElement.className).toContain('ng-dirty');
516-
expect(el.nativeElement.className).toContain('ng-valid');
517-
518-
var blur: Event;
519-
if (BROWSER_SUPPORTS_EVENT_CONSTRUCTORS) {
520-
blur = new Event('blur');
521-
} else {
522-
blur = document.createEvent('UIEvent');
523-
(<UIEvent>blur).initUIEvent('blur', true, true, window, 0);
524-
}
525-
el.nativeElement.dispatchEvent(blur);
526-
fixture.detectChanges();
527-
tick();
528-
expect(el.nativeElement.className).toContain('ng-touched');
529-
})();
546+
expect(el.nativeElement.className).toContain('ng-untouched');
547+
expect(el.nativeElement.className).toContain('ng-pristine');
548+
expect(invalidMsg.nativeElement.hidden).toBe(true);
549+
550+
controller.model.isChecked = true;
551+
552+
flushMicrotasks();
553+
fixture.detectChanges();
554+
555+
console.log('one');
556+
557+
fixture.whenStable().then(() => {
558+
console.log('stable');
559+
});
560+
561+
console.log('two');
562+
563+
//flushMicrotasks();
564+
565+
console.log('three');
566+
567+
//tick();
568+
569+
console.log('four');
570+
571+
expect(el.nativeElement.className).toContain('md-checkbox-checked');
572+
expect(el.nativeElement.className).toContain('ng-dirty');
573+
expect(el.nativeElement.className).toContain('ng-valid');
574+
575+
var blur: Event;
576+
if (BROWSER_SUPPORTS_EVENT_CONSTRUCTORS) {
577+
blur = new Event('blur');
578+
} else {
579+
blur = document.createEvent('UIEvent');
580+
(<UIEvent>blur).initUIEvent('blur', true, true, window, 0);
581+
}
582+
el.nativeElement.dispatchEvent(blur);
583+
fixture.detectChanges();
584+
//tick();
585+
expect(el.nativeElement.className).toContain('ng-touched');
530586

531587
let onceChanged = controller.model.waitForChange();
532588
click(el, fixture);
533589
onceChanged.then(function() {
534590
expect(controller.model.isChecked).toBe(false);
535-
}).then(done).catch(done);
536-
});
591+
});
592+
593+
//flushMicrotasks();
594+
}));
537595
});
538596

539597
describe('applying transition classes', function() {
@@ -780,18 +838,16 @@ class FormcontrolModel {
780838
}
781839

782840
@Component({
783-
selector: 'checkbox-formcontrol-controller',
841+
selector: 'checkbox-with-form-directives',
784842
template: `
785843
<form>
786-
<md-checkbox [(ngModel)]="model.isChecked"
787-
ngControl="cb" #cb="ngForm">
788-
</md-checkbox>
844+
<md-checkbox [(ngModel)]="model.isChecked" ngControl="cb" #cb="ngForm">Extra fun</md-checkbox>
789845
<p id="invalid-msg" [hidden]="cb.valid || cb.pristine">INVALID!</p>
790846
</form>
791847
`,
792848
directives: [MdCheckbox]
793849
})
794-
class CheckboxFormcontrolController {
850+
class CheckboxWithFormDirectives {
795851
model = new FormcontrolModel();
796852
}
797853

@@ -810,3 +866,29 @@ class CheckboxEndAlignedController {}
810866
class CheckboxBarebonesController {
811867
public isIndeterminate: boolean = false;
812868
}
869+
870+
// TODO(jelbourn): move things below here into common testing utilities.
871+
872+
// IE11 does not support event constructors, so we need to perform this check.
873+
var BROWSER_SUPPORTS_EVENT_CONSTRUCTORS: boolean = (function() {
874+
// See: https://github.com/rauschma/event_constructors_check/blob/gh-pages/index.html#L39
875+
try {
876+
return new Event('submit', { bubbles: false }).bubbles === false &&
877+
new Event('submit', { bubbles: true }).bubbles === true;
878+
} catch (e) {
879+
return false;
880+
}
881+
})();
882+
883+
884+
/** Dispatches a `blur` event on the given element. */
885+
function dispatchBlurEvent(element: HTMLElement) {
886+
var blur: Event;
887+
if (BROWSER_SUPPORTS_EVENT_CONSTRUCTORS) {
888+
blur = new Event('blur');
889+
} else {
890+
blur = document.createEvent('UIEvent');
891+
(<UIEvent>blur).initUIEvent('blur', true, true, window, 0);
892+
}
893+
element.dispatchEvent(blur);
894+
};

src/components/checkbox/checkbox.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ export class MdCheckbox implements ControlValueAccessor {
111111
/** Called when the checkbox is blurred. Needed to properly implement ControlValueAccessor. */
112112
onTouched: () => any = () => {};
113113

114+
/** Whether the `checked` state has been set to its initial value. */
115+
private _isInitialized: boolean = false;
116+
114117
private _currentAnimationClass: string = '';
115118

116119
private _currentCheckState: TransitionCheckState = TransitionCheckState.Init;
@@ -132,11 +135,20 @@ export class MdCheckbox implements ControlValueAccessor {
132135
}
133136

134137
set checked(checked: boolean) {
135-
this._indeterminate = false;
136-
this._checked = checked;
137-
this._transitionCheckState(
138-
this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
139-
this.change.emit(this._checked);
138+
let wasAlreadyInitialized = this._isInitialized;
139+
this._isInitialized = true;
140+
141+
if (checked != this.checked) {
142+
this._indeterminate = false;
143+
this._checked = checked;
144+
this._transitionCheckState(
145+
this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
146+
147+
// Only fire a change event if this isn't the first time the checked property is ever set.
148+
if (wasAlreadyInitialized) {
149+
this.change.emit(this._checked);
150+
}
151+
}
140152
}
141153

142154
/**
@@ -209,7 +221,11 @@ export class MdCheckbox implements ControlValueAccessor {
209221
if (this._changeSubscription) {
210222
this._changeSubscription.unsubscribe();
211223
}
212-
this._changeSubscription = <{unsubscribe: () => any}>this.change.subscribe(fn);
224+
this._changeSubscription = <{unsubscribe: () => any}>this.change.subscribe(() => {
225+
debugger;
226+
console.log('CHANGE FN INVOKED');
227+
fn();
228+
});
213229
}
214230

215231
/** Implemented as part of ControlValueAccessor. */

0 commit comments

Comments
 (0)