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

fix(cli): Allow common custom scaffold template files #11755

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6569464
feat(cli): allow common custom component files to be generated by sca…
esteban-url Dec 7, 2024
bce7a71
feat(cli): allow common custom page files to be generated by scaffold…
esteban-url Dec 7, 2024
3cd47bf
chore: add changeset
esteban-url Dec 7, 2024
589d855
Merge branch 'main' into er-custom-scaffold-files
esteban-url Dec 9, 2024
ee9df89
Merge branch 'main' into er-custom-scaffold-files
esteban-url Dec 26, 2024
8b1585e
Merge branch 'main' into er-custom-scaffold-files
Tobbe Dec 27, 2024
ecf9f0e
more specific regex
Tobbe Dec 27, 2024
b633c6b
add tests for mocks, tests etc
Tobbe Dec 27, 2024
24799b0
Merge branch 'main' into er-custom-scaffold-files
esteban-url Dec 28, 2024
776518e
feat(scaffold): add mock templates and test files for new components
esteban-url Dec 29, 2024
51f83ad
fix(scaffold): remove duplicated template files
esteban-url Dec 30, 2024
0fc3c9b
fix(scaffold): correct typo in command name from 'destory' to 'destroy'
esteban-url Dec 30, 2024
a853a9f
test(scaffold): update tests to expect 48 files instead of 19
esteban-url Dec 30, 2024
4263d32
feat(scaffold): add mock & test templates for all pages & components …
esteban-url Dec 30, 2024
ce10dcf
refactor(scaffold): restore default functionality and update tests
esteban-url Dec 30, 2024
be06b9c
chore(changelog): update changelog description
esteban-url Dec 30, 2024
692e21c
Merge branch 'main' into er-custom-scaffold-files
esteban-url Dec 30, 2024
d11aa8f
test() instead of match()
Tobbe Jan 1, 2025
cf9d91a
test-project update
Tobbe Jan 1, 2025
1f16d1b
consistent mock values
Tobbe Jan 2, 2025
af40618
feat: showcase the use of relations
esteban-url Jan 3, 2025
21278a5
update snapshots
esteban-url Jan 3, 2025
393068e
Update test project
Tobbe Jan 6, 2025
43773c0
Merge branch 'main' into er-custom-scaffold-files
Tobbe Jan 6, 2025
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
5 changes: 5 additions & 0 deletions .changesets/11755.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- fix(cli): Allow common custom scaffold template files (#11755) by @esteban-url

Adds the ability to generate test, stories and mock files when custom scaffold templates are in use.

Adds initial tests, stories and mocks to the generator they can generated by using the flags `--tests` and `--stories`
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Define your own mock data here:
export const standard = (/* vars, { ctx, req } */) => ({
contact: {
__typename: 'Contact',
id: 42,
name: 'String',
email: 'String',
message: 'String',
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Pass props to your component by passing an `args` object to your story
//
// ```tsx
// export const Primary: Story = {
// args: {
// propName: propValue
// }
// }
// ```
//
// See https://storybook.js.org/docs/react/writing-stories/args.

import type { Meta, StoryObj } from '@storybook/react'

import Contact from './Contact'

const meta: Meta<typeof Contact> = {
component: Contact,
tags: ['autodocs'],
}

export default meta

type Story = StoryObj<typeof Contact>

export const Primary: Story = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { render } from '@redwoodjs/testing/web'

import Contact from './Contact'
import { standard } from './Contact.mock'

// Improve this test with help from the Redwood Testing Doc:
// https://redwoodjs.com/docs/testing#testing-components

describe('Contact', () => {
it('renders successfully', () => {
expect(() => {
render(<Contact contact={standard().contact} />)
}).not.toThrow()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Define your own mock data here:
export const standard = (/* vars, { ctx, req } */) => ({
contact: {
__typename: 'Contact',
id: 42,
name: 'String',
email: 'String',
message: 'String',
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Meta, StoryObj } from '@storybook/react'

import { Loading, Failure, Success } from './ContactCell'
import { standard } from './ContactCell.mock'

const meta: Meta = {
title: 'Cells/ContactCell',
tags: ['autodocs'],
}

export default meta

export const loading: StoryObj<typeof Loading> = {
render: () => {
return Loading ? <Loading /> : <></>
},
}

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} /> : <></>
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { render } from '@redwoodjs/testing/web'

import { Loading, Failure, Success } from './ContactCell'
import { standard } from './ContactCell.mock'

// Improve this test with help from the Redwood Testing Doc:
// https://redwoodjs.com/docs/testing#testing-components

describe('ContactCell', () => {
it('renders loading successfully', () => {
expect(() => {
render(<Loading />)
}).not.toThrow()
})
it('renders failure successfully', () => {
expect(() => {
render(<Failure error={new Error('Oh no')} />)
}).not.toThrow()
})
it('renders successfully', () => {
expect(() => {
render(<Success contact={standard().contact} />)
}).not.toThrow()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Define your own mock data here:
export const standard = (/* vars, { ctx, req } */) => ({
contact: {
__typename: 'Contact',
id: 42,
name: 'String',
email: 'String',
message: 'String',
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Pass props to your component by passing an `args` object to your story
//
// ```tsx
// export const Primary: Story = {
// args: {
// propName: propValue
// }
// }
// ```
//
// See https://storybook.js.org/docs/react/writing-stories/args.

import type { Meta, StoryObj } from '@storybook/react'

import ContactForm from './ContactForm'

const meta: Meta<typeof ContactForm> = {
component: ContactForm,
tags: ['autodocs'],
}

export default meta

type Story = StoryObj<typeof ContactForm>

export const Primary: Story = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { render } from '@redwoodjs/testing/web'

import ContactForm from './ContactForm'

// Improve this test with help from the Redwood Testing Doc:
// https://redwoodjs.com/docs/testing#testing-components

describe('ContactForm', () => {
it('renders successfully', () => {
expect(() => {
render(<ContactForm />)
}).not.toThrow()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Define your own mock data here:
export const standard = (/* vars, { ctx, req } */) => ({
contacts: [
{
__typename: 'Contact',
id: 42,
name: 'String',
email: 'String',
message: 'String',
},
{
__typename: 'Contact',
id: 43,
name: 'String',
email: 'String',
message: 'String',
},
],
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Pass props to your component by passing an `args` object to your story
//
// ```tsx
// export const Primary: Story = {
// args: {
// propName: propValue
// }
// }
// ```
//
// See https://storybook.js.org/docs/react/writing-stories/args.

import type { Meta, StoryObj } from '@storybook/react'

import Contacts from './Contacts'

const meta: Meta<typeof Contacts> = {
component: Contacts,
tags: ['autodocs'],
}

export default meta

type Story = StoryObj<typeof Contacts>

export const Primary: Story = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { render } from '@redwoodjs/testing/web'

import Contacts from './Contacts'
import { standard } from './Contacts.mock'

// Improve this test with help from the Redwood Testing Doc:
// https://redwoodjs.com/docs/testing#testing-components

describe('Contacts', () => {
it('renders successfully', () => {
expect(() => {
render(<Contacts contacts={standard().contacts} />)
}).not.toThrow()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Define your own mock data here:
export const standard = (/* vars, { ctx, req } */) => ({
contacts: [
{
__typename: 'Contact',
id: 42,
name: 'String',
email: 'String',
message: 'String',
},
{
__typename: 'Contact',
id: 43,
name: 'String',
email: 'String',
message: 'String',
},
],
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Meta, StoryObj } from '@storybook/react'

import { Loading, Empty, Failure, Success } from './ContactsCell'
import { standard } from './ContactsCell.mock'

const meta: Meta = {
title: 'Cells/ContactsCell',
tags: ['autodocs'],
}

export default meta

export const loading: StoryObj<typeof Loading> = {
render: () => {
return Loading ? <Loading /> : <></>
},
}

export const failure: StoryObj<typeof Failure> = {
render: (args) => {
return Failure ? <Failure error={new Error('Oh no')} {...args} /> : <></>
},
}

export const empty: StoryObj<typeof Empty> = {
render: (args) => {
return Empty ? <Empty {...args} /> : <></>
},
}

export const success: StoryObj<typeof Success> = {
render: (args) => {
return Success ? <Success {...standard()} {...args} /> : <></>
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { render } from '@redwoodjs/testing/web'

import { Loading, Failure, Empty, Success } from './ContactsCell'
import { standard } from './ContactsCell.mock'

// Improve this test with help from the Redwood Testing Doc:
// https://redwoodjs.com/docs/testing#testing-components

describe('ContactsCell', () => {
it('renders loading successfully', () => {
expect(() => {
render(<Loading />)
}).not.toThrow()
})
it('renders failure successfully', () => {
expect(() => {
render(<Failure error={new Error('Oh no')} />)
}).not.toThrow()
})
it('renders empty successfully', () => {
expect(() => {
render(<Empty />)
}).not.toThrow()
})
it('renders successfully', () => {
expect(() => {
render(<Success contacts={standard().contacts} />)
}).not.toThrow()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Define your own mock data here:
export const standard = (/* vars, { ctx, req } */) => ({
contact: {
__typename: 'Contact',
id: 42,
name: 'String',
email: 'String',
message: 'String',
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Meta, StoryObj } from '@storybook/react'

import { Loading, Failure, Success } from './EditContactCell'
import { standard } from './EditContactCell.mock'

const meta: Meta = {
title: 'Cells/EditContactCell',
tags: ['autodocs'],
}

export default meta

export const loading: StoryObj<typeof Loading> = {
render: () => {
return Loading ? <Loading /> : <></>
},
}

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} /> : <></>
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { render } from '@redwoodjs/testing/web'

import { Loading, Failure, Success } from './EditContactCell'
import { standard } from './EditContactCell.mock'

// Improve this test with help from the Redwood Testing Doc:
// https://redwoodjs.com/docs/testing#testing-components

describe('EditContactCell', () => {
it('renders loading successfully', () => {
expect(() => {
render(<Loading />)
}).not.toThrow()
})
it('renders failure successfully', () => {
expect(() => {
render(<Failure error={new Error('Oh no')} />)
}).not.toThrow()
})
it('renders successfully', () => {
expect(() => {
render(<Success contacts={standard().contacts} />)
}).not.toThrow()
})
})
Loading
Loading