-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to create an instance of the client and initialise it later. Don't expose internal methods and have a consistent 'init' method to use.
- Loading branch information
Nick Colley
committed
May 11, 2020
1 parent
e891ef7
commit d77a142
Showing
3 changed files
with
31 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/dotcom-ui-client-embed/src/__test__/client/ClientEmbedClient.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ClientEmbedClient as subject } from '../../client' | ||
import loadClientEmbed from '../../client/loadClientEmbed' | ||
import ClientEmbedData from '../../client/ClientEmbedData' | ||
jest.mock('../../client/loadClientEmbed.ts') | ||
jest.mock('../../client/ClientEmbedData.ts') | ||
|
||
describe('dotcom-ui-app-context/src/client/ClientEmbedData', () => { | ||
describe('.init()', () => { | ||
it('returns the value of an existing client embed data', () => { | ||
const instance = new subject('TEST') | ||
instance.init() | ||
|
||
expect(loadClientEmbed).toBeCalledWith('TEST') | ||
expect(ClientEmbedData).toHaveBeenCalledTimes(1) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import loadClientEmbed from './loadClientEmbed' | ||
import ClientEmbedData from './ClientEmbedData' | ||
|
||
const init = (id: string) => { | ||
const data = loadClientEmbed(id) | ||
return new ClientEmbedData(data) | ||
class ClientEmbedClient { | ||
private id: string | ||
constructor(id: string) { | ||
this.id = id | ||
} | ||
init() { | ||
const data = loadClientEmbed(this.id) | ||
return new ClientEmbedData(data) | ||
} | ||
} | ||
|
||
export { loadClientEmbed, ClientEmbedData, init } | ||
export { loadClientEmbed, ClientEmbedClient } |