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

Remove Feature Flag for progress updates section in tasks deatails page Status site. #1093

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
43 changes: 30 additions & 13 deletions __tests__/Unit/Components/Tasks/ProgressCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { Provider } from 'react-redux';
import { store } from '@/app/store';
import ProgressCard from '@/components/ProgressCard';
import { renderWithRouter } from '@/test_utils/createMockRouter';
import { fireEvent, screen } from '@testing-library/react';
import moment from 'moment';
import { setupServer } from 'msw/node';
import handlers from '../../../../__mocks__/handlers';
import { Provider } from 'react-redux';
import { mockGetTaskProgress } from '../../../../__mocks__/db/progresses';
import ProgressCard from '@/components/ProgressCard';
import handlers from '../../../../__mocks__/handlers';

const server = setupServer(...handlers);

Expand All @@ -15,11 +16,21 @@ beforeAll(() => {
});
});

const dateInAgoFormatOne = moment(
mockGetTaskProgress.data[0].createdAt
).fromNow();
const dateInAgoFormatTwo = moment(
mockGetTaskProgress.data[1].createdAt
).fromNow();
const dateInAgoFormatThree = moment(
mockGetTaskProgress.data[2].createdAt
).fromNow();

afterEach(() => server.resetHandlers());
afterAll(() => server.close());

