Skip to content

chore(forms): update components to forms 0.2.0 #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/router": "v3.0.0-alpha.8",
"@angular/forms": "^0.1.0",
"@angular/forms": "^0.2.0",
"core-js": "^2.4.0",
"hammerjs": "^2.0.8",
"rxjs": "5.0.0-beta.6",
Expand Down
2 changes: 1 addition & 1 deletion src/components/checkbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"homepage": "https://github.com/angular/material2#readme",
"peerDependencies": {
"@angular2-material/core": "2.0.0-alpha.6-2",
"@angular/forms": "^0.1.0"
"@angular/forms": "^0.2.0"
}
}
18 changes: 12 additions & 6 deletions src/components/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,25 @@ describe('MdInput', function () {
});
}));


// TODO(kara): update when core/testing adds fix
it('support ngModel', async(() => {
builder.createAsync(MdInputBaseTestController)
.then(fixture => {
fixture.detectChanges();
let instance = fixture.componentInstance;
let component = fixture.debugElement.query(By.directive(MdInput)).componentInstance;
let el: HTMLInputElement = fixture.debugElement.query(By.css('input')).nativeElement;

instance.model = 'hello';
fixture.detectChanges();
expect(el.value).toEqual('hello');
fixture.whenStable().then(() => {

component.value = 'world';
fixture.detectChanges();
expect(el.value).toEqual('world');
// this workaround is temp, see https://github.com/angular/angular/issues/10148
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(el.value).toBe('hello');
});
});
});
}));

Expand Down Expand Up @@ -80,7 +84,9 @@ describe('MdInput', function () {

instance.model = 'hello';
fixture.detectChanges();
expect(inputInstance.characterCount).toEqual(5);
fixture.whenStable().then(() => {
expect(inputInstance.characterCount).toEqual(5);
});
});
}));

Expand Down
2 changes: 1 addition & 1 deletion src/components/input/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"homepage": "https://github.com/angular/material2#readme",
"peerDependencies": {
"@angular2-material/core": "2.0.0-alpha.6-2",
"@angular/forms": "^0.1.0"
"@angular/forms": "^0.2.0"
}
}
2 changes: 1 addition & 1 deletion src/components/radio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"homepage": "https://github.com/angular/material2#readme",
"peerDependencies": {
"@angular2-material/core": "2.0.0-alpha.6-2",
"@angular/forms": "^0.1.0"
"@angular/forms": "^0.2.0"
}
}
2 changes: 1 addition & 1 deletion src/components/slide-toggle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"homepage": "https://github.com/angular/material2#readme",
"peerDependencies": {
"@angular2-material/core": "2.0.0-alpha.6-2",
"@angular/forms": "^0.1.0"
"@angular/forms": "^0.2.0"
}
}
78 changes: 42 additions & 36 deletions src/components/slide-toggle/slide-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ describe('MdSlideToggle', () => {
});
}));


it('should update the model correctly', () => {
// TODO(kara); update when core/testing adds fix
it('should update the model correctly', async(() => {
expect(slideToggleElement.classList).not.toContain('md-checked');

testComponent.slideModel = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(slideToggleElement.classList).toContain('md-checked');
});

expect(slideToggleElement.classList).toContain('md-checked');
});
}));

it('should apply class based on color attribute', () => {
testComponent.slideColor = 'primary';
Expand Down Expand Up @@ -127,11 +130,11 @@ describe('MdSlideToggle', () => {
expect(testComponent.onSlideClick).toHaveBeenCalledTimes(1);
});

it('should trigger the change event properly', async(() => {
it('should trigger the change event properly', async(() => {
expect(inputElement.checked).toBe(false);
expect(slideToggleElement.classList).not.toContain('md-checked');

labelElement.click();
labelElement.click();
fixture.detectChanges();

expect(inputElement.checked).toBe(true);
Expand All @@ -140,33 +143,33 @@ describe('MdSlideToggle', () => {
// Wait for the fixture to become stable, because the EventEmitter for the change event,
// will only fire after the zone async change detection has finished.
fixture.whenStable().then(() => {
// The change event shouldn't fire, because the value change was not caused
// by any interaction.
// The change event shouldn't fire, because the value change was not caused
// by any interaction.
expect(testComponent.onSlideChange).toHaveBeenCalledTimes(1);
});

}));

it('should not trigger the change event by changing the native value', async(() => {
expect(inputElement.checked).toBe(false);
expect(slideToggleElement.classList).not.toContain('md-checked');

testComponent.slideChecked = true;
fixture.detectChanges();

expect(inputElement.checked).toBe(true);
expect(slideToggleElement.classList).toContain('md-checked');

// Wait for the fixture to become stable, because the EventEmitter for the change event,
// will only fire after the zone async change detection has finished.
fixture.whenStable().then(() => {
// The change event shouldn't fire, because the value change was not caused
// by any interaction.
expect(testComponent.onSlideChange).not.toHaveBeenCalled();
});

}));

it('should not trigger the change event by changing the native value', async(() => {
expect(inputElement.checked).toBe(false);
expect(slideToggleElement.classList).not.toContain('md-checked');
testComponent.slideChecked = true;
fixture.detectChanges();
expect(inputElement.checked).toBe(true);
expect(slideToggleElement.classList).toContain('md-checked');
// Wait for the fixture to become stable, because the EventEmitter for the change event,
// will only fire after the zone async change detection has finished.
fixture.whenStable().then(() => {
// The change event shouldn't fire, because the value change was not caused
// by any interaction.
expect(testComponent.onSlideChange).not.toHaveBeenCalled();
});
}));
it('should not trigger the change event on initialization', async(() => {
expect(inputElement.checked).toBe(false);
expect(slideToggleElement.classList).not.toContain('md-checked');
Expand All @@ -180,8 +183,8 @@ describe('MdSlideToggle', () => {
// Wait for the fixture to become stable, because the EventEmitter for the change event,
// will only fire after the zone async change detection has finished.
fixture.whenStable().then(() => {
// The change event shouldn't fire, because the native input element is not focused.
expect(testComponent.onSlideChange).not.toHaveBeenCalled();
// The change event shouldn't fire, because the native input element is not focused.
expect(testComponent.onSlideChange).not.toHaveBeenCalled();
});

}));
Expand Down Expand Up @@ -315,17 +318,20 @@ describe('MdSlideToggle', () => {
expect(slideToggleElement.classList).not.toContain('md-checked');
});

it('should not set the control to touched when changing the model', () => {
// TODO(kara): update when core/testing adds fix
it('should not set the control to touched when changing the model', async(() => {
// The control should start off with being untouched.
expect(slideToggleControl.touched).toBe(false);

testComponent.slideModel = true;
fixture.detectChanges();

expect(slideToggleControl.touched).toBe(false);
expect(slideToggle.checked).toBe(true);
expect(slideToggleElement.classList).toContain('md-checked');
});
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(slideToggleControl.touched).toBe(false);
expect(slideToggle.checked).toBe(true);
expect(slideToggleElement.classList).toContain('md-checked');
});
}));

it('should correctly set the slide-toggle to checked on focus', () => {
expect(slideToggleElement.classList).not.toContain('md-slide-toggle-focused');
Expand Down