Update snapshots

This commit is contained in:
Chi Vinh Le
2018-07-12 16:23:27 -03:00
parent 37338ceab9
commit 11d667cfb8
4 changed files with 29 additions and 6 deletions
@@ -8,8 +8,10 @@ import Timestamp from './Timestamp'
# Timestamp
Renders relative time until given `date`.
## Basic usage
<Playground>
<Timestamp date={`2018-07-04T12:14:14.564Z`} />
<Timestamp date="2018-07-04T12:14"
formatter={(value, unit, suffix, timestamp) => "".concat(value, " ", unit, " ", suffix)} />
</Playground>
@@ -15,7 +15,7 @@ it("uses default formatter", () => {
it("uses formatter from context", () => {
const context: any = {
timeagoFormatter: () => "My Formatter",
timeagoFormatter: () => "My Context Formatter",
};
const props = {
date: new Date("December 17, 2108 03:24:00").toISOString(),
@@ -28,3 +28,13 @@ it("uses formatter from context", () => {
expect(tree).toMatchSnapshot();
});
it("uses formatter from props", () => {
const props = {
date: new Date("December 17, 2108 03:24:00").toISOString(),
formatter: () => "My Props Formatter",
};
const tree = create(<Timestamp {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
@@ -13,6 +13,7 @@ interface InnerProps {
live?: boolean;
classes: typeof styles;
className?: string;
formatter?: Formatter;
}
const defaultFormatter: Formatter = (value, unit, suffix, timestamp: string) =>
@@ -20,7 +21,7 @@ const defaultFormatter: Formatter = (value, unit, suffix, timestamp: string) =>
class Timestamp extends React.Component<InnerProps> {
public render() {
const { date, classes, live, className } = this.props;
const { date, classes, live, className, formatter } = this.props;
return (
<UIContext.Consumer>
{({ timeagoFormatter }) => (
@@ -28,7 +29,7 @@ class Timestamp extends React.Component<InnerProps> {
date={date}
className={cn(className, classes.root)}
live={live}
formatter={timeagoFormatter || defaultFormatter}
formatter={timeagoFormatter || formatter || defaultFormatter}
/>
)}
</UIContext.Consumer>
@@ -16,6 +16,16 @@ exports[`uses formatter from context 1`] = `
dateTime="2108-12-17T06:24:00.000Z"
title="2108-12-17T06:24:00.000Z"
>
My Formatter
My Context Formatter
</time>
`;
exports[`uses formatter from props 1`] = `
<time
className="root"
dateTime="2108-12-17T06:24:00.000Z"
title="2108-12-17T06:24:00.000Z"
>
My Props Formatter
</time>
`;