describe('ProgressCard Component', () => {
it('shuld render the ProgressCard', async () => {
it('should render the ProgressCard', async () => {
renderWithRouter(
<Provider store={store()}>
<ProgressCard taskProgress={mockGetTaskProgress.data} />
Expand Down Expand Up @@ -55,12 +66,12 @@ describe('ProgressCard Component', () => {
</Provider>
);
const progressArr = container.querySelectorAll(
'[data-testid="progress-item"]'
'[data-testid="progress-update-card-date"]'
);
expect(progressArr[0]).toHaveTextContent('Wednesday, 31 May 2023');

expect(progressArr[1]).toHaveTextContent('Wednesday, 31 May 2023');
expect(progressArr[2]).toHaveTextContent('Sunday, 28 May 2023');
expect(progressArr[0]).toHaveTextContent(dateInAgoFormatOne);
expect(progressArr[1]).toHaveTextContent(dateInAgoFormatTwo);
expect(progressArr[2]).toHaveTextContent(dateInAgoFormatThree);
});
it('should render the progress enteries in dscending order after Dsc btn click ', async () => {
const { container, getByRole } = renderWithRouter(
Expand All @@ -72,10 +83,16 @@ describe('ProgressCard Component', () => {
const btn = getByRole('button', { name: 'Dsc' });
fireEvent.click(btn);
const progressArr = container.querySelectorAll(
'[data-testid="progress-item"]'
'[data-testid="progress-update-card-date"]'
);
expect(progressArr[progressArr.length - 1]).toHaveTextContent(
dateInAgoFormatOne
);
expect(progressArr[progressArr.length - 2]).toHaveTextContent(
dateInAgoFormatTwo
);
expect(progressArr[progressArr.length - 3]).toHaveTextContent(
dateInAgoFormatThree
);
expect(progressArr[2]).toHaveTextContent('Wednesday, 31 May 2023');
expect(progressArr[1]).toHaveTextContent('Sunday, 28 May 2023');
expect(progressArr[0]).toHaveTextContent('Saturday, 27 May 2023');
});
});
82 changes: 15 additions & 67 deletions __tests__/Unit/Components/Tasks/ProgressDetails.test.tsx
Original file line number Diff line number Diff line change
@@ -1,90 +1,38 @@
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { Provider } from 'react-redux';
import { store } from '@/app/store';
import ProgressUpdateCard from '@/components/taskDetails/ProgressUpdateCard/ProgressUpdateCard';
import { renderWithRouter } from '@/test_utils/createMockRouter';
import { screen } from '@testing-library/react';
import { setupServer } from 'msw/node';
import handlers from '../../../../__mocks__/handlers';
import { Provider } from 'react-redux';
import { mockGetTaskProgress } from '../../../../__mocks__/db/progresses';
import ProgressDetails from '@/components/taskDetails/ProgressDetails';
import handlers from '../../../../__mocks__/handlers';

const server = setupServer(...handlers);

let mockedOpenDetailsFunction: jest.Mock<void, [React.MouseEvent<HTMLElement>]>;

beforeAll(() => {
server.listen({
onUnhandledRequest: 'error',
});
mockedOpenDetailsFunction =
jest.fn<void, [React.MouseEvent<HTMLElement>]>();
});
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

describe('ProgressDetails Component', () => {
it('should render the ProgressDetails', async () => {
renderWithRouter(
<Provider store={store()}>
<ProgressDetails data={mockGetTaskProgress.data[2]} />
</Provider>
);

const progress = screen.getByTestId('progress-item');
expect(progress).toBeInTheDocument();
expect(progress).toHaveTextContent('Wednesday, 31 May 2023');
});
it('should open the modal with the specific progress details when clicked on details', () => {
renderWithRouter(
<Provider store={store()}>
<ProgressDetails data={mockGetTaskProgress.data[2]} />
</Provider>
);

const progress = screen.getByTestId('progress-item');
fireEvent.click(progress);

const modalBackground = screen.getByTestId('modal-background');
const content = screen.getByTestId('content');
const completed = screen.getByText('Completed:');

expect(modalBackground).toBeInTheDocument();
expect(content).toBeInTheDocument();
expect(completed).toBeInTheDocument();
});

it('should close the modal when clicking outside the modal', () => {
it('should render the ProgressUpdateCard', async () => {
renderWithRouter(
<Provider store={store()}>
<ProgressDetails data={mockGetTaskProgress.data[2]} />
<ProgressUpdateCard
data={mockGetTaskProgress.data[2]}
openDetails={mockedOpenDetailsFunction}
/>
</Provider>
);

const progress = screen.getByTestId('progress-item');
fireEvent.click(progress);

const modalBackground = screen.getByTestId('modal-background');
const content = screen.getByTestId('content');

expect(modalBackground).toBeInTheDocument();
fireEvent.click(modalBackground);

expect(content).not.toBeInTheDocument();
});

it('should close the modal on clicking CLOSE button', () => {
renderWithRouter(
<Provider store={store()}>
<ProgressDetails data={mockGetTaskProgress.data[2]} />
</Provider>
);

const progress = screen.getByTestId('progress-item');
fireEvent.click(progress);

const closeButton = screen.getByText('Close');
expect(closeButton).toBeInTheDocument();

const content = screen.getByTestId('content');
expect(content).toBeInTheDocument();

fireEvent.click(closeButton);

expect(content).not.toBeInTheDocument();
const cardTitle = screen.getByRole('heading');
expect(cardTitle).toBeInTheDocument();
});
});
13 changes: 5 additions & 8 deletions src/components/ProgressCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { useRouter } from 'next/router';
import React, { useEffect, useState } from 'react';
import TaskContainer from '../taskDetails/TaskContainer';
import styles from '@/components/ProgressCard/ProgressCard.module.scss';
import { ProgressDetailsData } from '@/types/standup.type';
import { useEffect, useState } from 'react';
import ProgressDetails from '../taskDetails/ProgressDetails';
import styles from '@/components/ProgressCard/ProgressCard.module.scss';
import LatestProgressUpdateCard from '../taskDetails/ProgressUpdateCard/LatestProgressUpdateCard';
import TaskContainer from '../taskDetails/TaskContainer';

type SortedProgressType = { data: ProgressDetailsData[]; order: number };

type Props = { taskProgress: ProgressDetailsData[] };

export default function ProgressCard({ taskProgress }: Props) {
const [sortedProgress, setSortedProgress] = useState<SortedProgressType>();
const isDev = useRouter().query?.dev === 'true';
const sortedProgressLength = sortedProgress?.data?.length;

const reverseSortingOrder = () => {
Expand Down Expand Up @@ -44,7 +42,7 @@ export default function ProgressCard({ taskProgress }: Props) {
}, [taskProgress]);

const cardsToShow = sortedProgress?.data?.map((progress, idx) => {
if (idx === 0 && sortedProgress?.order === 1 && isDev) {
if (idx === 0 && sortedProgress?.order === 1) {
return (
<LatestProgressUpdateCard key={progress.id} data={progress} />
);
Expand All @@ -53,8 +51,7 @@ export default function ProgressCard({ taskProgress }: Props) {
if (
sortedProgressLength &&
idx === sortedProgressLength - 1 &&
sortedProgress?.order === 0 &&
isDev
sortedProgress?.order === 0
) {
return (
<LatestProgressUpdateCard key={progress.id} data={progress} />
Expand Down
62 changes: 2 additions & 60 deletions src/components/taskDetails/ProgressDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { useState, FC, MouseEvent } from 'react';
import { ProgressDetailsData } from '@/types/standup.type';
import { getDateFromTimestamp } from '@/utils/getDateFromTimestamp';
import styles from './progress-details.module.scss';
import { useRouter } from 'next/router';
import { FC, MouseEvent, useState } from 'react';
import ProgressUpdateCard from './ProgressUpdateCard/ProgressUpdateCard';

type Props = {
data: ProgressDetailsData;
};
const ProgressDetails: FC<Props> = ({ data }) => {
const router = useRouter();
const [showProgressDetails, setShowProgressDetails] =
useState<boolean>(false);

Expand All @@ -21,61 +17,7 @@ const ProgressDetails: FC<Props> = ({ data }) => {
setShowProgressDetails(false);
};

const isDev = router.query.dev === 'true';
return (
<>
{isDev ? (
<ProgressUpdateCard data={data} openDetails={openDetails} />
) : (
<li
onClick={openDetails}
className={styles['list-item']}
data-testid="progress-item"
>
{getDateFromTimestamp(data.date)}
</li>
)}
{showProgressDetails && (
<div className={styles['container-parent']}>
<div
role="button"
className={styles['container-back']}
onClick={closeDetails}
data-testid="modal-background"
></div>

<div className={styles['container-main']}>
<h2>{getDateFromTimestamp(data.date)}</h2>
<div
className={styles['content']}
data-testid="content"
>
<div className={styles['content-wrapper']}>
<div className={styles['content-item']}>
<span>Completed:</span>
<p>{data.completed}</p>
</div>
<div className={styles['content-item']}>
<span>Planned:</span>
<p>{data.planned}</p>
</div>
<div className={styles['content-item']}>
<span>Blockers:</span>
<p>{data.blockers}</p>
</div>
</div>
</div>
<button
className={styles['container-close']}
onClick={closeDetails}
>
Close
</button>
</div>
</div>
)}
</>
);
return <ProgressUpdateCard data={data} openDetails={openDetails} />;
};

export default ProgressDetails;
Loading
Loading