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

v0.2.6 -> v0.2.7 #78

Merged
merged 39 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f87c6bb
Feat #43 - Tag, Link components
sam-dassana Aug 14, 2020
97d5e4f
Fix #47 - Fix Link props - both onClick & href are undef (#48)
sam-dassana Aug 14, 2020
ba77ee2
Chore #49- Upgrade Storybook and dependencies (#50)
sam-dassana Aug 18, 2020
caa3e01
feat #38 - Add eslint and fix lint errors & warnings (#39)
sam-dassana Aug 11, 2020
cb4b319
Feat #43 - Tag, Link components
sam-dassana Aug 14, 2020
0a9a022
Fix #47 - Fix Link props - both onClick & href are undef (#48)
sam-dassana Aug 14, 2020
2584b28
Chore #49- Upgrade Storybook and dependencies (#50)
sam-dassana Aug 18, 2020
427e22f
feat #3 - Input field component (#53)
nancy-dassana Aug 21, 2020
e0c0bc6
Feat #30 - Toggle and Icon components (#52)
sam-dassana Aug 21, 2020
9a88334
chore #41 - Add verify labels GitHub action (#42)
parth-dassana Aug 12, 2020
5b98c5b
Feat #43 - Tag, Link components
sam-dassana Aug 14, 2020
74d7d33
Fix #47 - Fix Link props - both onClick & href are undef (#48)
sam-dassana Aug 14, 2020
b41ca47
Chore #49- Upgrade Storybook and dependencies (#50)
sam-dassana Aug 18, 2020
2dba6fe
feat #38 - Add eslint and fix lint errors & warnings (#39)
sam-dassana Aug 11, 2020
c17778d
chore #41 - Add verify labels GitHub action (#42)
parth-dassana Aug 12, 2020
cc37822
Feat #43 - Tag, Link components
sam-dassana Aug 14, 2020
df26689
Fix #47 - Fix Link props - both onClick & href are undef (#48)
sam-dassana Aug 14, 2020
8ed4189
Chore #49- Upgrade Storybook and dependencies (#50)
sam-dassana Aug 18, 2020
e64138e
feat #3 - Input field component (#53)
nancy-dassana Aug 21, 2020
fc5b3fa
Feat #30 - Toggle and Icon components (#52)
sam-dassana Aug 21, 2020
81a4894
Bump up version to 0.2.0
parth-dassana Aug 21, 2020
0eb414d
Comment out icon component
parth-dassana Aug 21, 2020
64e7c7a
Update package.json
parth-dassana Aug 21, 2020
3f0ac79
Update index.ts
parth-dassana Aug 21, 2020
94568de
Merge branch 'master' into dev
parth-dassana Aug 21, 2020
062ccb0
Bump up package.json
parth-dassana Aug 21, 2020
e12ea02
Update package-lock.json
parth-dassana Aug 21, 2020
0fa95d0
fix #58 - Address icon, styles, global css, and typescript issues (#59)
parth-dassana Aug 21, 2020
62204c3
Merge branch 'master' into dev
parth-dassana Aug 24, 2020
e39215c
Merge branch 'master' into dev
parth-dassana Aug 24, 2020
d6aca00
chore #63 - Update .eslintrc.js (#64)
sam-dassana Aug 25, 2020
7cce5bd
feat #61 - Skeleton loader component (#66)
nancy-dassana Aug 25, 2020
f7b7331
feat #65 - Form Component (#67)
nancy-dassana Aug 27, 2020
8082187
Merge branch 'master' into dev
parth-dassana Aug 27, 2020
c562ceb
v0.2.4 -> v0.2.5
parth-dassana Aug 27, 2020
31e099f
feat #71 - Notification component (#72)
nancy-dassana Sep 2, 2020
2e5d713
Merge branch 'master' into dev
Sep 2, 2020
06d095a
feat #76 - Refactor Form.Button to be Form.SubmitButton (#77)
nancy-dassana Sep 8, 2020
70bf0c4
Merge branch 'master' into dev
Sep 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dassana-io/web-components",
"version": "0.2.6",
"version": "0.2.7",
"publishConfig": {
"registry": "https://npm.pkg.github.com/dassana-io"
},
Expand Down
2 changes: 1 addition & 1 deletion src/__snapshots__/storybook.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ exports[`Storyshots Form Default 1`] = `
</div>
<button
className="ant-btn ant-btn-default"
disabled={false}
disabled={true}
onClick={[Function]}
type="button"
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Template: Story<FormProps<UserModel>> = (args: FormProps<UserModel>) => (
<Form {...args} initialValues={{ firstName: 'First Name' }}>
<Form.Input label='First Name' name='firstName' required />
<Form.Input label='Last Name' name='lastName' />
<Form.Button />
<Form.SubmitButton>Submit</Form.SubmitButton>
</Form>
)

Expand Down
16 changes: 11 additions & 5 deletions src/components/Form/Form.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FieldContext from './FieldContext'
import FormButton from './FormButton'
import FormSubmitButton from './FormSubmitButton'
import React from 'react'
import Form, { FormProps } from './index'
import { mount, shallow, ShallowWrapper } from 'enzyme'
Expand All @@ -9,6 +9,12 @@ jest.mock('react-hook-form', () => ({
useForm: () => ({
handleSubmit: jest.fn(),
reset: mockReset
}),
useFormContext: () => ({
formState: {
isDirty: true
},
handleSubmit: jest.fn()
})
}))

Expand All @@ -25,7 +31,7 @@ const mockReset = jest.fn()
beforeEach(() => {
wrapper = shallow(
<Form initialValues={mockInitialValues} onSubmit={mockOnSubmit}>
<FormButton />
<FormSubmitButton>Submit</FormSubmitButton>
</Form>
)
})
Expand All @@ -36,7 +42,7 @@ describe('Form', () => {
})

it('renders children properly', () => {
expect(wrapper.find(FormButton)).toHaveLength(1)
expect(wrapper.find(FormSubmitButton)).toHaveLength(1)
})

it('passes the correct props to FieldContext provider', () => {
Expand All @@ -52,7 +58,7 @@ describe('Form', () => {
it('correctly defaults initial values to empty object if none is passed in', () => {
wrapper = shallow(
<Form onSubmit={mockOnSubmit}>
<FormButton />
<FormSubmitButton>Submit</FormSubmitButton>
</Form>
)

Expand All @@ -64,7 +70,7 @@ describe('Form', () => {
it('correctly updates initial values', () => {
const form = mount(
<Form onSubmit={mockOnSubmit}>
<FormButton />
<FormSubmitButton>Submit</FormSubmitButton>
</Form>
)

Expand Down
46 changes: 0 additions & 46 deletions src/components/Form/FormButton/FormButton.test.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions src/components/Form/FormButton/index.tsx

This file was deleted.

70 changes: 70 additions & 0 deletions src/components/Form/FormSubmitButton/FormSubmitButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as reactHookForm from 'react-hook-form'
import Button from '../../Button'
import FieldContext from '../FieldContext'
import React from 'react'
import FormSubmitButton, { FormButtonProps } from './index'
import { mount, ReactWrapper } from 'enzyme'

let wrapper: ReactWrapper<FormButtonProps>

const mockOnSubmit = jest.fn()

const getMockFormContext = (isDirty = true) =>
({
formState: {
isDirty
},
handleSubmit: (onSubmit: any) => onSubmit()
} as reactHookForm.UseFormMethods)

const getWrapper = () => (
<FieldContext.Provider
value={{ initialValues: {}, loading: true, onSubmit: mockOnSubmit }}
>
<FormSubmitButton>Submit</FormSubmitButton>
</FieldContext.Provider>
)

beforeEach(() => {
jest.spyOn(reactHookForm, 'useFormContext').mockImplementation(() =>
getMockFormContext()
)

wrapper = mount(getWrapper())
})

afterEach(() => {
jest.resetAllMocks()
})

describe('FormButton', () => {
it('renders', () => {
expect(wrapper).toHaveLength(1)
})

it('calls onSubmit when clicked', () => {
wrapper.simulate('click')

expect(mockOnSubmit).toHaveBeenCalledTimes(1)
})

it('correctly passes loading from field context', () => {
expect(wrapper.find(Button).props().loading).toBe(true)
})

it('enables the submit button if form is dirty', () => {
expect(wrapper.find(Button).props().disabled).toBe(false)
})

it('disables the submit button if form is pristine', () => {
jest.clearAllMocks()

jest.spyOn(reactHookForm, 'useFormContext').mockImplementation(() =>
getMockFormContext(false)
)

wrapper = mount(getWrapper())

expect(wrapper.find(Button).props().disabled).toBe(true)
})
})
23 changes: 23 additions & 0 deletions src/components/Form/FormSubmitButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import FieldContext from '../FieldContext'
import { useFormContext } from 'react-hook-form'
import Button, { ButtonProps } from '../../Button'
import React, { FC, useContext } from 'react'

export type FormButtonProps = Omit<ButtonProps, 'loading' | 'onClick'>

const FormSubmitButton: FC<FormButtonProps> = (props: FormButtonProps) => {
const { handleSubmit, formState } = useFormContext()
const { loading, onSubmit } = useContext(FieldContext)
const { isDirty } = formState

return (
<Button
disabled={!isDirty}
loading={loading}
onClick={handleSubmit(onSubmit)}
{...props}
/>
)
}

export default FormSubmitButton
4 changes: 2 additions & 2 deletions src/components/Form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createUseStyles } from 'react-jss'
import FieldContext from './FieldContext'
import { FieldValues } from 'react-hook-form/dist/types/form'
import FormButton from './FormButton'
import FormInput from './FormInput'
import FormSubmitButton from './FormSubmitButton'
import { FormProvider, SubmitHandler, useForm } from 'react-hook-form'
import React, { ReactNode, useEffect } from 'react'

Expand Down Expand Up @@ -49,7 +49,7 @@ function Form<Model>({
)
}

Form.Button = FormButton
Form.SubmitButton = FormSubmitButton
Form.Input = FormInput

export default Form