-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
6,974 additions
and
51 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ coverage | |
node_modules | ||
flow-typed | ||
dist | ||
.DS_Store |
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,6 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- node | ||
- 8 | ||
- 6 | ||
- node | ||
- 8 | ||
after_script: 'cat ./coverage/lcov.info | coveralls' |
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,14 @@ | ||
// @flow strict | ||
/* eslint-disable */ | ||
import * as React from 'react'; | ||
import { translate, type I18nType } from '../../src'; | ||
import mockI18n from '../../src/mockI18n'; | ||
|
||
|
||
// Case 1: React stateless component | ||
const StatelessCom = ({ name, i18n }: { name: string, i18n: I18nType }) => ( | ||
<div>{i18n.gettext('S')}</div> | ||
); | ||
const TStatelessCom = translate(StatelessCom); | ||
// Should throw error for missing required prop content | ||
result = <TStatelessCom />; |
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,32 @@ | ||
// @flow strict | ||
/* eslint-disable */ | ||
import * as React from 'react'; | ||
import { translate, type I18nType } from '../../src'; | ||
import mockI18n from '../../src/mockI18n'; | ||
|
||
// Case 1: throw error for missing props | ||
class ComponentB extends React.PureComponent<{ | ||
i18n: I18nType, | ||
content: string, | ||
children: React.Node, | ||
}> { | ||
componentDidMount() { | ||
console.log('hey'); | ||
} | ||
|
||
render() { | ||
const { i18n, content, children } = this.props; | ||
|
||
return ( | ||
<div> | ||
{i18n.gettext('hey')} | ||
{content} | ||
{children} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const TComponentB = translate(ComponentB); | ||
// Should throw error for missing required prop content | ||
const result = <TComponentB >bar</TComponentB>; |
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,40 @@ | ||
// @flow strict | ||
/* eslint-disable */ | ||
import * as React from 'react'; | ||
import { translate, type I18nType } from '../../src'; | ||
import mockI18n from '../../src/mockI18n'; | ||
|
||
//Case 1: class component with static | ||
class ComponentC extends React.Component<{ | ||
i18n: I18nType, | ||
content: string, | ||
children: React.Node, | ||
}> { | ||
static method(str: string) { | ||
console.log('hey', str); | ||
} | ||
|
||
componentDidMount() { | ||
console.log('hey'); | ||
} | ||
|
||
render() { | ||
const { i18n, content, children } = this.props; | ||
|
||
return ( | ||
<div> | ||
{i18n.gettext('hey')} | ||
{content} | ||
{children} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const TComponentC = translate(ComponentC); | ||
const result = <TComponentC content="foo">bar</TComponentC>; | ||
|
||
ComponentC.method('foo'); | ||
|
||
// Should throw Error | ||
TComponentC.WrappedComponent.notExistMethod('foo'); |
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,127 @@ | ||
// @flow strict | ||
/* eslint-disable */ | ||
import * as React from 'react'; | ||
import { translate, type I18nType } from '../src'; | ||
import mockI18n from '../src/mockI18n'; | ||
|
||
let result; | ||
|
||
// Case 1: functional component | ||
const ComponentA = ({ | ||
i18n, | ||
content, | ||
children, | ||
}: { | ||
i18n: I18nType, | ||
content: string, | ||
children: React.Node, | ||
}) => ( | ||
<div> | ||
{i18n.gettext('hey')} | ||
{content} | ||
{children} | ||
</div> | ||
); | ||
|
||
const TComponentA = translate(ComponentA); | ||
result = <TComponentA content="foo">bar</TComponentA>; | ||
result = ( | ||
<TComponentA.WrappedComponent content="foo" i18n={mockI18n}> | ||
bar | ||
</TComponentA.WrappedComponent> | ||
); | ||
|
||
// Case 2: simple class component | ||
class ComponentB extends React.PureComponent<{ | ||
i18n: I18nType, | ||
content: string, | ||
children: React.Node, | ||
}> { | ||
componentDidMount() { | ||
console.log('hey'); | ||
} | ||
|
||
render() { | ||
const { i18n, content, children } = this.props; | ||
|
||
return ( | ||
<div> | ||
{i18n.gettext('hey')} | ||
{content} | ||
{children} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const TComponentB = translate(ComponentB); | ||
result = <TComponentB content="foo">bar</TComponentB>; | ||
|
||
// Case 3: class component with static | ||
class ComponentC extends React.Component<{ | ||
i18n: I18nType, | ||
content: string, | ||
children: React.Node, | ||
}> { | ||
static method(str: string) { | ||
console.log('hey', str); | ||
} | ||
|
||
componentDidMount() { | ||
console.log('hey'); | ||
} | ||
|
||
render() { | ||
const { i18n, content, children } = this.props; | ||
|
||
return ( | ||
<div> | ||
{i18n.gettext('hey')} | ||
{content} | ||
{children} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const TComponentC = translate(ComponentC); | ||
result = <TComponentC content="foo">bar</TComponentC>; | ||
|
||
ComponentC.method('foo'); | ||
TComponentC.WrappedComponent.method('foo'); | ||
// `name` is build-in string prop | ||
const TComponentName = TComponentC.name; | ||
const TComponentDisplayName = TComponentC.displayName; | ||
|
||
// Case 4: class component with defaultProps | ||
class ComponentD extends React.Component<{ | ||
i18n: I18nType, | ||
content: string, | ||
children: React.Node, | ||
}> { | ||
static defaultProps = { | ||
content: 'foo', | ||
}; | ||
|
||
componentDidMount() { | ||
console.log('hey'); | ||
} | ||
|
||
render() { | ||
const { i18n, content, children } = this.props; | ||
|
||
return ( | ||
<div> | ||
{i18n.gettext('hey')} | ||
{content} | ||
{children} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
// Case 4: React stateless component | ||
const StatelessCom = ({name, i18n}: {name: string, i18n: I18nType}) => <div>{i18n.gettext('S')}</div> | ||
const TStatelessCom = translate(StatelessCom); | ||
|
||
result = <TStatelessCom name="Kate" />; |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
// @flow | ||
import 'raf/polyfill'; | ||
import Enzyme from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.