-
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.
add cell for fetching organization reportingPeriods and agencies for …
…upload form
- Loading branch information
Showing
11 changed files
with
238 additions
and
43 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
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 |
---|---|---|
|
@@ -35,6 +35,7 @@ export const getCurrentUser = async ( | |
console.log(decoded) | ||
return { | ||
id: 1, | ||
organizationId: 1, | ||
email: '[email protected]', | ||
roles: ['admin'], | ||
} | ||
|
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,8 @@ | ||
// Define your own mock data here: | ||
export const standard = (/* vars, { ctx, req } */) => ({ | ||
organization: { | ||
id: 42, | ||
reportingPeriods: [{ id: 1, name: 'Reporting Period 1' }], | ||
agencies: [{ id: 1, name: 'Agency 1' }], | ||
}, | ||
}) |
34 changes: 34 additions & 0 deletions
34
web/src/components/OrganizationCell/OrganizationCell.stories.tsx
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 type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { Loading, Empty, Failure, Success } from './OrganizationCell' | ||
import { standard } from './OrganizationCell.mock' | ||
|
||
const meta: Meta = { | ||
title: 'Cells/OrganizationCell', | ||
} | ||
|
||
export default meta | ||
|
||
export const loading: StoryObj<typeof Loading> = { | ||
render: () => { | ||
return Loading ? <Loading /> : <></> | ||
}, | ||
} | ||
|
||
export const empty: StoryObj<typeof Empty> = { | ||
render: () => { | ||
return Empty ? <Empty /> : <></> | ||
}, | ||
} | ||
|
||
export const failure: StoryObj<typeof Failure> = { | ||
render: (args) => { | ||
return Failure ? <Failure error={new Error('Oh no')} {...args} /> : <></> | ||
}, | ||
} | ||
|
||
export const success: StoryObj<typeof Success> = { | ||
render: (args) => { | ||
return Success ? <Success {...standard()} {...args} /> : <></> | ||
}, | ||
} |
42 changes: 42 additions & 0 deletions
42
web/src/components/OrganizationCell/OrganizationCell.test.tsx
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,42 @@ | ||
import { render } from '@redwoodjs/testing/web' | ||
|
||
import { Loading, Empty, Failure } from './OrganizationCell' | ||
// import { standard } from './OrganizationCell.mock' | ||
|
||
// Generated boilerplate tests do not account for all circumstances | ||
// and can fail without adjustments, e.g. Float and DateTime types. | ||
// Please refer to the RedwoodJS Testing Docs: | ||
// https://redwoodjs.com/docs/testing#testing-cells | ||
// https://redwoodjs.com/docs/testing#jest-expect-type-considerations | ||
|
||
describe('OrganizationCell', () => { | ||
it('renders Loading successfully', () => { | ||
expect(() => { | ||
render(<Loading />) | ||
}).not.toThrow() | ||
}) | ||
|
||
it('renders Empty successfully', async () => { | ||
expect(() => { | ||
render(<Empty />) | ||
}).not.toThrow() | ||
}) | ||
|
||
it('renders Failure successfully', async () => { | ||
expect(() => { | ||
render(<Failure error={new Error('Oh no')} />) | ||
}).not.toThrow() | ||
}) | ||
|
||
// When you're ready to test the actual output of your component render | ||
// you could test that, for example, certain text is present: | ||
// | ||
// 1. import { screen } from '@redwoodjs/testing/web' | ||
// 2. Add test: expect(screen.getByText('Hello, world')).toBeInTheDocument() | ||
|
||
// it('renders Success successfully', async () => { | ||
// expect(() => { | ||
// render(<Success organization={standard().organization} />) | ||
// }).not.toThrow() | ||
// }) | ||
}) |
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,70 @@ | ||
import type { | ||
FindOrganizationQuery, | ||
FindOrganizationQueryVariables, | ||
} from 'types/graphql' | ||
|
||
import { Label, SelectField } from '@redwoodjs/forms' | ||
import type { CellSuccessProps, CellFailureProps } from '@redwoodjs/web' | ||
|
||
export const QUERY = gql` | ||
query FindOrganizationQuery($id: Int!) { | ||
organization: organization(id: $id) { | ||
id | ||
reportingPeriods { | ||
id | ||
name | ||
} | ||
agencies { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
` | ||
|
||
export const Loading = () => <div>Loading...</div> | ||
|
||
export const Empty = () => <div>Empty</div> | ||
|
||
export const Failure = ({ | ||
error, | ||
}: CellFailureProps<FindOrganizationQueryVariables>) => ( | ||
<div style={{ color: 'red' }}>Error: {error?.message}</div> | ||
) | ||
|
||
export const Success = ({ | ||
organization, | ||
}: CellSuccessProps<FindOrganizationQuery, FindOrganizationQueryVariables>) => { | ||
return ( | ||
<div> | ||
<Label | ||
name="reportingPeriodId" | ||
className="rw-label" | ||
errorClassName="rw-label rw-label-error" | ||
> | ||
Reporting Period | ||
</Label> | ||
<SelectField name="reportingPeriodId"> | ||
{organization.reportingPeriods.map((reportingPeriod) => ( | ||
<option key={reportingPeriod.id} value={reportingPeriod.id}> | ||
{reportingPeriod.name} | ||
</option> | ||
))} | ||
</SelectField> | ||
<Label | ||
name="agencyId" | ||
className="rw-label" | ||
errorClassName="rw-label rw-label-error" | ||
> | ||
Agency Code | ||
</Label> | ||
<SelectField name="agencyId"> | ||
{organization.agencies.map((agency) => ( | ||
<option key={agency.id} value={agency.id}> | ||
{agency.name} | ||
</option> | ||
))} | ||
</SelectField> | ||
</div> | ||
) | ||
} |
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