Skip to content

Commit

Permalink
fix(transport): Add test for lazy-loading the transport layer (#10)
Browse files Browse the repository at this point in the history
* fix(transport): Add test for lazy-loading the transport layer

* Committing latest test

* feat: Added Manage APIs for `windowColor` and `windowOpacity` (#164)

# [0.15.0-next.5](v0.15.0-next.4...v0.15.0-next.5) (2023-07-31)

### Bug Fixes

* Upgrade to `firebolt-js/openrpc` version 2.0.3 ([c0a2647](c0a2647))

* feat: Added manage apis for windlowColor and windowOpacity (#157)

* feat: Added manage apis for windlowColor and windowOpacity

* chore(release): 0.16.0-next.1 [skip ci]

# [0.16.0-next.1](v0.15.0...v0.16.0-next.1) (2023-08-07)

### Features

* Added manage apis for windlowColor and windowOpacity ([#157](#157)) ([f508358](f508358))

* fix: Unit test cases for setting null value (#159)

fix: Unit test cases for setting null value

* fix: Update firebolt-openrpc, fix tests

* chore(release): 0.16.0-next.2 [skip ci]

# [0.16.0-next.2](v0.16.0-next.1...v0.16.0-next.2) (2023-08-10)

### Bug Fixes

* Unit test cases for setting null value ([#159](#159)) ([7e011e2](7e011e2))
* Update firebolt-openrpc, fix tests ([9480984](9480984))
* Update firebolt-openrpc, fix tests ([312b5ec](312b5ec))

* chore: Point to product `firebolt-openrpc` release

* chore(release): 0.16.0-next.3 [skip ci]

# [0.16.0-next.3](v0.16.0-next.2...v0.16.0-next.3) (2023-08-14)

### Bug Fixes

* Update package.json to point to release 2.0.4 of `firebolt-openrpc` ([9e3cf55](9e3cf55))

* Update CHANGELOG.md

---------

Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
Co-authored-by: Kevin <72702438+kevinshahfws@users.noreply.github.com>

* chore(release): 0.16.0 [skip ci]

# [0.16.0](v0.15.0...v0.16.0) (2023-08-14)

### Features

* Added Manage APIs for `windowColor` and `windowOpacity` ([#164](#164)) ([99b9fa6](99b9fa6)), closes [#157](#157) [#157](#157) [#159](#159) [#159](#159)

* fix: Move test to new location

fix: Move test to new location

* fix: Remove old test

* fix: Rename lazy-transport-test.js to lazy-transport-test.ts

* fix: Update test to TypeScript

---------

Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
Co-authored-by: Kevin <72702438+kevinshahfws@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 16, 2023
1 parent 5cf766a commit 168fcaf
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions src/sdks/core/test/suite/lazy-transport.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright 2021 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

// NOTE: this test SHOULD NOT include Setup, since it does it's own
// setup for Firebolt SDK/TL handshake
const win = globalThis || window

import Setup from '../../../../../test/Setup'
import { beforeAll, test, expect } from '@jest/globals';
import { Lifecycle, Discovery } from "../../build/javascript/src/firebolt";

// holds test transport layer state, e.g. callback
type stateType = {
callback: (arg0: string) => void | null
}

const state:stateType = {
callback: null
}

let navigateToListenCount = 0
let pullEntityInfoListenCount = 0
let callbackWiredUp = false
let sendCalled = false

const transport = {
send: function(message) {
sendCalled = true
const json = JSON.parse(message)
console.log('transport.send: ' + json.method)
if (json.method.toLowerCase() === 'lifecycle.ready') {
// we'll assert on this later...
navigateToListenCount++
if (state.callback) {
// we'll assert on this later...
callbackWiredUp = true
let response = {
jsonrpc: '2.0',
id: json.id,
result: true
}
// catching errors, so all tests don't fail if this breaks
try {
// send back the onInactive event immediately, to test for race conditions
state.callback(JSON.stringify(response))
}
catch (err) {
// fail silenetly (the boolean-based tests below will figure it out...)
}
}
}
else if (json.method.toLowerCase() === 'discovery.onpullentityinfo') {
pullEntityInfoListenCount++
}
},
receive: function(callback) {
console.log('transport.receive')
// store the callback
state.callback = callback
}
}

beforeAll(()=> {

// listen twice, using event-specific call FIRST
Discovery.listen("navigateTo", (value) => { callbackWiredUp = true })
Discovery.listen("navigateTo", (value) => { /* this just adds more listen calls to make sure we don't spam */ })
Discovery.listen((event, value) => { /* testing both listen signatures */ })
Discovery.listen((event, value) => { /* testing both listen signatures */ })
// listen three more times, using wildcard FIRST (from above)

let p = new Promise( (resolve, reject) => {
setTimeout( _ => {
resolve(null)
}, 4000)
})

Lifecycle.ready()

win.__firebolt.setTransportLayer(transport)

return p
})


test('Transport injected after SDK', () => {
expect(callbackWiredUp).toBe(true)
});

test('Transport send method working', () => {
expect(sendCalled).toBe(true)
});

test('Transport was sent listeners', () => {
expect(navigateToListenCount).toBeGreaterThan(0)
});

test('Transport was sent each listener only once', () => {
expect(navigateToListenCount).toBe(1)
});

0 comments on commit 168fcaf

Please sign in to comment.