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

Dev to Main Sync #1285

Merged
merged 1 commit into from
Nov 21, 2024
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
50 changes: 11 additions & 39 deletions __tests__/Unit/pages/Mine/Mine.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,12 @@ describe('Mine Page', () => {
);
});

it('should render no tasks found state when dev is enabled', async () => {
const { getByText } = renderWithRouter(
<Provider store={store()}>
<Mine />
</Provider>,
{ route: '/mine', query: { dev: 'true' } }
);
await waitFor(() =>
expect(getByText(/no tasks found/i)).toBeInTheDocument()
);
});

it('should render shimmer cards', async () => {
const { getAllByTestId } = renderWithRouter(
<Provider store={store()}>
<Mine />
</Provider>,
{ route: '/mine', query: { dev: 'true' } }
{ route: '/mine' }
);

await waitFor(() =>
Expand All @@ -106,52 +94,36 @@ describe('Mine Page', () => {
);
});

it('should render old UI component for mine tasks when dev is disabled', async () => {
it('should render filter dropdown', async () => {
const { getByText } = renderWithRouter(
<Provider store={store()}>
<Mine />
</Provider>,
{ route: '/mine', query: { dev: 'false' } }
);
await waitFor(() =>
expect(
getByText(
/Collapse non-interesting tasks or PRs in member details page/i
)
).toBeInTheDocument()
);
});

it('should render filter dropdown when dev is enabled', async () => {
const { getByText } = renderWithRouter(
<Provider store={store()}>
<Mine />
</Provider>,
{ route: '/mine', query: { dev: 'true' } }
{ route: '/mine' }
);

await waitFor(() => expect(getByText(/Filter/i)).toBeInTheDocument());
});

it('should render search input when dev is enabled', async () => {
it('should render search input', async () => {
const { getByTestId } = renderWithRouter(
<Provider store={store()}>
<Mine />
</Provider>,
{ route: '/mine', query: { dev: 'true' } }
{ route: '/mine' }
);

await waitFor(() =>
expect(getByTestId(/pill-input-wrapper/i)).toBeInTheDocument()
);
});

it('should render new UI component for mine tasks when dev is enabled', async () => {
it('should render task cards', async () => {
const { getAllByTestId } = renderWithRouter(
<Provider store={store()}>
<Mine />
</Provider>,
{ route: '/mine', query: { dev: 'true' } }
{ route: '/mine' }
);

await waitFor(() =>
Expand All @@ -161,12 +133,12 @@ describe('Mine Page', () => {
);
});

it('should filter tasks based on search input when dev is enabled', async () => {
it('should filter tasks based on search input', async () => {
const { findByText, getAllByText, findByTestId } = renderWithRouter(
<Provider store={store()}>
<Mine />
</Provider>,
{ route: '/mine', query: { dev: 'true' } }
{ route: '/mine' }
);

const searchInput = await findByTestId('search-input');
Expand All @@ -179,12 +151,12 @@ describe('Mine Page', () => {
});
});

it('should filter tasks based on filter dropdown select when dev is enabled', async () => {
it('should filter tasks based on filter dropdown select', async () => {
const { findByText, getAllByText } = renderWithRouter(
<Provider store={store()}>
<Mine />
</Provider>,
{ route: '/mine', query: { dev: 'true' } }
{ route: '/mine' }
);

const dropdown = await findByText('Filter');
Expand Down
41 changes: 2 additions & 39 deletions src/pages/mine/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { getActiveTab } from '@/utils/getActiveTab';
import TaskList from '@/components/tasks/TaskList/TaskList';
import getInputValueFromTaskField from '@/utils/getInputValueFromTaskField';
import getFilteredTasks from '@/utils/getFilteredTasks';
import Card from '@/components/tasks/card';
import { useRouter } from 'next/router';
import CardShimmer from '@/components/Loaders/cardShimmer';

export const searchTasks = (
Expand All @@ -34,7 +32,7 @@ export const searchTasks = (
}
};

const ContentDev = () => {
const Content = () => {
const [filteredTasks, setFilteredTasks] = useState<task[] | undefined>();
const [selectedTab, setSelectedTab] = useState<Tab>(Tab.ALL);
const [title, setTitle] = useState<string>('');
Expand Down Expand Up @@ -91,39 +89,8 @@ const ContentDev = () => {
);
};

function CardList({ tasks }: { tasks: task[] }) {
return (
<>
{tasks.map((item) => (
<Card
content={item}
key={item.id}
shouldEdit={false}
onContentChange={undefined}
/>
))}
</>
);
}

const Content = () => {
const { data: tasks, error, isLoading } = useGetMineTasksQuery();

if (isLoading) return <p>Loading...</p>;
if (error) return <p>Something went wrong! Please contact admin</p>;
if (tasks?.length)
return (
<div className={styles.mineTasksContainer}>
<CardList tasks={tasks} />
</div>
);
return <p>{NO_TASKS_FOUND_MESSAGE}</p>;
};

const Mine: FC = () => {
const { isLoading: isAuthenticating, isLoggedIn } = useAuthenticated();
const router = useRouter();
const dev = router.query.dev === 'true' ? true : false;

return (
<Layout>
Expand All @@ -132,11 +99,7 @@ const Mine: FC = () => {
{isAuthenticating ? (
<Loader />
) : isLoggedIn ? (
dev ? (
<ContentDev />
) : (
<Content />
)
<Content />
) : (
<div>
<p>You are not Authorized</p>
Expand Down
Loading