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

Moving back Done status under dev flag #1254

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
57 changes: 50 additions & 7 deletions __mocks__/handlers/task-details.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,48 @@ import { rest } from 'msw';
const URL = process.env.NEXT_PUBLIC_BASE_URL;

const taskDetailsHandler = [
rest.get(`${URL}/tasks/12345/details`, (_, res, ctx) => {
try {
return res(
ctx.status(200),
ctx.json({
message: 'task returned successfully',
taskData: {
id: '12345',
isNoteworthy: true,
lossRate: {
dinero: 0,
neelam: 0,
},
purpose: 'This is a sample description',
endsOn: 1618790410,
title: 'test 1 for drag and drop',
status: 'COMPLETED',
assignee: 'ankur',
links: [],
dependsOn: [],
percentCompleted: 0,
type: 'feature',
priority: 'high',
featureUrl: 'https://www.sampleUrl.com',
startedOn: 1617062400,
completionAward: {
neelam: 0,
dinero: 110,
},
github: {
issue: {
html_url:
'https://github.com/sample-org/sample-repo/issues/000',
},
},
},
})
skv93-coder marked this conversation as resolved.
Show resolved Hide resolved
);
} catch (error) {
return res(ctx.status(500), ctx.json({ error }));
}
}),
rest.get(`${URL}/tasks/6KhcLU3yr45dzjQIVm0J/details`, (_, res, ctx) => {
return res(
ctx.status(200),
Expand All @@ -19,8 +61,8 @@ const taskDetailsHandler = [
title: 'test 1 for drag and drop',
status: 'assigned',
assignee: 'ankur',
links: ['null'],
dependsOn: ['null'],
links: [],
dependsOn: [],
percentCompleted: 0,
type: 'feature',
priority: 'high',
Expand All @@ -32,9 +74,10 @@ const taskDetailsHandler = [
},
github: {
issue: {
html_url:'https://github.com/sample-org/sample-repo/issues/000'
}
}
html_url:
'https://github.com/sample-org/sample-repo/issues/000',
},
},
},
})
);
Expand All @@ -55,8 +98,8 @@ const taskDetailsHandler = [
title: 'test 1 for drag and drop',
status: 'assigned',
assignee: 'ankur',
links: ['null'],
dependsOn: ['null'],
links: [],
dependsOn: [],
percentCompleted: 0,
type: 'feature',
priority: 'high',
Expand Down
27 changes: 13 additions & 14 deletions __tests__/Unit/Components/Tabs/Tab.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import Tabs from '@/components/Tabs';
import { fireEvent, render, screen } from '@testing-library/react';
import { fireEvent, screen } from '@testing-library/react';
import {
Tab,
TABS,
depreciatedTaskStatus,
newTaskStatus,
} from '@/interfaces/task.type';
import { COMPLETED, DONE, AVAILABLE, UNASSIGNED } from '@/constants/constants';
import { AVAILABLE, UNASSIGNED } from '@/constants/constants';
import { renderWithRouter } from '@/test_utils/createMockRouter';

function changeName(name: string) {
if (name === COMPLETED) {
return DONE;
} else if (name === AVAILABLE) {
if (name === AVAILABLE) {
return UNASSIGNED;
} else {
return name.split('_').join(' ');
Expand All @@ -22,7 +21,7 @@ describe('Tabs Component', () => {
const onSelectMock = jest.fn();

it('should render all the buttons', () => {
render(
renderWithRouter(
<Tabs
tabs={TABS}
activeTab={Tab.ASSIGNED}
Expand All @@ -38,7 +37,7 @@ describe('Tabs Component', () => {
});

it('should render all the buttons when dev is true', () => {
render(
renderWithRouter(
<Tabs
dev={true}
tabs={TABS}
Expand All @@ -53,7 +52,7 @@ describe('Tabs Component', () => {
});

it('check if selectTab() is called with right key', () => {
render(
renderWithRouter(
<Tabs
tabs={TABS}
activeTab={Tab.ASSIGNED}
Expand All @@ -66,7 +65,7 @@ describe('Tabs Component', () => {
});

it('check if selectTab() is called with right key when dev is true', () => {
render(
renderWithRouter(
<Tabs
dev={true}
tabs={TABS}
Expand All @@ -82,19 +81,19 @@ describe('Tabs Component', () => {
});

it('Check if correct button is selected', () => {
render(
renderWithRouter(
<Tabs
tabs={TABS}
activeTab={Tab.COMPLETED}
onSelect={onSelectMock}
/>
);
const completedBtn = screen.getByRole('button', { name: /DONE/i });
const completedBtn = screen.getByRole('button', { name: /COMPLETED/i });
expect(completedBtn).toHaveClass('active');
});

it('Check if correct button is selected when dev is true', () => {
render(
renderWithRouter(
<Tabs
dev={true}
tabs={TABS}
Expand All @@ -109,7 +108,7 @@ describe('Tabs Component', () => {
});

it('should render all tabs passed with correct text', () => {
render(
renderWithRouter(
<Tabs
tabs={TABS}
activeTab={Tab.ASSIGNED}
Expand All @@ -126,7 +125,7 @@ describe('Tabs Component', () => {
});

it('should render all tabs passed with correct text when dev is true', () => {
render(
renderWithRouter(
<Tabs
dev={true}
tabs={TABS}
Expand Down
82 changes: 59 additions & 23 deletions __tests__/Unit/Components/Tasks/FilterDropdown.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import { fireEvent, screen } from '@testing-library/react';
import { Tab } from '@/interfaces/task.type';
import FilterDropdown from '@/components/tasks/TaskSearch/FilterDropdown';
import { renderWithRouter } from '@/test_utils/createMockRouter';

const mockOnSelect = jest.fn();
const mockOnClose = jest.fn();

describe('FilterDropdown', () => {
test('renders the modal with correct title and buttons', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.ASSIGNED, Tab.IN_PROGRESS]}
onSelect={mockOnSelect}
Expand All @@ -31,7 +32,7 @@ describe('FilterDropdown', () => {
});

test('renders the modal having overdue tab with correct title and buttons', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.ASSIGNED, Tab.IN_PROGRESS, Tab.OVERDUE]}
onSelect={mockOnSelect}
Expand All @@ -57,9 +58,9 @@ describe('FilterDropdown', () => {
});

test('renders the modal with correct title and buttons', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.UNASSIGNED, Tab.DONE]}
tabs={[Tab.UNASSIGNED, Tab.COMPLETED]}
onSelect={mockOnSelect}
activeTab={Tab.UNASSIGNED}
onClose={mockOnClose}
Expand All @@ -75,12 +76,12 @@ describe('FilterDropdown', () => {
const unassignedButton = screen.getByText(/unassigned/i);
expect(unassignedButton).toBeInTheDocument();

const doneButton = screen.getByText(/done/i);
expect(doneButton).toBeInTheDocument();
const completedButton = screen.getByText(/completed/i);
expect(completedButton).toBeInTheDocument();
});

test('calls onSelect and onClose when a status button is clicked', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.ASSIGNED, Tab.IN_PROGRESS]}
onSelect={mockOnSelect}
Expand All @@ -96,7 +97,7 @@ describe('FilterDropdown', () => {
});

test('calls onClose when the close button is clicked', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.ASSIGNED, Tab.IN_PROGRESS]}
onSelect={mockOnSelect}
Expand All @@ -111,7 +112,7 @@ describe('FilterDropdown', () => {
expect(mockOnClose).toBeCalled();
});
test('calls onClose when clicked on outside', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.ASSIGNED, Tab.IN_PROGRESS]}
onSelect={mockOnSelect}
Expand All @@ -135,7 +136,7 @@ describe('FilterDropdown', () => {
expect(mockOnClose).toBeCalled();
});
test('calls onClose when escape button is clicked', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.ASSIGNED, Tab.IN_PROGRESS]}
onSelect={mockOnSelect}
Expand All @@ -150,7 +151,7 @@ describe('FilterDropdown', () => {
});

test('renders the modal with correct active tab', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.ASSIGNED, Tab.IN_PROGRESS]}
onSelect={mockOnSelect}
Expand All @@ -167,24 +168,24 @@ describe('FilterDropdown', () => {
});

test('renders the modal with correct active tab', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.UNASSIGNED, Tab.DONE]}
tabs={[Tab.UNASSIGNED, Tab.COMPLETED]}
onSelect={mockOnSelect}
activeTab={Tab.DONE}
activeTab={Tab.COMPLETED}
onClose={mockOnClose}
/>
);

const doneButton = screen.getByText(/done/i);
expect(doneButton).toHaveClass('status-button-active');
const completedButton = screen.getByText(/completed/i);
expect(completedButton).toHaveClass('status-button-active');

const unassignedButton = screen.getByText(/unassigned/i);
expect(unassignedButton).not.toHaveClass('status-button-active');
});

test('render the filter model having BACKLOG tab with correct title and buttons', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.UNASSIGNED, Tab.BACKLOG]}
onSelect={mockOnSelect}
Expand All @@ -198,7 +199,7 @@ describe('FilterDropdown', () => {
});

test('onSelect Function Gets Called When the Backlog Status button is Clicked', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.BACKLOG, Tab.IN_PROGRESS]}
onSelect={mockOnSelect}
Expand All @@ -214,9 +215,9 @@ describe('FilterDropdown', () => {
});

test('Selection of the Backlog Button', () => {
render(
renderWithRouter(
<FilterDropdown
tabs={[Tab.BACKLOG, Tab.DONE]}
tabs={[Tab.BACKLOG, Tab.COMPLETED]}
onSelect={mockOnSelect}
activeTab={Tab.BACKLOG}
onClose={mockOnClose}
Expand All @@ -226,7 +227,42 @@ describe('FilterDropdown', () => {
const backlogButton = screen.getByText(/backlog/i);
expect(backlogButton).toHaveClass('status-button-active');

const doneButton = screen.getByText(/done/i);
expect(doneButton).not.toHaveClass('status-button-active');
const completedButton = screen.getByText(/completed/i);
expect(completedButton).not.toHaveClass('status-button-active');
});

it('Renders Task tab Done, when dev flag is on', async () => {
renderWithRouter(
<FilterDropdown
tabs={[Tab.BACKLOG, Tab.COMPLETED, Tab.DONE]}
onSelect={mockOnSelect}
activeTab={Tab.DONE}
onClose={mockOnClose}
/>,
{
query: { dev: 'true' },
}
);

const doneButton = screen.queryByText(/done/i);
const completedButton = screen.queryByText(/completed/i);

expect(doneButton).toBeInTheDocument();
expect(completedButton).toBeNull();
});
it('Renders Task status Completed, when dev flag is not on', async () => {
renderWithRouter(
<FilterDropdown
tabs={[Tab.BACKLOG, Tab.COMPLETED, Tab.DONE]}
onSelect={mockOnSelect}
activeTab={Tab.COMPLETED}
onClose={mockOnClose}
/>
);
const doneButton = screen.queryByText(/done/i);
const completedButton = screen.queryByText(/completed/i);

expect(completedButton).toBeInTheDocument();
expect(doneButton).toBeNull();
});
});
Loading
Loading