-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: plop and generators set up (#5)
Co-authored-by: Jérémy Fumeron <jeremy.fumeron@ubisoft.com>
- Loading branch information
Showing
40 changed files
with
1,128 additions
and
35 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 |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
node_modules | ||
out | ||
styled-system | ||
public | ||
public | ||
plop-templates | ||
CHANGELOG.md |
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,4 +1,6 @@ | ||
.next | ||
node_modules | ||
out | ||
styled-system | ||
styled-system | ||
plop-templates | ||
CHANGELOG.md |
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
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,37 @@ | ||
import { act, renderHook } from '@testing-library/react'; | ||
|
||
import use{{pascalCase name}}Behavior from '../behavior'; | ||
|
||
describe('use{{pascalCase name}}Behavior', () => { | ||
it('should initialize count with the provided initialCount', () => { | ||
const { result } = renderHook(() => | ||
use{{pascalCase name}}Behavior({ initialCount: 5 }), | ||
); | ||
|
||
expect(result.current.count).toBe(5); | ||
}); | ||
|
||
it('should increment count when increment function is called', () => { | ||
const { result } = renderHook(() => | ||
use{{pascalCase name}}Behavior({ initialCount: 0 }), | ||
); | ||
|
||
act(() => { | ||
result.current.increment(); | ||
}); | ||
|
||
expect(result.current.count).toBe(1); | ||
}); | ||
|
||
it('should decrement count when decrement function is called', () => { | ||
const { result } = renderHook(() => | ||
use{{pascalCase name}}Behavior({ initialCount: 3 }), | ||
); | ||
|
||
act(() => { | ||
result.current.decrement(); | ||
}); | ||
|
||
expect(result.current.count).toBe(2); | ||
}); | ||
}); |
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,25 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
|
||
interface {{pascalCase name}}BehaviorProps { | ||
readonly initialCount: number; | ||
} | ||
|
||
const use{{pascalCase name}}Behavior = ({ | ||
initialCount, | ||
}: {{pascalCase name}}BehaviorProps) => { | ||
const [count, setCount] = useState(initialCount); | ||
|
||
const increment = () => { | ||
setCount(count + 1); | ||
}; | ||
|
||
const decrement = () => { | ||
setCount(count - 1); | ||
}; | ||
|
||
return { count, increment, decrement }; | ||
}; | ||
|
||
export default use{{pascalCase name}}Behavior; |
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,16 @@ | ||
import { render } from '@testing-library/react'; | ||
|
||
import {{pascalCase name}} from '..'; | ||
|
||
describe('{{pascalCase name}}', () => { | ||
it('renders without error', () => { | ||
|
||
}); | ||
|
||
it('component matches snapshot', async () => { | ||
const view = render( | ||
<{{pascalCase name}} />, | ||
); | ||
expect(view.container).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{{#if isClient}} | ||
'use client'; | ||
|
||
{{/if}} | ||
import React from 'react'; | ||
|
||
{{#if hasBehavior}} | ||
import use{{pascalCase name}}Behavior from './behavior'; | ||
{{/if}} | ||
|
||
{{#if hasTranslation}} | ||
import { TLocale } from '@/interfaces'; | ||
import { getComponentsTranslation } from '@/utils/translate'; | ||
|
||
interface {{pascalCase name}}Props { | ||
readonly lang: TLocale; | ||
} | ||
const {{pascalCase name}} = ({ lang }: {{pascalCase name}}Props): React.JSX.Element => { | ||
const { {{camelCase name}}: t{{pascalCase name}} } = getComponentsTranslation(lang, ['{{camelCase name}}']); | ||
{{#if hasBehavior}} | ||
const { tochange } = use{{pascalCase name}}Behavior; | ||
{{/if}} | ||
|
||
return ( | ||
<div> | ||
{t{{pascalCase name}}['label']} | ||
</div> | ||
); | ||
}; | ||
{{else}} | ||
{{#if hasBehavior}} | ||
const {{pascalCase name}} = (): React.JSX.Element => { | ||
const { tochange } = use{{pascalCase name}}Behavior; | ||
return ( | ||
<div> | ||
{{pascalCase name}} | ||
</div> | ||
); | ||
}; | ||
{{else}} | ||
const {{pascalCase name}} = (): React.JSX.Element => ( | ||
<div> | ||
{{pascalCase name}} | ||
</div> | ||
); | ||
{{/if}} | ||
{{/if}} | ||
|
||
export default {{pascalCase name}}; |
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 @@ | ||
import { TLangContent } from '@/interfaces/langs.interface'; | ||
|
||
export const {{camelCase name}}: TLangContent = { | ||
label: { | ||
en: '🛑 {{camelCase name}} TO CHANGE 🛑', | ||
fr: '🛑 {{camelCase name}} TO CHANGE 🛑', | ||
}, | ||
}; |
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,61 @@ | ||
import { render } from '@testing-library/react'; | ||
|
||
import { | ||
getComponentsTranslation, | ||
getMetadataPageTranslation, | ||
getPageTranslation, | ||
} from '@/utils/translate'; | ||
|
||
import {{pascalCase name}}, { generateMetadata, generateStaticParams } from '../page'; | ||
|
||
jest.mock('@/utils/translate', () => ({ | ||
getPageTranslation: jest.fn(), | ||
getComponentsTranslation: jest.fn(), | ||
getMetadataPageTranslation: jest.fn(), | ||
})); | ||
|
||
|
||
|
||
describe('{{pascalCase name}}', () => { | ||
describe('Page', () => { | ||
it('component matches snapshot', async () => { | ||
const view = render( | ||
<{{pascalCase name}} params={ { lang: 'fr' } }/>, | ||
); | ||
expect(view.container).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
|
||
describe('generateStaticParams', () => { | ||
it('should generate static params for all available locales', async () => { | ||
const staticParams = await generateStaticParams(); | ||
expect(staticParams).toHaveLength(2); | ||
expect(staticParams).toEqual( | ||
expect.arrayContaining([{ lang: 'en' }, { lang: 'fr' }]), | ||
); | ||
}); | ||
}); | ||
|
||
|
||
describe('generateMetadata', () => { | ||
it('should generate metadata for locale', async () => { | ||
const mockMTranslationData = { | ||
title: 'Lorem ipsum dolor sit amet.', | ||
description: | ||
'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo architecto mollitia blanditiis, accusantium quibusdam possimus officia eligendi eveniet nostrum iure.', | ||
}; | ||
|
||
(getMetadataPageTranslation as jest.Mock).mockReturnValue( | ||
mockMTranslationData, | ||
); | ||
|
||
const metadata = await generateMetadata({ params: { lang: 'en' } }); | ||
expect(metadata).toEqual(mockMTranslationData); | ||
expect(getMetadataPageTranslation as jest.Mock).toHaveBeenCalledWith( | ||
'en', | ||
'{{camelCase name}}', | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.