|
7 | 7 | <script src="../../web-component-tester/browser.js"></script> |
8 | 8 | <script src="../../iron-test-helpers/test-helpers.js"></script> |
9 | 9 | <script src="../../iron-test-helpers/mock-interactions.js"></script> |
| 10 | + <link rel="import" href="../../arc-polyfills/arc-polyfills.html"> |
10 | 11 | <link rel="import" href="../api-console.html"> |
11 | 12 | </head> |
12 | 13 |
|
|
269 | 270 | element._notifyApicExtension(); |
270 | 271 | }); |
271 | 272 | }); |
| 273 | + |
| 274 | + suite('_modelLocationChanged()', () => { |
| 275 | + let element; |
| 276 | + let xhr; |
| 277 | + let requests; |
| 278 | + setup(() => { |
| 279 | + requests = []; |
| 280 | + element = fixture('Basic'); |
| 281 | + }); |
| 282 | + |
| 283 | + suiteSetup(() => { |
| 284 | + xhr = sinon.useFakeXMLHttpRequest(); |
| 285 | + xhr.onCreate = function(xhr) { |
| 286 | + requests.push(xhr); |
| 287 | + }; |
| 288 | + }); |
| 289 | + |
| 290 | + suiteTeardown(() => { |
| 291 | + xhr.restore(); |
| 292 | + }); |
| 293 | + |
| 294 | + test('Do nothing when no argument', () => { |
| 295 | + element._modelLocationChanged(); |
| 296 | + assert.equal(requests.length, 0); |
| 297 | + }); |
| 298 | + |
| 299 | + test('Downloads model from remote location', () => { |
| 300 | + element._modelLocationChanged('apip.json'); |
| 301 | + assert.equal(requests.length, 1); |
| 302 | + requests[0].respond(200, { |
| 303 | + 'Content-Type': 'application/json'}, |
| 304 | + '[{"@context":{}, "@id": "","@type": []}]'); |
| 305 | + assert.typeOf(element.amfModel, 'array'); |
| 306 | + }); |
| 307 | + |
| 308 | + test('Calls _apiLoadErrorHandler() when url is invalid', () => { |
| 309 | + const callback = sinon.spy(element, '_apiLoadErrorHandler'); |
| 310 | + element._modelLocationChanged('error.json'); |
| 311 | + requests[0].respond(404, { |
| 312 | + 'Content-Type': 'text/plain'}, |
| 313 | + 'nothing'); |
| 314 | + assert.isTrue(callback.called); |
| 315 | + }); |
| 316 | + }); |
| 317 | + |
| 318 | + suite('_apiLoadEndHandler()', () => { |
| 319 | + let element; |
| 320 | + setup(() => { |
| 321 | + element = fixture('Basic'); |
| 322 | + }); |
| 323 | + |
| 324 | + test('Sets amfModel property', () => { |
| 325 | + element._apiLoadEndHandler({ |
| 326 | + response: '[{"@context":{}, "@id": "","@type": []}]' |
| 327 | + }); |
| 328 | + assert.typeOf(element.amfModel, 'array'); |
| 329 | + }); |
| 330 | + |
| 331 | + test('Calles _apiLoadErrorHandler when response is not valid', () => { |
| 332 | + const callback = sinon.spy(element, '_apiLoadErrorHandler'); |
| 333 | + element._apiLoadEndHandler({ |
| 334 | + response: '[{"@context":' |
| 335 | + }); |
| 336 | + assert.isTrue(callback.called); |
| 337 | + }); |
| 338 | + }); |
| 339 | + |
| 340 | + suite('_apiLoadErrorHandler()', () => { |
| 341 | + let element; |
| 342 | + setup(() => { |
| 343 | + element = fixture('Basic'); |
| 344 | + }); |
| 345 | + |
| 346 | + test('Sets message on the toast', () => { |
| 347 | + element._apiLoadErrorHandler(new Error('test')); |
| 348 | + assert.typeOf(element.$.apiLoadErrorToast.text, 'string'); |
| 349 | + }); |
| 350 | + |
| 351 | + test('The toast is opened', () => { |
| 352 | + element._apiLoadErrorHandler(new Error('test')); |
| 353 | + assert.isTrue(element.$.apiLoadErrorToast.opened); |
| 354 | + }); |
| 355 | + }); |
| 356 | + |
| 357 | + suite('resetLayout()', () => { |
| 358 | + let element; |
| 359 | + setup((done) => { |
| 360 | + element = fixture('Basic'); |
| 361 | + flush(() => done()); |
| 362 | + }); |
| 363 | + |
| 364 | + test('Resets layout', () => { |
| 365 | + element.resetLayout(); |
| 366 | + // no error is thrown |
| 367 | + }); |
| 368 | + }); |
| 369 | + |
| 370 | + suite('_noExtBannerChanged()', () => { |
| 371 | + let element; |
| 372 | + setup(() => { |
| 373 | + element = fixture('Basic'); |
| 374 | + element._setExtensionBannerActive(true); |
| 375 | + }); |
| 376 | + |
| 377 | + test('Sets extensionBannerActive to false', () => { |
| 378 | + element._noExtBannerChanged(true); |
| 379 | + assert.isFalse(element.extensionBannerActive); |
| 380 | + }); |
| 381 | + |
| 382 | + test('Does nothing if argument is false', () => { |
| 383 | + element._noExtBannerChanged(false); |
| 384 | + assert.isTrue(element.extensionBannerActive); |
| 385 | + }); |
| 386 | + }); |
| 387 | + |
| 388 | + suite('_computeRenderInlineTryIt()', () => { |
| 389 | + let element; |
| 390 | + setup(() => { |
| 391 | + element = fixture('Basic'); |
| 392 | + }); |
| 393 | + |
| 394 | + test('Return false whem no "wideLayout"', () => { |
| 395 | + const result = element._computeRenderInlineTryIt(false); |
| 396 | + assert.isFalse(result); |
| 397 | + }); |
| 398 | + |
| 399 | + test('Return false whem no "isMethod"', () => { |
| 400 | + const result = element._computeRenderInlineTryIt(true, true, false); |
| 401 | + assert.isFalse(result); |
| 402 | + }); |
| 403 | + |
| 404 | + test('Return false whem no "app"', () => { |
| 405 | + const result = element._computeRenderInlineTryIt(true, false, true); |
| 406 | + assert.isFalse(result); |
| 407 | + }); |
| 408 | + |
| 409 | + test('Return false whem "inlineMethods"', () => { |
| 410 | + const result = element._computeRenderInlineTryIt(true, true, true, true); |
| 411 | + assert.isFalse(result); |
| 412 | + }); |
| 413 | + |
| 414 | + test('Return true to inline methods', () => { |
| 415 | + const result = element._computeRenderInlineTryIt(true, true, true, false); |
| 416 | + assert.isTrue(result); |
| 417 | + }); |
| 418 | + }); |
| 419 | + |
| 420 | + suite('_computeNoTryItValue()', () => { |
| 421 | + let element; |
| 422 | + setup(() => { |
| 423 | + element = fixture('Basic'); |
| 424 | + }); |
| 425 | + |
| 426 | + test('Returns true when renderInlineTyit', () => { |
| 427 | + const result = element._computeNoTryItValue(false, true); |
| 428 | + assert.isTrue(result); |
| 429 | + }); |
| 430 | + |
| 431 | + test('Returns value io noTryIt', () => { |
| 432 | + const result = element._computeNoTryItValue(false); |
| 433 | + assert.isFalse(result); |
| 434 | + }); |
| 435 | + }); |
272 | 436 | </script> |
273 | 437 | </body> |
274 | 438 |
|
|
0 commit comments