-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from christin-wednesday/fix/remove-make-selector
refactor: Add somePayload state variable selector def and usages
- Loading branch information
Showing
12 changed files
with
91 additions
and
96 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 |
---|---|---|
|
@@ -8,3 +8,5 @@ stats.json | |
.DS_Store | ||
npm-debug.log | ||
.idea | ||
.vscode/** | ||
app/** |
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,3 @@ | ||
import loadable from '@utils/loadable' | ||
import loadable from '@utils/loadable'; | ||
|
||
export default loadable(() => import('./index')) | ||
export default loadable(() => import('./index')); |
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 |
---|---|---|
@@ -1,24 +1,17 @@ | ||
// import produce from 'immer' | ||
import { {{ camelCase name }}Reducer, {{ camelCase name }}Types, initialState } from '../reducer' | ||
import { {{ camelCase name }}Reducer, {{ camelCase name }}Types, initialState } from '../reducer'; | ||
|
||
/* eslint-disable default-case, no-param-reassign */ | ||
describe('{{ properCase name }} reducer tests', () => { | ||
let state | ||
beforeEach(() => { | ||
state = initialState | ||
}) | ||
it('should return the initial state by default', () => { | ||
expect({{ camelCase name }}Reducer(undefined, {})).toEqual(initialState); | ||
}); | ||
|
||
it('should return the initial state', () => { | ||
expect({{ camelCase name }}Reducer(undefined, {})).toEqual(state) | ||
}) | ||
|
||
it('should return the update the state when an action of type DEFAULT is dispatched', () => { | ||
const expectedResult = {...state, somePayload: 'Mohammed Ali Chherawalla'} | ||
it('should return the updated state when an action of type DEFAULT is dispatched', () => { | ||
const expectedResult = {...initialState, somePayLoad: 'Mohammed Ali Chherawalla'}; | ||
expect( | ||
{{ camelCase name }}Reducer(state, { | ||
{{ camelCase name }}Reducer(initialState, { | ||
type: {{ camelCase name}}Types.DEFAULT_ACTION, | ||
somePayload: 'Mohammed Ali Chherawalla' | ||
somePayLoad: 'Mohammed Ali Chherawalla' | ||
}) | ||
).toEqual(expectedResult) | ||
}) | ||
}) | ||
).toEqual(expectedResult); | ||
}); | ||
}); |
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,13 +1,13 @@ | ||
import { takeLatest } from 'redux-saga/effects' | ||
import { {{ camelCase name}}Types } from './reducer' | ||
import { takeLatest } from 'redux-saga/effects'; | ||
import { {{ camelCase name}}Types } from './reducer'; | ||
|
||
// Individual exports for testing | ||
const { DEFAULT_ACTION } = {{ camelCase name }}Types | ||
const { DEFAULT_ACTION } = {{ camelCase name }}Types; | ||
|
||
export function *defaultFunction (/* action */) { | ||
// console.log('Do something here') | ||
|
||
} | ||
}; | ||
|
||
export default function* {{ camelCase name }}Saga() { | ||
yield takeLatest(DEFAULT_ACTION, defaultFunction) | ||
} | ||
yield takeLatest(DEFAULT_ACTION, defaultFunction); | ||
}; |
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,17 +1,14 @@ | ||
import { createSelector } from 'reselect' | ||
import { initialState } from './reducer' | ||
import { createSelector } from 'reselect'; | ||
import { initialState } from './reducer'; | ||
|
||
/** | ||
* Direct selector to the {{ camelCase name }} state domain | ||
*/ | ||
|
||
const select{{ properCase name }}Domain = state => state.{{ camelCase name }} || initialState | ||
const select{{ properCase name }}Domain = state => state.{{ camelCase name }} || initialState; | ||
|
||
/** | ||
* use createSelector if you are doing something with the returned state. | ||
* https://redux.js.org/usage/deriving-data-selectors#createselector-overview | ||
* e.g: const makeSelect{{ properCase name }} = () => | ||
* createSelector(select{{ properCase name }}Domain, substate => get(substate, 'somevalue')) | ||
*/ | ||
export const select{{ properCase name }} = () => | ||
createSelector(select{{ properCase name }}Domain, substate => substate) | ||
createSelector(select{{ properCase name }}Domain, substate => substate); | ||
|
||
export const selectSomePayLoad = () => | ||
createSelector(select{{properCase name}}Domain, substate => substate.somePayLoad); |
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,16 +1,19 @@ | ||
import { select{{ properCase name }} } from '../selectors' | ||
import { select{{ properCase name }}, selectSomePayLoad } from '../selectors'; | ||
|
||
describe('{{ properCase name }} selector tests', () => { | ||
let mockedState | ||
|
||
beforeEach(() => { | ||
mockedState = { | ||
{{ camelCase name }}: {} | ||
const mockedState = { | ||
{{ camelCase name }}: { | ||
somePayLoad: "W.S" | ||
} | ||
} | ||
}) | ||
|
||
it('should select the user state', () => { | ||
it('should select the {{ camelCase name }} state', () => { | ||
const {{ camelCase name }}Selector = select{{ properCase name }}(); | ||
expect({{ camelCase name }}Selector(mockedState)).toEqual(mockedState.{{ camelCase name }}); | ||
}) | ||
}); | ||
|
||
it('should select the somePayLoad state', () => { | ||
const somePayLoadSelector = selectSomePayLoad(); | ||
expect(somePayLoadSelector(mockedState)).toEqual(mockedState.{{ camelCase name }}.somePayLoad); | ||
}); | ||
}) |
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,26 +1,27 @@ | ||
/** | ||
* | ||
* Tests for {{ properCase name }} | ||
* Tests for {{ properCase name }} container | ||
* | ||
* | ||
*/ | ||
|
||
|
||
import React from 'react' | ||
import { renderProvider } from '@utils/testUtils' | ||
// import { fireEvent } from '@testing-library/dom' | ||
import { {{ properCase name }}Test as {{ properCase name }} } from '../index' | ||
import React from 'react'; | ||
// import { fireEvent } from '@testing-library/dom'; | ||
import { renderProvider } from '@utils/testUtils'; | ||
import { {{ properCase name }}Test as {{ properCase name }} } from '../index'; | ||
|
||
describe('<{{ properCase name }} /> container tests', () => { | ||
// let submitSpy | ||
// let submitSpy | ||
|
||
beforeEach(() => { | ||
// submitSpy = jest.fn() | ||
}) | ||
// submitSpy = jest.fn(); | ||
}); | ||
|
||
it('should render and match the snapshot', () => { | ||
const { baseElement } = renderProvider( | ||
<{{ properCase name }} /> | ||
) | ||
expect(baseElement).toMatchSnapshot() | ||
}) | ||
}) | ||
); | ||
expect(baseElement).toMatchSnapshot(); | ||
}); | ||
}); |
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