Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/click and log #1

Merged
merged 23 commits into from
Jul 15, 2021
Merged

Feature/click and log #1

merged 23 commits into from
Jul 15, 2021

Conversation

kmaaallen
Copy link
Owner

This includes the first basic component to increment habit count on click and persist locally.
Nothing pushed to main branch yet, keeping on dev and feature branching from there. Happy to change this practice moving forward based on what works best.

Other points:

  • Folder structure simple for now - will build out as project progresses
  • Included increment count and last update as key features for the habit component - can expand to others later
  • For now 'My Habit' hardcoded as card title. Will pass data object later.

@jdbann - Could you please review and feedback on how this has been implemented? Anything that could be done better / differently, anything missing etc?

@kmaaallen kmaaallen added the enhancement New feature or request label Jul 11, 2021
App.test.js Outdated
it('renders correctly', () => {
const tree = renderer.create(<App />).toJSON();
expect(tree).toMatchSnapshot();
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wahey! Tests from the first PR 👍

How should I run these? There's a test script in package.json but both tests fail and the file pattern doesn't actually match this file.

We'll probably want to focus the snapshot tests on smaller components as the project progresses. They're great for ensuring we're not affecting the output of a component as we refactor - but as almost any change will modify the application the snapshots will most likely be rebuilt each time.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just ran npm run test or install jest globally and run jest - they seem to be failing since updating App with react navigation.
I also didn't update the snapshot but updating locally seems to return null. Still looking into this, not too familiar with jest.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool cool, maybe this would be a good first thing to pair on to make sure we both understand how testing will work in the app

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates:

Fixed previous test errors by updating snapshots and adding mock for 'PersistGate' which was causing App to return null initially - rt2zz/redux-persist#822 (comment)

Added additional unit tests for LogButton component and countReducer reducer.

Modified test script in package.json: running 'npm run test ' should run individual test file or just 'npm run test' to run all.

package.json Outdated Show resolved Hide resolved
Comment on lines 21 to 30
const mapStateToProps = (state) => ({
count: state.countReducer.count,
updated: state.countReducer.updated
})

const mapActionsToProps = {
incrementCount,
}

export default connect(mapStateToProps, mapActionsToProps)(LogButton);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about it for this PR, but I'd be interested to explore hooks for connecting components to the redux store. I'm not sure if they would be clearer to read, or maybe just make testing harder...

return {
...state,
count: state.count + 1,
updated: setUpdated()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh! I'm torn on this one. Should the action or the reducer set this timestamp? I think it would be an interesting exercise to write a test for this reducer

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left it in the reducer for now, unit test for the reducer can be found in reducers.test.js file and run with 'npm run test reducers.test.js'.

I've bundled tests into a test file at root level - is this best practice or would it be better to have each test file nested with it's component?

src/redux/store.js Outdated Show resolved Hide resolved
src/redux/store.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@jdbann jdbann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid stuff! Works nicely on the iOS simulator. I've left a few questions but let me know if they don't make much sense. As a lot of this will be iterated on quite soon feel free to make whatever changes seem sensible and merge when you're comfortable and we can make further improvements as we go

@kmaaallen kmaaallen merged commit 34715df into dev Jul 15, 2021
@kmaaallen kmaaallen deleted the feature/click-and-log branch July 18, 2021 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants