Skip to content

Commit

Permalink
fix: Load flags from legacy DOM (#968)
Browse files Browse the repository at this point in the history
* fix: Load flags from legacy DOM

* tests: Un-focus test

Co-Authored-By: Patrick Browne <[email protected]>

Co-authored-by: Patrick Browne <[email protected]>
  • Loading branch information
y-lohse and ptbrowne authored Feb 24, 2020
1 parent efa9fa3 commit 6f54cc7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/cozy-flags/src/flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const initializeFromRemote = async client => {
enable(attributes)
}

const capitalize = str => str[0].toUppercase() + str.slice(1)
const capitalize = str => str[0].toUpperCase() + str.slice(1)

export const getTemplateData = attr => {
if (typeof document === 'undefined') {
Expand Down
20 changes: 20 additions & 0 deletions packages/cozy-flags/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,26 @@ export default function testFlagAPI(flag) {
document.body.removeChild(div)
}
})

it('should initialize from DOM (legacy)', async () => {
jest.spyOn(console, 'warn').mockImplementation(() => {})
let div
try {
div = document.createElement('div')
div.dataset.cozyFlags = JSON.stringify(domFlags)
document.body.appendChild(div)
await flag.initialize()
expect(flag('has_feature1')).toBe(true)
expect(flag('has_feature2')).toBe(false)
expect(flag('number_of_foos')).toBe(10)
expect(flag('bar_config')).toEqual({ qux: 'quux' })

// eslint-disable-next-line no-console
expect(console.warn).toHaveBeenCalled()
} finally {
document.body.removeChild(div)
}
})
}

it('should initialize from the remote stack', async () => {
Expand Down

0 comments on commit 6f54cc7

Please sign in to comment.