Error: No provider for MdDialogRef!
import { UserModule } from './user.module';
import { MdDialogModule, MdDialogRef } from '@angular/material';
import { MdIconModule } from '@angular/material';
import { TestBed, async, inject } from '@angular/core/testing';
import { UserSubscriptionComponent, SubscribeDialogComponent } from './subscription.component';
fdescribe('Component: UserSubscription', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
MdIconModule.forRoot(),
MdDialogModule.forRoot(),
UserModule.forRoot()
]
});
}); it('should render the dialog', async(inject([MdDialogRef], (ref: MdDialogRef<SubscribeDialogComponent>) => {
let component = TestBed.createComponent(SubscribeDialogComponent);
component.detectChanges();
expect(component.nativeElement.textContent).toContain('Upgrade to Premier for $95/yr');
})));@Component({
selector: 'mv-subscribe-dialog',
templateUrl: './subscribe-dialog.component.html',
styleUrls: ['./subscription-dialog.component.css']
})
export class SubscribeDialogComponent {
public card: PaymentMethod;
loading: boolean = false;
years: Array<string>;
months: Array<string>;
states: Array<string>;
countries: Array<string>;
constructor(
public dialogRef: MdDialogRef<SubscribeDialogComponent>,
private billing: BillingService,
private messages: MessageService
) {Error: Can't resolve all parameters for MdDialogRef: (?).
import { UserModule } from './user.module';
import { MdDialogModule, MdDialog, MdDialogConfig, MdDialogRef, MdIconModule, OverlayContainer } from '@angular/material';import { TestBed, async, inject } from '@angular/core/testing';import { FormBuilder, FormGroup } from '@angular/forms';import { UserSubscriptionComponent, SubscribeDialogComponent } from './subscription.component';
describe('Component: UserSubscription', () => { let overlayContainerElement: HTMLElement;
beforeEach(() => { TestBed.configureTestingModule({ imports: [ MdIconModule.forRoot(), MdDialogModule.forRoot(), UserModule.forRoot() ], providers: [{ provide: OverlayContainer, useFactory: () => { overlayContainerElement = document.createElement('div'); return { getContainerElement: () => overlayContainerElement }; } }] }); });
it('should render a response', () => { let component = TestBed.createComponent(UserSubscriptionComponent); component.detectChanges(); expect(component.nativeElement.textContent).toContain('Upgrade for $1!'); });
it('should open a dialog when upgrade is clicked', () => { let component = TestBed.createComponent(UserSubscriptionComponent); expect(component.componentInstance.dialogRef).not.toBeDefined(); document.getElementById('upgrade-action').click(); expect(component.componentInstance.dialogRef).toBeDefined(); });
it('should render the dialog correctly', () => { let component = TestBed.createComponent(UserSubscriptionComponent); component.componentInstance.upgrade(); let dialogRef = component.componentInstance.dialogRef; expect(overlayContainerElement.textContent).toContain('Card Number'); expect(overlayContainerElement.textContent).toContain('Expiration Date'); expect(overlayContainerElement.textContent).toContain('CVV'); expect(overlayContainerElement.textContent).toContain('Cardholder Name'); expect(overlayContainerElement.textContent).toContain('Address 1'); expect(overlayContainerElement.textContent).toContain('Address 2'); expect(overlayContainerElement.textContent).toContain('City'); expect(overlayContainerElement.textContent).toContain('State'); expect(overlayContainerElement.textContent).toContain('Postal Code'); });
it('submits the upgrade request fields', inject([BillingService], (billing: BillingService) => { let component = TestBed.createComponent(UserSubscriptionComponent); component.componentInstance.upgrade(); let dialogRef = component.componentInstance.dialogRef; let dialog = dialogRef.componentInstance; let paymentMethod = { accountKey: 'A00000020', creditCardType: 'Visa', creditCardNumber: '4111111111111111', expirationMonth: '10', expirationYear: '2020', securityCode: '911', cardHolderInfo: { cardHolderName: 'Jeff Moss', addressLine1: '1234 Main St', addressLine2: '', city: 'Salt Lake City', state: 'UT', zipCode: '84123', country: 'USA', phone: '8015551234', email: 'je...@example.com' } }; let observable = { subscribe: (callback) => { callback({ success: true }); } }; component.detectChanges(); let form = <FormGroup> dialog.paymentMethodForm; form.controls['creditCardNumber'].setValue('4111111111111111'); form.controls['expirationMonth'].setValue('10'); form.controls['expirationYear'].setValue('2020'); form.controls['securityCode'].setValue('911'); let group = <FormGroup> dialog.paymentMethodForm.controls['cardHolderInfo']; group.controls['cardHolderName'].setValue('Jeff Moss'); group.controls['addressLine1'].setValue('1234 Main St'); group.controls['city'].setValue('Salt Lake City'); group.controls['state'].setValue('UT'); group.controls['country'].setValue('USA'); group.controls['zipCode'].setValue('84123'); group.controls['phone'].setValue('8015551234'); group.controls['email'].setValue('je...@example.com'); spyOn(billing, 'createPaymentMethod').and.returnValue(observable); dialog.processUpgrade(); expect(billing.createPaymentMethod).toHaveBeenCalledWith(paymentMethod); }));});
upgrade () {
if (!this.dialogRef) {
let config = new MdDialogConfig();
config.viewContainerRef = this.viewContainerRef;
this.dialogRef = this.dialog.open(SubscribeDialogComponent, config);
this.dialogRef.afterClosed().subscribe(
result => this.dialogRef = null
);
}
}
To view this discussion on the web visit https://groups.google.com/d/msgid/angular-material2/a8b6de7e-801a-4ad0-8cc6-90dc7f7b75b2%40googlegroups.com.--
You received this message because you are subscribed to a topic in the Google Groups "angular-material2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular-material2/xo29ERf0Mx4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular-material2+unsubscribe@googlegroups.com.
To post to this group, send email to angular-material2@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to angular-materi...@googlegroups.com.
To post to this group, send email to angular-...@googlegroups.com.
TestBed.configureTestingModule({
declarations: [ DialogComponent],
});
TestBed.overrideModule(BrowserDynamicTestingModule, {
set: {
entryComponents: [ DialogComponent],
},
});beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ConfirmDialogComponent], imports: [MdDialogModule.forRoot()], providers: [ { provide: OverlayContainer, useFactory: () => { overlayContainerElement = document.createElement('div'); return { getContainerElement: () => overlayContainerElement }; } } ], }) .overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [ConfirmDialogComponent], }, }) .compileComponents(); }));