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

Feat: Add shimmer card in tasks page #1300

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
41 changes: 41 additions & 0 deletions __tests__/Unit/pages/Tasks/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Tasks from '@/pages/tasks';
import { store } from '@/app/store';
import { Provider } from 'react-redux';
import { AppTreeType } from 'next/dist/shared/lib/utils';
import { useGetAllTasksQuery } from '@/app/services/tasksApi';

type TaskPageProps = {
dev: boolean;
Expand All @@ -21,7 +22,47 @@ jest.mock('next/router', () => ({
}),
}));

jest.mock('@/app/services/tasksApi', () => ({
useGetAllTasksQuery: jest.fn(),
}));

describe('Tasks', () => {
it('should display shimmer cards when isLoading is true and dev is true', () => {
(useGetAllTasksQuery as jest.Mock).mockReturnValue({
data: { tasks: [], next: '' },
isError: false,
isLoading: true,
isFetching: false,
});

render(
<Provider store={store()}>
<Tasks dev={true} />
</Provider>
);
const skeletonContainer = screen.getByTestId('task-skeleton-container');
expect(skeletonContainer).toBeInTheDocument();

const shimmerCards = screen.getAllByTestId('task-shimmer-card');
expect(shimmerCards).toHaveLength(5);
});

it('should display loading state when isLoading is true', () => {
(useGetAllTasksQuery as jest.Mock).mockReturnValue({
data: { tasks: [], next: '' },
isError: false,
isLoading: true,
isFetching: false,
});

render(
<Provider store={store()}>
<Tasks />
</Provider>
);
expect(screen.getByText('Loading...')).toBeInTheDocument();
});

it('should render the Tasks component', () => {
render(
<Provider store={store()}>
Expand Down
13 changes: 13 additions & 0 deletions src/components/tasks/TasksContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {

import useIntersection from '@/hooks/useIntersection';
import TaskSearchDev from './TaskSearch/TaskSearch';
import TaskCardShimmer from '../Loaders/taskCardShimmer';

export const TasksContent = ({ dev }: { dev?: boolean }) => {
const router = useRouter();
Expand Down Expand Up @@ -127,6 +128,18 @@ export const TasksContent = ({ dev }: { dev?: boolean }) => {
earlyReturn: loadedTasks[selectedTab].length === 0,
});

if (isLoading && dev)
return (
<div
className={styles.taskSkeletonContainer}
data-testid="task-skeleton-container"
>
{[...Array(5)].map((n: number, index) => (
<TaskCardShimmer key={index} />
))}
</div>
);

if (isLoading) return <p>Loading...</p>;

if (isError) return <p>{TASKS_FETCH_ERROR_MESSAGE}</p>;
Expand Down
11 changes: 11 additions & 0 deletions src/styles/tasks.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
width: 64%;
}

.taskSkeletonContainer {
padding: 2rem 0 0;
display: flex;
flex-direction: column;
align-items: center;

@media (max-width: 448px) {
iamitprakash marked this conversation as resolved.
Show resolved Hide resolved
padding: 2rem 1rem 0;
}
}

.container {
text-align: center;
display: flex;
Expand Down
Loading