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

Activity timeline refactoring followup #5835

Merged
merged 5 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
Weiko committed Jun 12, 2024
commit b6c05f7c277f0cc990476e46730810323f9a7b92
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const EventCardCalendarEvent = ({
return <div>Calendar event not found</div>;
}

return <div>Error loading message</div>;
return <div>Error loading calendar event</div>;
}

if (loading || isUndefined(calendarEvent)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Meta, StoryObj } from '@storybook/react';
import { graphql, HttpResponse } from 'msw';
import { ComponentDecorator } from 'twenty-ui';

import { TimelineActivityContext } from '@/activities/timelineActivities/contexts/TimelineActivityContext';
import { EventCardMessage } from '@/activities/timelineActivities/rows/message/components/EventCardMessage';
import { ObjectMetadataItemsDecorator } from '~/testing/decorators/ObjectMetadataItemsDecorator';
import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';

const meta: Meta<typeof EventCardMessage> = {
title: 'Modules/TimelineActivities/Rows/Message/EventCardMessage',
component: EventCardMessage,
decorators: [
ComponentDecorator,
ObjectMetadataItemsDecorator,
SnackBarDecorator,
(Story) => {
return (
<TimelineActivityContext.Provider
value={{
labelIdentifierValue: 'Mock',
}}
>
<Story />
</TimelineActivityContext.Provider>
);
},
],
};

export default meta;
type Story = StoryObj<typeof EventCardMessage>;

export const Default: Story = {
args: {
messageId: '1',
authorFullName: 'John Doe',
},
parameters: {
msw: {
handlers: [
graphql.query('FindOneMessage', () => {
return HttpResponse.json({
data: {
message: {
id: '1',
subject: 'Mock title',
text: 'Mock body',
messageParticipants: [],
},
},
});
}),
],
},
},
};

export const NotShared: Story = {
args: {
messageId: '1',
authorFullName: 'John Doe',
},
parameters: {
msw: {
handlers: [
graphql.query('FindOneMessage', () => {
return HttpResponse.json({
errors: [
{
message: 'Forbidden',
extensions: {
code: 'FORBIDDEN',
},
},
],
});
}),
],
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3638,7 +3638,7 @@ export const getObjectMetadataItemsMock = () => {
},
{
__typename: 'object',
id: '20202020-049d-4d0c-9e7c-e74fee3f88b2',
id: '20202020-6736-4337-b5c4-8b39fae325a5',
dataSourceId: '20202020-7f63-47a9-b1b3-6c7290ca9fb1',
nameSingular: 'timelineActivity',
namePlural: 'timelineActivities',
Expand All @@ -3654,6 +3654,24 @@ export const getObjectMetadataItemsMock = () => {
updatedAt: '2023-11-30T11:13:15.206Z',
fields: [],
},
{
__typename: 'object',
id: '20202020-3f6b-4425-80ab-e468899ab4b2',
dataSourceId: '20202020-7f63-47a9-b1b3-6c7290ca9fb1',
nameSingular: 'message',
namePlural: 'messages',
labelSingular: 'Message',
labelPlural: 'Messages',
description: 'A message',
icon: 'IconMessage',
isCustom: false,
isRemote: false,
isActive: true,
isSystem: true,
createdAt: '2023-11-30T11:13:15.206Z',
updatedAt: '2023-11-30T11:13:15.206Z',
fields: [],
},
];

// Todo fix typing here (the backend is not in sync with the frontend)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
formatToHumanReadableDay,
formatToHumanReadableMonth,
formatToHumanReadableTime,
} from '../formatDate';

describe('formatToHumanReadableMonth', () => {
it('should format the date to a human-readable month', () => {
const date = new Date('2022-01-01');
const result = formatToHumanReadableMonth(date);
expect(result).toBe('Jan');
});
});

describe('formatToHumanReadableDay', () => {
it('should format the date to a human-readable day', () => {
const date = new Date('2022-01-01');
const result = formatToHumanReadableDay(date);
expect(result).toBe('1');
});
});

describe('formatToHumanReadableTime', () => {
it('should format the date to a human-readable time', () => {
const date = new Date('2022-01-01T12:30:00');
const result = formatToHumanReadableTime(date);
expect(result).toBe('12:30 PM');
});
});
26 changes: 26 additions & 0 deletions packages/twenty-front/src/utils/format/formatDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { parseDate } from '~/utils/date-utils';

export const formatToHumanReadableMonth = (date: Date | string) => {
const parsedJSDate = parseDate(date).toJSDate();

return new Intl.DateTimeFormat(undefined, {
month: 'short',
}).format(parsedJSDate);
};

export const formatToHumanReadableDay = (date: Date | string) => {
const parsedJSDate = parseDate(date).toJSDate();

return new Intl.DateTimeFormat(undefined, {
day: 'numeric',
}).format(parsedJSDate);
};

export const formatToHumanReadableTime = (date: Date | string) => {
const parsedJSDate = parseDate(date).toJSDate();

return new Intl.DateTimeFormat(undefined, {
hour: 'numeric',
minute: 'numeric',
}).format(parsedJSDate);
};
25 changes: 0 additions & 25 deletions packages/twenty-front/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,6 @@ export const formatToHumanReadableDateTime = (date: Date | string) => {
}).format(parsedJSDate);
};

export const formatToHumanReadableMonth = (date: Date | string) => {
const parsedJSDate = parseDate(date).toJSDate();

return new Intl.DateTimeFormat(undefined, {
month: 'short',
}).format(parsedJSDate);
};

export const formatToHumanReadableDay = (date: Date | string) => {
const parsedJSDate = parseDate(date).toJSDate();

return new Intl.DateTimeFormat(undefined, {
day: 'numeric',
}).format(parsedJSDate);
};

export const formatToHumanReadableTime = (date: Date | string) => {
const parsedJSDate = parseDate(date).toJSDate();

return new Intl.DateTimeFormat(undefined, {
hour: 'numeric',
minute: 'numeric',
}).format(parsedJSDate);
};

export const sanitizeURL = (link: string | null | undefined) => {
return link
? link.replace(/(https?:\/\/)|(www\.)/g, '').replace(/\/$/, '')
Expand Down
Loading