1- import { fixture , assert , aTimeout , html } from '@open-wc/testing' ;
1+ import { fixture , assert , aTimeout , html , nextFrame } from '@open-wc/testing' ;
22import * as sinon from 'sinon/pkg/sinon-esm.js' ;
33import * as MockInteractions from '@polymer/iron-test-helpers/mock-interactions.js' ;
44import { isChrome } from '../src/ApiConsole.js' ;
@@ -8,7 +8,7 @@ import '../api-console.js';
88// Tests for computations that do not require AMF model.
99//
1010
11- describe ( '<api-console>' , function ( ) {
11+ describe ( '<api-console>' , function ( ) {
1212 async function basicFixture ( ) {
1313 return ( await fixture ( `<api-console></api-console>` ) ) ;
1414 }
@@ -63,7 +63,7 @@ describe('<api-console>', function() {
6363 let requests ;
6464 before ( ( ) => {
6565 xhr = sinon . useFakeXMLHttpRequest ( ) ;
66- xhr . onCreate = function ( xhr ) {
66+ xhr . onCreate = function ( xhr ) {
6767 requests . push ( xhr ) ;
6868 } ;
6969 } ) ;
@@ -86,7 +86,8 @@ describe('<api-console>', function() {
8686 element . modelLocation = 'apip.json' ;
8787 assert . equal ( requests . length , 1 ) ;
8888 requests [ 0 ] . respond ( 200 , {
89- 'Content-Type' : 'application/json' } ,
89+ 'Content-Type' : 'application/json'
90+ } ,
9091 '[{"@context":{}, "@id": "","@type": []}]' ) ;
9192 assert . typeOf ( element . amf , 'array' ) ;
9293 } ) ;
@@ -100,7 +101,8 @@ describe('<api-console>', function() {
100101 const callback = sinon . spy ( element , '_apiLoadErrorHandler' ) ;
101102 element . modelLocation = 'error.json' ;
102103 requests [ 0 ] . respond ( 404 , {
103- 'Content-Type' : 'text/plain' } ,
104+ 'Content-Type' : 'text/plain'
105+ } ,
104106 'nothing' ) ;
105107 assert . isTrue ( callback . called ) ;
106108 } ) ;
@@ -230,7 +232,7 @@ describe('<api-console>', function() {
230232 } ) ;
231233 } ) ;
232234
233- describe ( 'Attribution' , function ( ) {
235+ describe ( 'Attribution' , function ( ) {
234236 it ( 'Attribution logo is rendered' , async ( ) => {
235237 const element = await basicFixture ( ) ;
236238 const node = element . shadowRoot . querySelector ( '.powered-by' ) ;
@@ -327,10 +329,10 @@ describe('<api-console>', function() {
327329 function basicFixture ( loc ) {
328330 return new Promise ( ( resolve , reject ) => {
329331 fixture ( html `< api-console modelLocation ="${ loc } "> </ api-console > ` )
330- . then ( ( element ) => {
331- element . addEventListener ( 'model-load-success' , ( ) => resolve ( element ) ) ;
332- element . addEventListener ( 'model-load-error' , ( ) => reject ( element ) ) ;
333- } )
332+ . then ( ( element ) => {
333+ element . addEventListener ( 'model-load-success' , ( ) => resolve ( element ) ) ;
334+ element . addEventListener ( 'model-load-error' , ( ) => reject ( element ) ) ;
335+ } )
334336 } ) ;
335337 }
336338
@@ -464,4 +466,25 @@ describe('<api-console>', function() {
464466 } ) ;
465467 } ) ;
466468 } ) ;
469+
470+ describe ( 'Server selection change' , ( ) => {
471+ let element ;
472+
473+ beforeEach ( async ( ) => {
474+ element = await basicFixture ( ) ;
475+ } ) ;
476+
477+ it ( 'Should update selectedServerValue and selectedServerType' , async ( ) => {
478+ const e = new CustomEvent ( 'api-server-changed' , {
479+ detail : {
480+ selectedValue : 'https://example.org' ,
481+ selectedType : 'custom' ,
482+ }
483+ } ) ;
484+ element . dispatchEvent ( e ) ;
485+ await nextFrame ( ) ;
486+ assert . equal ( element . selectedServerValue , 'https://example.org' ) ;
487+ assert . equal ( element . selectedServerType , 'custom' ) ;
488+ } ) ;
489+ } ) ;
467490} ) ;
0 commit comments