Skip to content

Commit

Permalink
Merge branch 'develop' into feature/show-progress-updater-info
Browse files Browse the repository at this point in the history
  • Loading branch information
AnujChhikara authored Dec 18, 2024
2 parents 9a97533 + 8ce8a31 commit 17ccf17
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 30 deletions.
8 changes: 6 additions & 2 deletions __tests__/Unit/Components/Calendar/UserSearchField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,17 @@ describe('SearchField component', () => {
userEvent.type(input, 'mu');
await waitFor(() => expect(input).toHaveValue('mu'));

const suggestionsAfterFirstTyping = screen.queryAllByRole('listitem');
const suggestionsAfterFirstTyping = await waitFor(() =>
screen.queryAllByRole('listitem')
);
expect(suggestionsAfterFirstTyping.length).toBeGreaterThan(0);

userEvent.type(input, 'hammad');
await waitFor(() => expect(input).toHaveValue('muhammad'));

const suggestionsAfterSecondTyping = screen.queryAllByRole('listitem');
const suggestionsAfterSecondTyping = await waitFor(() =>
screen.queryAllByRole('listitem')
);
expect(suggestionsAfterSecondTyping.length).toBeGreaterThan(0);
expect(suggestionsAfterSecondTyping.length).toBeLessThan(
suggestionsAfterFirstTyping.length
Expand Down
31 changes: 18 additions & 13 deletions __tests__/Unit/Components/Tasks/TaskDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,24 +405,25 @@ test('should update the title and description with the new values', async () =>
<Provider store={store()}>
<TaskDetails taskID={details.taskID} />
<ToastContainer />
</Provider>,
{}
</Provider>
);
await waitFor(() => {
const editButton = screen.getByRole('button', { name: 'Edit' });
fireEvent.click(editButton);
});
const textareaElement = screen.getByTestId('title-textarea');

const editButton = await screen.findByRole('button', { name: 'Edit' });
fireEvent.click(editButton);

const textareaElement = await screen.findByTestId('title-textarea');
fireEvent.change(textareaElement, {
target: { name: 'title', value: 'New Title' },
});

const saveButton = await screen.findByRole('button', {
name: 'Save',
});
const saveButton = await screen.findByRole('button', { name: 'Save' });
fireEvent.click(saveButton);
expect(screen.findByText(/Successfully saved/i)).not.toBeNull();

await waitFor(() => {
expect(screen.getByText(/Successfully saved/i)).toBeInTheDocument();
});
});

test('should not update the title and description with the same values', async () => {
server.use(...taskDetailsHandler);
renderWithRouter(
Expand All @@ -447,7 +448,9 @@ test('should not update the title and description with the same values', async (
name: 'Save',
});
fireEvent.click(saveButton);
expect(screen.queryByText(/Successfully saved/i)).toBeNull();
await waitFor(() => {
expect(screen.queryByText(/Successfully saved/i)).toBeNull();
});
});

test('Should render No task progress', async () => {
Expand Down Expand Up @@ -577,7 +580,9 @@ describe('Task details Edit mode ', () => {
});
fireEvent.click(saveButton);
});
expect(screen.queryByText(/Successfully saved/i)).toBeNull();
await waitFor(() => {
expect(screen.queryByText(/Successfully saved/i)).toBeNull();
});
});
test('Should render task progress', async () => {
server.use(superUserSelfHandler);
Expand Down
19 changes: 12 additions & 7 deletions __tests__/Unit/pages/Mine/Mine.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { waitFor } from '@testing-library/react';
import { waitFor, within } from '@testing-library/react';
import Mine, { searchTasks } from '@/pages/mine';
import { store } from '@/app/store';
import { Provider } from 'react-redux';
Expand All @@ -25,13 +25,14 @@ afterAll(() => server.close());

describe('Mine Page', () => {
it('should render loading state', () => {
const { getByText } = renderWithRouter(
const { getByTestId } = renderWithRouter(
<Provider store={store()}>
<Mine />
</Provider>,
{ route: '/mine' }
);
expect(getByText(/loading/i)).toBeInTheDocument();
const container = getByTestId('mine-page-container');
expect(within(container).getByText(/loading/i)).toBeInTheDocument();
});

it('should call searchTasks', () => {
Expand Down Expand Up @@ -142,13 +143,17 @@ describe('Mine Page', () => {
);

const searchInput = await findByTestId('search-input');
userEvent.type(searchInput, 'status:verified');
expect(searchInput).toBeInTheDocument();
await userEvent.type(searchInput, 'status:verified');
await waitFor(() => expect(searchInput).toHaveValue('status:verified'));
await waitFor(() => findByText('status: verified'));

const tag = await findByText('status: verified');
expect(tag).toBeInTheDocument();

userEvent.click(tag);

await waitFor(() => {
expect(getAllByText('Verified').length).toEqual(2);
});
await waitFor(() => expect(getAllByText('Verified').length).toEqual(2));
});

it('should filter tasks based on filter dropdown select', async () => {
Expand Down
8 changes: 1 addition & 7 deletions src/hooks/useAuthenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ const useAuthenticated = (): userDetails => {
profilePicture: DEFAULT_AVATAR,
});

const { data, isSuccess } = useUserData();
const { data, isSuccess, isLoading } = useUserData();

const [isLoading, setIsLoading] = useState(false);
const setUserDetails = () => {
setIsLoading(true);

if (data?.incompleteUserDetails) {
window.open(`${SIGNUP_LINK}`, '_blank', 'noopener');
}
Expand All @@ -25,10 +22,7 @@ const useAuthenticated = (): userDetails => {
firstName: data?.first_name ?? '',
profilePicture: data?.picture?.url ?? DEFAULT_AVATAR,
});

if (isSuccess) setIsLoggedIn(true);

setIsLoading(false);
};

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/mine/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const Mine: FC = () => {
return (
<Layout>
<Head title="Mine" />
<div className={styles.container}>
<div className={styles.container} data-testid="mine-page-container">
{isAuthenticating ? (
<Loader />
) : isLoggedIn ? (
Expand Down

0 comments on commit 17ccf17

Please sign in to comment.