Skip to content

Commit

Permalink
feat:issue#1263 | Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Saitharun279 authored Jan 18, 2025
1 parent 2088552 commit 90f78e4
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 7 deletions.
48 changes: 47 additions & 1 deletion __tests__/Unit/Components/Tasks/Card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const DEFAULT_PROPS = {
startedOn: '1618790400',
isNoteworthy: true,
title: 'test 1 for drag and drop',
purpose: 'string',
purpose: 'to test purpose',
percentCompleted: 0,
endsOn: 1618790400,
status: COMPLETED,
Expand All @@ -54,9 +54,55 @@ const DEFAULT_PROPS = {
onContentChange: jest.fn(),
};

describe("Task card, self task's purpose and status", () => {
it('renders the card with title and status', () => {
renderWithRouter(
<Provider store={store()}>
<Card {...DEFAULT_PROPS} />
</Provider>,
{
query: { dev: 'true' },
}
);
expect(
screen.getByText('test 1 for drag and drop')
).toBeInTheDocument();
expect(screen.getByText('Done')).toBeInTheDocument();
});

it('displays the purpose if provided', () => {
renderWithRouter(
<Provider store={store()}>
<Card {...DEFAULT_PROPS} />
</Provider>,
{
query: { dev: 'true' },
}
);
expect(screen.getByText('to test purpose')).toBeInTheDocument();
});

it('does not display the purpose if not provided', () => {
const PROPS_WITHOUT_PURPOSE = {
...DEFAULT_PROPS,
content: { ...DEFAULT_PROPS.content, purpose: '' },
};
renderWithRouter(
<Provider store={store()}>
<Card {...PROPS_WITHOUT_PURPOSE} />
</Provider>,
{
query: { dev: 'true' },
}
);
expect(screen.queryByText('to test purpose')).not.toBeInTheDocument();
});
});

jest.mock('@/hooks/useUserData', () => {
return () => ({
data: {
username: 'ankur',
roles: {
admin: true,
super_user: true,
Expand Down
23 changes: 23 additions & 0 deletions __tests__/Unit/Components/Tasks/TaskDropDown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ describe('TaskDropDown', () => {
expect(onChange).toHaveBeenCalledTimes(0);
expect(screen.getByTestId('task-status')).toHaveValue(oldStatus);
});

it('should render cardPurposeAndStatusFont for label and taskStatusUpdate for select when isDevMode is true', () => {
const oldProgress = 100;
const oldStatus = BACKEND_TASK_STATUS.NEEDS_REVIEW;
const TASK_STATUS_UPDATE = 'taskStatusUpdate';
const CARD_PURPOSE_STATUS_FONT = 'cardPurposeAndStatusFont';

render(
<TaskDropDown
isDevMode={true}
oldProgress={oldProgress}
oldStatus={oldStatus}
onChange={onChange}
/>
);
expect(screen.getByTestId('task-status')).toHaveClass(
TASK_STATUS_UPDATE
);
expect(screen.getByTestId('task-status-label')).toHaveClass(
CARD_PURPOSE_STATUS_FONT
);
});

it('should not show any model info on change of status from in progress to backlog', () => {
const oldProgress = 80;
const oldStatus = BACKEND_TASK_STATUS.IN_PROGRESS;
Expand Down
23 changes: 23 additions & 0 deletions __tests__/Unit/Components/Tasks/TaskStatusEditMode.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ const BLOCKED_TASK = {

describe('TaskStatusEditMode', () => {
let updateTaskSpy: any;
let updateSelfTaskSpy: any;
beforeEach(() => {
updateTaskSpy = jest.spyOn(tasksApi, 'useUpdateTaskMutation');
updateSelfTaskSpy = jest.spyOn(tasksApi, 'useUpdateSelfTaskMutation');
});

afterEach(() => {
Expand Down Expand Up @@ -173,6 +175,27 @@ describe('TaskStatusEditMode', () => {
expect(screen.getByTestId('error')).toBeInTheDocument();
});
});

it('change task status from BLOCKED to IN_PROGRESS when and isDevMode are true', async () => {
const setEditedTaskDetails = jest.fn();

renderWithRouter(
<Provider store={store()}>
<TaskStatusEditMode
task={BLOCKED_TASK}
setEditedTaskDetails={setEditedTaskDetails}
isDevMode={true}
isSelfTask={true}
/>
</Provider>
);

const statusSelect = screen.getByLabelText('Status:');
expect(statusSelect).toHaveValue('BLOCKED');

fireEvent.change(statusSelect, { target: { value: 'IN_PROGRESS' } });
expect(statusSelect).toHaveValue('IN_PROGRESS');
});
});

describe('test beautifyStatus function', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/tasks/TaskDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ export default function TaskDropDown({
if (isDevMode) {
return (
<>
<label className={styles.cardPurposeAndStatusFont}>
<label
className={styles.cardPurposeAndStatusFont}
data-testid="task-status-label"
>
Status:
<select
className={styles.taskStatusUpdate}
Expand Down
7 changes: 2 additions & 5 deletions src/components/tasks/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
import { useGetUsersByUsernameQuery } from '@/app/services/usersApi';
import { ConditionalLinkWrapper } from './ConditionalLinkWrapper';
import useUserData from '@/hooks/useUserData';
import { useGetUserQuery } from '@/app/services/userApi';
import { isTaskDetailsPageLinkEnabled } from '@/constants/FeatureFlags';
import { useUpdateTaskMutation } from '@/app/services/tasksApi';
import ProgressIndicator from './progressContainer/ProgressIndicator';
Expand Down Expand Up @@ -74,9 +73,7 @@ const Card: FC<CardProps> = ({
userResponse?.users[0]?.picture?.url || placeholderImageURL;
const { SUCCESS, ERROR } = ToastTypes;

const { isUserAuthorized } = useUserData();

const { data: userData } = useGetUserQuery();
const { data, isUserAuthorized } = useUserData();

const [showEditButton, setShowEditButton] = useState(false);

Expand Down Expand Up @@ -269,7 +266,7 @@ const Card: FC<CardProps> = ({
setIsEditMode(true);
};
const isEditable = shouldEdit && isUserAuthorized && isEditMode;
const isSelfTask = editedTaskDetails.assignee === userData?.username;
const isSelfTask = editedTaskDetails.assignee === data?.username;
const verifiedTask =
editedTaskDetails.status === VERIFIED &&
editedTaskDetails.percentCompleted === 100;
Expand Down

0 comments on commit 90f78e4

Please sign in to comment.