1- import { ReactiveFormsModule } from '@angular/forms' ;
2- import { async , inject , ComponentFixture , TestBed } from '@angular/core/testing' ;
3- import { MockBackend } from '@angular/http/testing' ;
4- import { Response , ResponseOptions } from '@angular/http' ;
5- import { By } from '@angular/platform-browser' ;
6-
7- import { EXAMPLE_COMPONENTS } from '@angular/material-examples' ;
8- import { ExampleViewer } from './example-viewer' ;
9- import { DocsAppTestingModule } from '../../testing/testing-module' ;
10- import { DocViewerModule } from '../doc-viewer/doc-viewer-module' ;
11- import { FormsModule } from '@angular/forms' ;
12- import { NgModule } from '@angular/core' ;
131import { CommonModule } from '@angular/common' ;
14- import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
2+ import { NgModule } from '@angular/core' ;
3+ import { async , ComponentFixture , inject , TestBed } from '@angular/core/testing' ;
4+ import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
5+ import { Response , ResponseOptions } from '@angular/http' ;
6+ import { MockBackend } from '@angular/http/testing' ;
157import {
168 MatAutocompleteModule ,
179 MatInputModule ,
18- MatSlideToggleModule
10+ MatSlideToggleModule ,
11+ MatSnackBar ,
1912} from '@angular/material' ;
13+
14+ import { EXAMPLE_COMPONENTS } from '@angular/material-examples' ;
15+ import { By } from '@angular/platform-browser' ;
16+ import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
17+ import { DocsAppTestingModule } from '../../testing/testing-module' ;
2018import { CopierService } from '../copier/copier.service' ;
21- import { MatSnackBar } from '@angular/material' ;
19+ import { DocViewerModule } from '../doc-viewer/doc-viewer-module' ;
20+ import { ExampleViewer } from './example-viewer' ;
2221
2322const exampleKey = 'autocomplete-overview' ;
2423
@@ -51,30 +50,30 @@ describe('ExampleViewer', () => {
5150 component = fixture . componentInstance ;
5251 } ) ;
5352
54- it ( 'should toggle showSource boolean' , ( ) => {
53+ it ( 'should toggle showSource boolean' , async ( ( ) => {
5554 fixture . detectChanges ( ) ;
5655 expect ( component . showSource ) . toBe ( false ) ;
5756 component . toggleSourceView ( ) ;
5857 expect ( component . showSource ) . toBe ( true ) ;
59- } ) ;
58+ } ) ) ;
6059
61- it ( 'should set and return example properly' , ( ) => {
60+ it ( 'should set and return example properly' , async ( ( ) => {
6261 component . example = exampleKey ;
6362 fixture . detectChanges ( ) ;
6463 const data = component . exampleData ;
6564 // TODO(jelbourn): remove `as any` once LiveExample is updated to have optional members.
6665 expect ( data ) . toEqual ( EXAMPLE_COMPONENTS [ exampleKey ] as any ) ;
67- } ) ;
66+ } ) ) ;
6867
69- it ( 'should log message about missing example' , ( ) => {
68+ it ( 'should log message about missing example' , async ( ( ) => {
7069 spyOn ( console , 'log' ) ;
7170 component . example = 'foobar' ;
7271 fixture . detectChanges ( ) ;
7372 expect ( console . log ) . toHaveBeenCalled ( ) ;
7473 expect ( console . log ) . toHaveBeenCalledWith ( 'MISSING EXAMPLE: ' , 'foobar' ) ;
75- } ) ;
74+ } ) ) ;
7675
77- it ( 'should return assets path for example based on extension' , ( ) => {
76+ it ( 'should return assets path for example based on extension' , async ( ( ) => {
7877 // set example
7978 component . example = exampleKey ;
8079 fixture . detectChanges ( ) ;
@@ -87,7 +86,7 @@ describe('ExampleViewer', () => {
8786 const actual = component . exampleFileUrl ( ext ) ;
8887 expect ( actual ) . toEqual ( expected ) ;
8988 } ) ;
90- } ) ;
89+ } ) ) ;
9190
9291 describe ( 'copy button' , ( ) => {
9392 let button : HTMLElement ;
@@ -103,33 +102,33 @@ describe('ExampleViewer', () => {
103102 button = btnDe ? btnDe . nativeElement : null ;
104103 } ) ;
105104
106- it ( 'should call copier service when clicked' , ( ) => {
105+ it ( 'should call copier service when clicked' , ( ( ) => {
107106 const copierService : CopierService = TestBed . get ( CopierService ) ;
108107 const spy = spyOn ( copierService , 'copyText' ) ;
109108 expect ( spy . calls . count ( ) ) . toBe ( 0 , 'before click' ) ;
110109 button . click ( ) ;
111110 expect ( spy . calls . count ( ) ) . toBe ( 1 , 'after click' ) ;
112111 expect ( spy . calls . argsFor ( 0 ) [ 0 ] ) . toBe ( 'my docs page' , 'click content' ) ;
113- } ) ;
112+ } ) ) ;
114113
115- it ( 'should display a message when copy succeeds' , ( ) => {
114+ it ( 'should display a message when copy succeeds' , ( ( ) => {
116115 const snackBar : MatSnackBar = TestBed . get ( MatSnackBar ) ;
117116 const copierService : CopierService = TestBed . get ( CopierService ) ;
118117 spyOn ( snackBar , 'open' ) ;
119118 spyOn ( copierService , 'copyText' ) . and . returnValue ( true ) ;
120119 button . click ( ) ;
121120 expect ( snackBar . open ) . toHaveBeenCalledWith ( 'Code copied' , '' , { duration : 2500 } ) ;
122- } ) ;
121+ } ) ) ;
123122
124- it ( 'should display an error when copy fails' , ( ) => {
123+ it ( 'should display an error when copy fails' , ( ( ) => {
125124 const snackBar : MatSnackBar = TestBed . get ( MatSnackBar ) ;
126125 const copierService : CopierService = TestBed . get ( CopierService ) ;
127126 spyOn ( snackBar , 'open' ) ;
128127 spyOn ( copierService , 'copyText' ) . and . returnValue ( false ) ;
129128 button . click ( ) ;
130129 expect ( snackBar . open )
131130 . toHaveBeenCalledWith ( 'Copy failed. Please try again!' , '' , { duration : 2500 } ) ;
132- } ) ;
131+ } ) ) ;
133132 } ) ;
134133
135134} ) ;
0 commit comments