-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reintroduce Laika component * improved tests and added request delay * add disabled test also for hook
- Loading branch information
Showing
9 changed files
with
187 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Changelog | ||
|
||
## [1.1.0] - 2021-11-03 | ||
|
||
### Added | ||
|
||
- Re-added Laika component. It can now use the context as well. | ||
- Added this changelog | ||
|
||
## [1.0.0] - 2021-11-02 | ||
|
||
### Changed | ||
|
||
- This release is a complete rewrite in TypeScript which replaces the Laika component with a hook that can also optionally read its values from a context. | ||
|
||
### Added | ||
|
||
- Context | ||
- `useLaika` hook |
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
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
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,60 @@ | ||
import { mount } from '@cypress/react' | ||
import { Laika } from 'lib/component' | ||
import { Config, LaikaContext } from 'lib/config' | ||
import { mockRequest } from 'lib/mock/mockRequest' | ||
import { cy, describe, it } from 'local-cypress' | ||
import React from 'react' | ||
|
||
describe('component', () => { | ||
const uri = 'https://laika.example.com' | ||
|
||
it('with-parameters', () => { | ||
mockRequest('component-test', uri, 'test', true) | ||
|
||
mount( | ||
<Laika | ||
feature="component-test" | ||
uri={uri} | ||
env="test" | ||
onTrue={<div>Enabled</div>} | ||
onFalse={<div>Disabled</div>} | ||
/>, | ||
) | ||
cy.get('div').contains('Enabled') | ||
}) | ||
|
||
it('with-parameters-disabled', () => { | ||
mockRequest('component-test', uri, 'test', false) | ||
|
||
mount( | ||
<Laika | ||
feature="component-test" | ||
uri={uri} | ||
env="test" | ||
onTrue={<div>Enabled</div>} | ||
onFalse={<div>Disabled</div>} | ||
/>, | ||
) | ||
cy.get('div').contains('Disabled') | ||
}) | ||
|
||
it('with-context', () => { | ||
mockRequest('component-test', uri, 'test', true) | ||
|
||
const ctx: Config = { | ||
env: 'test', | ||
uri, | ||
} | ||
|
||
mount( | ||
<LaikaContext.Provider value={ctx}> | ||
<Laika | ||
feature="component-test" | ||
onTrue={<div>Enabled</div>} | ||
onFalse={<div>Disabled</div>} | ||
/> | ||
</LaikaContext.Provider>, | ||
) | ||
cy.get('div').contains('Enabled') | ||
}) | ||
}) |
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,34 @@ | ||
import { bool, node, number, oneOfType, string } from 'prop-types' | ||
import React from 'react' | ||
import { useLaika } from 'lib/hook' | ||
|
||
export interface LaikaProps { | ||
feature: string | ||
env?: string | ||
uri?: string | ||
cacheTimeout?: number | ||
onTrue: React.ReactElement | false | ||
onFalse: React.ReactElement | false | ||
} | ||
|
||
export function Laika(props: LaikaProps) { | ||
const [featureEnabled, featureIsLoading] = useLaika( | ||
props.feature, | ||
props.uri, | ||
props.env, | ||
props.cacheTimeout, | ||
) | ||
|
||
const children = featureEnabled ? props.onTrue : props.onFalse | ||
return <>{!featureIsLoading && children}</> | ||
} | ||
|
||
// For using it with JavaScript | ||
Laika.propTypes = { | ||
feature: string.isRequired, | ||
uri: string, | ||
env: string, | ||
cacheTimeout: number, | ||
onTrue: oneOfType([node, bool]).isRequired, | ||
onFalse: oneOfType([node, bool]).isRequired, | ||
} |
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
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,3 +1,4 @@ | ||
export { getFeatureStatus } from './utils' | ||
export { useLaika } from './hook' | ||
export { Config, LaikaContext } from './config' | ||
export { getFeatureStatus } from 'lib/utils' | ||
export { useLaika } from 'lib/hook' | ||
export { Config, LaikaContext } from 'lib/config' | ||
export { Laika } from 'lib/component' |
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 |
---|---|---|
|
@@ -12,5 +12,6 @@ export function mockRequest( | |
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
delay: 500, | ||
}) | ||
} |
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