@@ -4,6 +4,7 @@ import $ from 'jquery';
44import { MARKERS , ROUTES } from './utils.js' ;
55import AzureProvider from '__internal/ui/map/m_provider.dynamic.azure' ;
66import ajaxMock from '../../../helpers/ajaxMock.js' ;
7+ import errors from 'ui/widget/ui.errors' ;
78
89import 'ui/map' ;
910
@@ -94,12 +95,13 @@ QUnit.module('map loading', moduleConfig, () => {
9495 setTimeout ( function ( ) {
9596 $ ( '#map' ) . dxMap ( {
9697 provider : 'azure' ,
97- onReady : $ . proxy ( ( ) => {
98- assert . ok ( window . atlas . Map . customFlag , 'map loaded without getting script' ) ;
99-
100- done ( ) ;
101- } , this )
10298 } ) ;
99+
100+ setTimeout ( ( ) => {
101+ assert . ok ( window . atlas . Map . customFlag , 'map loaded without getting script' ) ;
102+
103+ done ( ) ;
104+ } , 50 ) ;
103105 } ) ;
104106 } ) ;
105107 } ) ;
@@ -151,6 +153,19 @@ QUnit.module('map loading', moduleConfig, () => {
151153 }
152154 } ) ;
153155 } ) ;
156+
157+ QUnit . test ( 'map should add ready event handler to call map ready callback' , function ( assert ) {
158+ const done = assert . async ( ) ;
159+
160+ $ ( '#map' ) . dxMap ( {
161+ provider : 'azure' ,
162+ onReady : ( ) => {
163+ assert . strictEqual ( atlas . readyCallbackCalled , true , 'map ready callback was called' ) ;
164+
165+ done ( ) ;
166+ }
167+ } ) . dxMap ( 'instance' ) ;
168+ } ) ;
154169} ) ;
155170
156171QUnit . module ( 'basic options' , moduleConfig , ( ) => {
@@ -1043,4 +1058,97 @@ QUnit.module('Routes', moduleConfig, () => {
10431058 }
10441059 } ) . dxMap ( 'instance' ) ;
10451060 } ) ;
1061+
1062+ QUnit . test ( 'Should log an error if get route request failed' , function ( assert ) {
1063+ const done = assert . async ( ) ;
1064+ const mapReadyDeferred = $ . Deferred ( ) ;
1065+
1066+ const map = $ ( '#map' ) . dxMap ( {
1067+ provider : 'azure' ,
1068+ onReady : ( ) => {
1069+ mapReadyDeferred . resolve ( ) ;
1070+ } ,
1071+ } ) . dxMap ( 'instance' ) ;
1072+
1073+ const errorStub = sinon . stub ( errors , 'log' ) ;
1074+
1075+ mapReadyDeferred . done ( ( ) => {
1076+ ajaxMock . clear ( ) ;
1077+ ajaxMock . setup ( {
1078+ url : '/fakeAzureUrl' ,
1079+ responseText : {
1080+ routes : [ {
1081+ legs : {
1082+ length : 1 ,
1083+ } ,
1084+ } ] ,
1085+ } ,
1086+ } ) ;
1087+
1088+ map . addRoute ( ROUTES [ 0 ] ) . done ( ( ) => {
1089+ const message = errorStub . args [ 0 ] [ 1 ] . message ;
1090+
1091+ assert . ok ( errorStub . withArgs ( 'W1006' ) . calledOnce , 'warning is logged' ) ;
1092+ assert . strictEqual ( message , 'route.legs.flatMap is not a function' , 'warning message text is correct' ) ;
1093+
1094+ errorStub . restore ( ) ;
1095+ done ( ) ;
1096+ } ) ;
1097+ } ) ;
1098+ } ) ;
1099+
1100+ QUnit . module ( 'Postponed map ready' , {
1101+ beforeEach : function ( ) {
1102+ window . postponeMapReadyPromise = true ;
1103+ } ,
1104+ afterEach : function ( ) {
1105+ delete window . postponeMapReadyPromise ;
1106+ }
1107+ } , ( ) => {
1108+ QUnit . test ( 'Route should not be added on init before map ready promise is resolved' , function ( assert ) {
1109+ const done = assert . async ( ) ;
1110+ const onRouteAdded = sinon . stub ( ) ;
1111+
1112+ $ ( '#map' ) . dxMap ( {
1113+ provider : 'azure' ,
1114+ onReady : ( ) => {
1115+ assert . strictEqual ( onRouteAdded . callCount , 1 , 'route was added after map is ready' ) ;
1116+
1117+ done ( ) ;
1118+ } ,
1119+ onRouteAdded,
1120+ routes : [ ROUTES [ 0 ] ] ,
1121+ } ) ;
1122+
1123+ setTimeout ( ( ) => {
1124+ assert . strictEqual ( onRouteAdded . callCount , 0 , 'route was not added before map is ready' ) ;
1125+
1126+ atlas . mapReadyResolve ( ) ;
1127+ } , 100 ) ;
1128+ } ) ;
1129+
1130+ QUnit . test ( 'Add route method should not be called before map ready promise is resolved' , function ( assert ) {
1131+ const done = assert . async ( ) ;
1132+ const onRouteAdded = sinon . stub ( ) ;
1133+
1134+ const map = $ ( '#map' ) . dxMap ( {
1135+ provider : 'azure' ,
1136+ onReady : ( ) => {
1137+ assert . strictEqual ( onRouteAdded . callCount , 1 , 'route was added after map is ready' ) ;
1138+
1139+ done ( ) ;
1140+ } ,
1141+ onRouteAdded,
1142+ routes : [ ROUTES [ 0 ] ] ,
1143+ } ) . dxMap ( 'instance' ) ;
1144+
1145+ map . addRoute ( ROUTES [ 0 ] ) ;
1146+
1147+ setTimeout ( ( ) => {
1148+ assert . strictEqual ( onRouteAdded . callCount , 0 , 'route was not added before map is ready' ) ;
1149+
1150+ atlas . mapReadyResolve ( ) ;
1151+ } , 100 ) ;
1152+ } ) ;
1153+ } ) ;
10461154} ) ;
0 commit comments