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' ;
13
1
import { 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' ;
15
7
import {
16
8
MatAutocompleteModule ,
17
9
MatInputModule ,
18
- MatSlideToggleModule
10
+ MatSlideToggleModule ,
11
+ MatSnackBar ,
19
12
} 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' ;
20
18
import { 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' ;
22
21
23
22
const exampleKey = 'autocomplete-overview' ;
24
23
@@ -51,30 +50,30 @@ describe('ExampleViewer', () => {
51
50
component = fixture . componentInstance ;
52
51
} ) ;
53
52
54
- it ( 'should toggle showSource boolean' , ( ) => {
53
+ it ( 'should toggle showSource boolean' , async ( ( ) => {
55
54
fixture . detectChanges ( ) ;
56
55
expect ( component . showSource ) . toBe ( false ) ;
57
56
component . toggleSourceView ( ) ;
58
57
expect ( component . showSource ) . toBe ( true ) ;
59
- } ) ;
58
+ } ) ) ;
60
59
61
- it ( 'should set and return example properly' , ( ) => {
60
+ it ( 'should set and return example properly' , async ( ( ) => {
62
61
component . example = exampleKey ;
63
62
fixture . detectChanges ( ) ;
64
63
const data = component . exampleData ;
65
64
// TODO(jelbourn): remove `as any` once LiveExample is updated to have optional members.
66
65
expect ( data ) . toEqual ( EXAMPLE_COMPONENTS [ exampleKey ] as any ) ;
67
- } ) ;
66
+ } ) ) ;
68
67
69
- it ( 'should log message about missing example' , ( ) => {
68
+ it ( 'should log message about missing example' , async ( ( ) => {
70
69
spyOn ( console , 'log' ) ;
71
70
component . example = 'foobar' ;
72
71
fixture . detectChanges ( ) ;
73
72
expect ( console . log ) . toHaveBeenCalled ( ) ;
74
73
expect ( console . log ) . toHaveBeenCalledWith ( 'MISSING EXAMPLE: ' , 'foobar' ) ;
75
- } ) ;
74
+ } ) ) ;
76
75
77
- it ( 'should return assets path for example based on extension' , ( ) => {
76
+ it ( 'should return assets path for example based on extension' , async ( ( ) => {
78
77
// set example
79
78
component . example = exampleKey ;
80
79
fixture . detectChanges ( ) ;
@@ -87,7 +86,7 @@ describe('ExampleViewer', () => {
87
86
const actual = component . exampleFileUrl ( ext ) ;
88
87
expect ( actual ) . toEqual ( expected ) ;
89
88
} ) ;
90
- } ) ;
89
+ } ) ) ;
91
90
92
91
describe ( 'copy button' , ( ) => {
93
92
let button : HTMLElement ;
@@ -103,33 +102,33 @@ describe('ExampleViewer', () => {
103
102
button = btnDe ? btnDe . nativeElement : null ;
104
103
} ) ;
105
104
106
- it ( 'should call copier service when clicked' , ( ) => {
105
+ it ( 'should call copier service when clicked' , ( ( ) => {
107
106
const copierService : CopierService = TestBed . get ( CopierService ) ;
108
107
const spy = spyOn ( copierService , 'copyText' ) ;
109
108
expect ( spy . calls . count ( ) ) . toBe ( 0 , 'before click' ) ;
110
109
button . click ( ) ;
111
110
expect ( spy . calls . count ( ) ) . toBe ( 1 , 'after click' ) ;
112
111
expect ( spy . calls . argsFor ( 0 ) [ 0 ] ) . toBe ( 'my docs page' , 'click content' ) ;
113
- } ) ;
112
+ } ) ) ;
114
113
115
- it ( 'should display a message when copy succeeds' , ( ) => {
114
+ it ( 'should display a message when copy succeeds' , ( ( ) => {
116
115
const snackBar : MatSnackBar = TestBed . get ( MatSnackBar ) ;
117
116
const copierService : CopierService = TestBed . get ( CopierService ) ;
118
117
spyOn ( snackBar , 'open' ) ;
119
118
spyOn ( copierService , 'copyText' ) . and . returnValue ( true ) ;
120
119
button . click ( ) ;
121
120
expect ( snackBar . open ) . toHaveBeenCalledWith ( 'Code copied' , '' , { duration : 2500 } ) ;
122
- } ) ;
121
+ } ) ) ;
123
122
124
- it ( 'should display an error when copy fails' , ( ) => {
123
+ it ( 'should display an error when copy fails' , ( ( ) => {
125
124
const snackBar : MatSnackBar = TestBed . get ( MatSnackBar ) ;
126
125
const copierService : CopierService = TestBed . get ( CopierService ) ;
127
126
spyOn ( snackBar , 'open' ) ;
128
127
spyOn ( copierService , 'copyText' ) . and . returnValue ( false ) ;
129
128
button . click ( ) ;
130
129
expect ( snackBar . open )
131
130
. toHaveBeenCalledWith ( 'Copy failed. Please try again!' , '' , { duration : 2500 } ) ;
132
- } ) ;
131
+ } ) ) ;
133
132
} ) ;
134
133
135
134
} ) ;
0 commit comments