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

Addon-interactions: Fix using dates in expect statements #28413

Open
wants to merge 8 commits into
base: next-8.5
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const Args = () => (
/>
<Node value={{ __date__: { value: new Date(1600000000000).toISOString() } }} />
<Node value={{ __date__: { value: new Date(1600000000123).toISOString() } }} />
<Node value={{ __date__: { value: new Date(1600000000123) } }} />
<Node value={{ __error__: { name: 'EvalError', message: '' } }} />
<Node value={{ __error__: { name: 'SyntaxError', message: "Can't do that" } }} />
<Node
Expand Down
28 changes: 22 additions & 6 deletions code/addons/interactions/src/components/MethodCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,32 @@ export const ElementNode = ({
);
};

export const DateNode = ({ value }: { value: string }) => {
const [date, time, ms] = value.split(/[T.Z]/);
export const DateNode = ({ value }: { value: string | Date }) => {
let dateSplit: string[] = [];
if (value instanceof Date) {
try {
dateSplit = value.toISOString().split(/[T.Z]/);
} catch (error) {
console.error('Invalid date value provided to DateNode:', value);
dateSplit = ['Invalid date', '', ''];
ghengeveld marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
dateSplit = value.split(/[T.Z]/);
}
yann-combarnous marked this conversation as resolved.
Show resolved Hide resolved
const [date, time, ms] = dateSplit;

const colors = useThemeColors();
return (
<span style={{ whiteSpace: 'nowrap', color: colors.date }}>
{date}
<span style={{ opacity: 0.7 }}>T</span>
{time === '00:00:00' ? <span style={{ opacity: 0.7 }}>{time}</span> : time}
{ms === '000' ? <span style={{ opacity: 0.7 }}>.{ms}</span> : `.${ms}`}
<span style={{ opacity: 0.7 }}>Z</span>
{ date !== 'Invalid date' && (
<>
<span style={{ opacity: 0.7 }}>T</span>
{time === '00:00:00' ? <span style={{ opacity: 0.7 }}>{time}</span> : time}
{ms === '000' ? <span style={{ opacity: 0.7 }}>.{ms}</span> : `.${ms}`}
<span style={{ opacity: 0.7 }}>Z</span>
</>
)}
</span>
);
yann-combarnous marked this conversation as resolved.
Show resolved Hide resolved
};
Expand Down
Loading