|
3 | 3 | [](https://circleci.com/gh/saljuama/codebar-pairing-tool)
|
4 | 4 |
|
5 | 5 | See it in action: https://saljuama.github.io/codebar-pairing-tool
|
| 6 | + |
| 7 | +## Development |
| 8 | + |
| 9 | +### Running the application locally |
| 10 | + |
| 11 | +```bash |
| 12 | +$ yarn start |
| 13 | +``` |
| 14 | + |
| 15 | +### Running the tests |
| 16 | + |
| 17 | +#### Unit tests |
| 18 | + |
| 19 | +```bash |
| 20 | +$ yarn test |
| 21 | +``` |
| 22 | + |
| 23 | +#### Functional tests |
| 24 | + |
| 25 | +This requires that the application is running locally |
| 26 | + |
| 27 | +```bash |
| 28 | +$ yarn test:e2e |
| 29 | +``` |
| 30 | + |
| 31 | +### Working with Feature Toggles |
| 32 | + |
| 33 | +If we wanted to create a new toggle named `myToggle` with a default value of `false`, we would: |
| 34 | + |
| 35 | +#### Adding a new toggle |
| 36 | +Add the name, and the default value in the `src/config/featureToggles.js` file. |
| 37 | +```javascript |
| 38 | +export const featureToggles = { |
| 39 | + myToggle: false |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +It is recommended to create new toggles with a default value of `false` so new features developed under them are not |
| 44 | +available to the users right away until the features are ready for it |
| 45 | + |
| 46 | +#### Accessing the value of a feature toggle |
| 47 | +```javascript |
| 48 | +import {useSelector} from 'react-redux' |
| 49 | +import {featureEnabled} from '..path-to-config-folder../config/togglesSlice' |
| 50 | + |
| 51 | +const AnyComponent = () => { |
| 52 | + const myToggleValue = useSelector(featureEnabled('myToggle')) // false |
| 53 | + // rest of the component |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +#### Overriding a toggle value |
| 58 | +With the querystring parameters: |
| 59 | +* Local: after `yarn start` we can visit `http://localhost:3000?myToggle=true` |
| 60 | +* In GH pages: visit `https://saljuama.github.io/codebar-pairing-tool?myToggle=true` |
| 61 | + |
| 62 | +#### Releasing and cleaning up |
| 63 | +To release a feature, or a change, hidden under a feature toggle, just go to the `src/config/featureToggles.js` file and |
| 64 | +change the value to `true`. |
| 65 | + |
| 66 | +Once is verified that the feature is stable, and we will not need to turn the toggle off, we can start cleaning up the |
| 67 | +source code to remove the toggle usages and remove the toggle from the `src/config/featureToggles.js` file itself. |
0 commit comments