|
| 1 | +import { LOCALE_ID } from '@angular/core'; |
1 | 2 | import { inject, TestBed } from '@angular/core/testing'; |
2 | | - |
3 | 3 | import { DocumentRef, WindowRef } from '../../utils/browser-globals'; |
4 | | - |
5 | 4 | import { GoogleMapsScriptProtocol, LAZY_MAPS_API_CONFIG, LazyMapsAPILoader, LazyMapsAPILoaderConfigLiteral } from './lazy-maps-api-loader'; |
6 | 5 | import { MapsAPILoader } from './maps-api-loader'; |
7 | 6 |
|
@@ -32,6 +31,7 @@ describe('Service: LazyMapsAPILoader', () => { |
32 | 31 | {provide: MapsAPILoader, useClass: LazyMapsAPILoader}, |
33 | 32 | {provide: WindowRef, useValue: windowRef}, |
34 | 33 | {provide: DocumentRef, useValue: documentRef}, |
| 34 | + {provide: LOCALE_ID, useValue: 'en-US'}, |
35 | 35 | ], |
36 | 36 | }); |
37 | 37 | }); |
@@ -83,24 +83,51 @@ describe('Service: LazyMapsAPILoader', () => { |
83 | 83 | {provide: MapsAPILoader, useClass: LazyMapsAPILoader}, |
84 | 84 | {provide: WindowRef, useValue: windowRef}, |
85 | 85 | {provide: DocumentRef, useValue: documentRef}, |
| 86 | + {provide: LOCALE_ID, useValue: 'en-US'}, |
86 | 87 | {provide: LAZY_MAPS_API_CONFIG, useValue: lazyLoadingConf}, |
87 | 88 | ], |
88 | 89 | }); |
89 | 90 |
|
90 | | - inject([MapsAPILoader], (loader: LazyMapsAPILoader) => { |
91 | | - interface Script { |
92 | | - src?: string; |
93 | | - async?: boolean; |
94 | | - defer?: boolean; |
95 | | - type?: string; |
96 | | - } |
97 | | - const scriptElem: Script = {}; |
98 | | - (doc.createElement as jest.Mock).mockReturnValue(scriptElem); |
| 91 | + const loader: LazyMapsAPILoader = TestBed.get(MapsAPILoader); |
99 | 92 |
|
100 | | - loader.load(); |
101 | | - expect(doc.createElement).toHaveBeenCalled(); |
102 | | - expect(scriptElem.src).toContain('http://maps.googleapis.com/maps/api/js'); |
103 | | - expect(doc.body.appendChild).toHaveBeenCalledWith(scriptElem); |
| 93 | + interface Script { |
| 94 | + src?: string; |
| 95 | + async?: boolean; |
| 96 | + defer?: boolean; |
| 97 | + type?: string; |
| 98 | + } |
| 99 | + const scriptElem: Script = {}; |
| 100 | + (doc.createElement as jest.Mock).mockReturnValue(scriptElem); |
| 101 | + |
| 102 | + loader.load(); |
| 103 | + expect(doc.createElement).toHaveBeenCalled(); |
| 104 | + expect(scriptElem.src).toContain('http://maps.googleapis.com/maps/api/js'); |
| 105 | + expect(doc.body.appendChild).toHaveBeenCalledWith(scriptElem); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should load language based on locale', () => { |
| 109 | + TestBed.configureTestingModule({ |
| 110 | + providers: [ |
| 111 | + {provide: MapsAPILoader, useClass: LazyMapsAPILoader}, |
| 112 | + {provide: WindowRef, useValue: windowRef}, |
| 113 | + {provide: DocumentRef, useValue: documentRef}, |
| 114 | + {provide: LOCALE_ID, useValue: 'es'}, |
| 115 | + ], |
104 | 116 | }); |
| 117 | + |
| 118 | + const loader: LazyMapsAPILoader = TestBed.get(MapsAPILoader); |
| 119 | + interface Script { |
| 120 | + src?: string; |
| 121 | + async?: boolean; |
| 122 | + defer?: boolean; |
| 123 | + type?: string; |
| 124 | + } |
| 125 | + const scriptElem: Script = {}; |
| 126 | + (doc.createElement as jest.Mock).mockReturnValue(scriptElem); |
| 127 | + |
| 128 | + loader.load(); |
| 129 | + expect(doc.createElement).toHaveBeenCalled(); |
| 130 | + const url = new URL(scriptElem.src); |
| 131 | + expect(url.searchParams.get('language')).toEqual('es'); |
105 | 132 | }); |
106 | 133 | }); |
0 commit comments