Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 39 additions & 0 deletions src/renderer/components/metrics/CommentsPill.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { renderWithAppContext } from '../../__helpers__/test-utils';
import { mockGitifyNotification } from '../../__mocks__/notifications-mocks';

import { CommentsPill } from './CommentsPill';

describe('renderer/components/metrics/CommentsPill.tsx', () => {
it('renders with no comments (null)', () => {
const mockNotification = { ...mockGitifyNotification };
mockNotification.subject.commentCount = null;

const tree = renderWithAppContext(
<CommentsPill commentCount={mockNotification.subject.commentCount} />,
);

expect(tree).toMatchSnapshot();
});

it('renders with 1 comment', () => {
const mockNotification = { ...mockGitifyNotification };
mockNotification.subject.commentCount = 1;

const tree = renderWithAppContext(
<CommentsPill commentCount={mockNotification.subject.commentCount} />,
);

expect(tree).toMatchSnapshot();
});

it('renders with multiple comments', () => {
const mockNotification = { ...mockGitifyNotification };
mockNotification.subject.commentCount = 2;

const tree = renderWithAppContext(
<CommentsPill commentCount={mockNotification.subject.commentCount} />,
);

expect(tree).toMatchSnapshot();
});
});
29 changes: 29 additions & 0 deletions src/renderer/components/metrics/CommentsPill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { FC } from 'react';

import { CommentIcon } from '@primer/octicons-react';

import { IconColor } from '../../types';

import { formatMetricDescription } from '../../utils/notifications/formatters';
import { MetricPill } from './MetricPill';

export interface CommentsPillProps {
commentCount: number;
}

export const CommentsPill: FC<CommentsPillProps> = ({ commentCount }) => {
if (!commentCount) {
return null;
}

const description = formatMetricDescription(commentCount, 'comment');

return (
<MetricPill
color={IconColor.GRAY}
icon={CommentIcon}
metric={commentCount}
title={description}
/>
);
};
17 changes: 17 additions & 0 deletions src/renderer/components/metrics/LabelsPill.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { renderWithAppContext } from '../../__helpers__/test-utils';
import { mockGitifyNotification } from '../../__mocks__/notifications-mocks';

import { LabelsPill } from './LabelsPill';

describe('renderer/components/metrics/LabelsPill.tsx', () => {
it('renders labels pill', () => {
const mockNotification = { ...mockGitifyNotification };
mockNotification.subject.labels = ['enhancement', 'good-first-issue'];

const tree = renderWithAppContext(
<LabelsPill labels={mockNotification.subject.labels} />,
);

expect(tree).toMatchSnapshot();
});
});
37 changes: 37 additions & 0 deletions src/renderer/components/metrics/LabelsPill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { FC } from 'react';

import { TagIcon } from '@primer/octicons-react';

import { IconColor } from '../../types';

import { formatMetricDescription } from '../../utils/notifications/formatters';
import { MetricPill } from './MetricPill';

export interface LabelsPillProps {
labels: string[];
}

export const LabelsPill: FC<LabelsPillProps> = ({ labels }) => {
if (!labels?.length) {
return null;
}

const description = formatMetricDescription(
labels.length,
'label',
(count, noun) => {
const formatted = labels.map((label) => `🏷️ ${label}`).join(', ');

return `${count} ${noun}: ${formatted}`;
},
);

return (
<MetricPill
color={IconColor.GRAY}
icon={TagIcon}
metric={labels.length}
title={description}
/>
);
};
28 changes: 28 additions & 0 deletions src/renderer/components/metrics/LinkedIssuesPill.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { renderWithAppContext } from '../../__helpers__/test-utils';
import { mockGitifyNotification } from '../../__mocks__/notifications-mocks';

import { LinkedIssuesPill } from './LinkedIssuesPill';

describe('renderer/components/metrics/LinkedIssuesPill.tsx', () => {
it('renders when linked to one issue/pr', () => {
const mockNotification = { ...mockGitifyNotification };
mockNotification.subject.linkedIssues = ['#1'];

const tree = renderWithAppContext(
<LinkedIssuesPill linkedIssues={mockNotification.subject.linkedIssues} />,
);

expect(tree).toMatchSnapshot();
});

it('renders when linked to multiple issues/prs', () => {
const mockNotification = { ...mockGitifyNotification };
mockNotification.subject.linkedIssues = ['#1', '#2'];

const tree = renderWithAppContext(
<LinkedIssuesPill linkedIssues={mockNotification.subject.linkedIssues} />,
);

expect(tree).toMatchSnapshot();
});
});
35 changes: 35 additions & 0 deletions src/renderer/components/metrics/LinkedIssuesPill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { FC } from 'react';

import { IssueOpenedIcon } from '@primer/octicons-react';

import { IconColor } from '../../types';

import { formatMetricDescription } from '../../utils/notifications/formatters';
import { MetricPill } from './MetricPill';

export interface LinkedIssuesPillProps {
linkedIssues: string[];
}

export const LinkedIssuesPill: FC<LinkedIssuesPillProps> = ({
linkedIssues,
}) => {
if (!linkedIssues?.length) {
return null;
}

const description = formatMetricDescription(
linkedIssues.length,
'issue',
(count, noun) => `Linked to ${count} ${noun}: ${linkedIssues.join(', ')}`,
);

return (
<MetricPill
color={IconColor.GRAY}
icon={IssueOpenedIcon}
metric={linkedIssues.length}
title={description}
/>
);
};
Loading