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 #1299

Merged
merged 2 commits into from
Dec 19, 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
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
2 changes: 1 addition & 1 deletion __tests__/Unit/Components/Tasks/ProgressIndicator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Progress Indicator', () => {

test('should render the ProgressIndicator', () => {
const { container } = render(<ProgressIndicator {...DEFAULT_PROPS} />);
const parentDiv = container.getElementsByClassName('progressIndicator');
const parentDiv = container.getElementsByClassName('slider');
const childDiv = container.getElementsByClassName('progressStyle');
expect(parentDiv.length).toBe(1);
expect(childDiv.length).toBe(1);
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
59 changes: 17 additions & 42 deletions src/components/ProgressForm/InputWithQuestions.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,30 @@
import { inputPropsTypes } from '@/types/ProgressUpdates';
import styles from '@/components/ProgressForm/ProgressForm.module.scss';
import { useRouter } from 'next/router';

const InputWithQuestions = ({
name,
question,
value,
onChange,
}: inputPropsTypes) => {
const { query } = useRouter();
const isDev = query.dev === 'true';
return (
<>
{isDev ? (
<div className={styles.inputComponentUpdated}>
<label
className={styles.labelUpdated}
htmlFor={name}
aria-label={name}
>
{question}
</label>
<textarea
className={styles.inputUpdated}
value={value}
onChange={(e) =>
onChange({ type: name, value: e.target.value })
}
id={name}
/>
</div>
) : (
<div className={styles.inputComponent}>
<label
className={styles.label}
htmlFor={name}
aria-label={name}
>
{question}
</label>
<textarea
className={styles.input}
value={value}
onChange={(e) =>
onChange({ type: name, value: e.target.value })
}
id={name}
/>
</div>
)}
</>
<div className={styles.inputComponentUpdated}>
<label
className={styles.labelUpdated}
htmlFor={name}
aria-label={name}
>
{question}
</label>
<textarea
className={styles.inputUpdated}
value={value}
onChange={(e) =>
onChange({ type: name, value: e.target.value })
}
id={name}
/>
</div>
);
};

Expand Down
32 changes: 10 additions & 22 deletions src/components/ProgressForm/ProgressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const ProgressForm = ({ questions, onUpdateSuccess }: ExtendedFormProps) => {
const manager = [state.progress, state.plan, state.blockers];
const [saveProgress] = useSaveProgressMutation();
const router = useRouter();
const isDev = router.query.dev === 'true';
const isButtonEnabled =
state.progress && state.plan && state.blockers && !isLoading;

Expand Down Expand Up @@ -86,27 +85,16 @@ const ProgressForm = ({ questions, onUpdateSuccess }: ExtendedFormProps) => {
onChange={dispatch}
/>
))}
{isDev ? (
<button
className={styles.buttonUpdated}
onClick={handleSubmit}
disabled={!isButtonEnabled}
type="submit"
data-testid="submit-dev"
>
{isLoading ? <Spinner /> : 'Submit'}
</button>
) : (
<button
className={styles.button}
onClick={handleSubmit}
disabled={!isButtonEnabled}
type="submit"
data-testid="submit"
>
{isLoading ? <Spinner /> : 'Submit'}
</button>
)}

<button
className={styles.buttonUpdated}
onClick={handleSubmit}
disabled={!isButtonEnabled}
type="submit"
data-testid="submit-dev"
>
{isLoading ? <Spinner /> : 'Submit'}
</button>
</form>
);
};
Expand Down
2 changes: 0 additions & 2 deletions src/components/taskDetails/TaskUpdateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Props = {
styles: {
readonly [key: string]: string;
};
isDev: boolean;
taskDetailsData: task;
editedTaskDetails: task;
onUpdateSuccess: () => void;
Expand All @@ -23,7 +22,6 @@ function TaskUpdateModal({
isOpen,
setIsOpen,
styles,
isDev,
taskDetailsData,
editedTaskDetails,
onUpdateSuccess,
Expand Down
32 changes: 7 additions & 25 deletions src/components/taskDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ type Props = {

const TaskDetails: FC<Props> = ({ taskID }) => {
const router = useRouter();
const { query } = router;
const isDev = query.dev === 'true';

const { isUserAuthorized } = useUserData();
const [isEditing, setIsEditing] = useState<boolean>(false);
Expand Down Expand Up @@ -324,35 +322,19 @@ const TaskDetails: FC<Props> = ({ taskID }) => {
>
<TaskUpdateModal
isOpen={isOpen}
isDev={isDev}
styles={styles}
taskDetailsData={taskDetailsData}
editedTaskDetails={editedTaskDetails}
setIsOpen={setIsOpen}
onUpdateSuccess={handleProgressUpdate}
/>

{isDev ? (
<button
data-testid="update-progress-button-dev"
className={styles.button}
onClick={() => setIsOpen(true)}
>
Update Progress
</button>
) : (
<button
data-testid="update-progress-button"
className={styles.button}
onClick={() =>
router.push(
`/progress/${taskID}?dev=true`
)
}
>
Update Progress
</button>
)}
<button
data-testid="update-progress-button-dev"
className={styles.button}
onClick={() => setIsOpen(true)}
>
Update Progress
</button>
</TaskContainer>
</section>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ import { FC } from 'react';
import styles from '@/components/tasks/card/card.module.scss';
import { ProgressIndicatorProps } from '@/interfaces/task.type';
import handleProgressColor from '@/utils/handleProgressColor';
import { useRouter } from 'next/router';

const ProgressIndicator: FC<ProgressIndicatorProps> = ({
percentCompleted,
startedOn,
endsOn,
}) => {
const { query } = useRouter();
const isDev = query.dev === 'true';
const progressColor = handleProgressColor(
percentCompleted,
startedOn,
endsOn
);
return (
<div className={isDev ? styles.slider : styles.progressIndicator}>
<div className={styles.slider}>
<div
className={`
${progressColor}
Expand Down
Loading
Loading