Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop-postgres' into issue-2…
Browse files Browse the repository at this point in the history
…072-fix
  • Loading branch information
gurramkarthiknetha committed Jan 11, 2025
1 parent 2ac3dfb commit 8c8cf39
Show file tree
Hide file tree
Showing 11 changed files with 326 additions and 175 deletions.
36 changes: 36 additions & 0 deletions src/components/LeftDrawer/LeftDrawer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,40 @@ describe('Testing Left Drawer component for ADMIN', () => {

expect(global.window.location.pathname).toContain('/orglist');
});

it('Should set hideDrawer to false when initially null', async () => {
const mockSetHideDrawer = vi.fn();
await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<LeftDrawer hideDrawer={null} setHideDrawer={mockSetHideDrawer} />
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
);
});
expect(mockSetHideDrawer).toHaveBeenCalledWith(false);
expect(mockSetHideDrawer).toHaveBeenCalledTimes(1);
});

it('Should not call setHideDrawer when hideDrawer has a value', async () => {
const mockSetHideDrawer = vi.fn();
await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<LeftDrawer
hideDrawer={false}
setHideDrawer={mockSetHideDrawer}
/>
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
);
});
expect(mockSetHideDrawer).not.toHaveBeenCalled();
});
});
43 changes: 43 additions & 0 deletions src/components/LeftDrawerOrg/LeftDrawerOrg.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,47 @@ describe('Testing LeftDrawerOrg component for SUPERADMIN', () => {
</MockedProvider>,
);
});

test('Should set hideDrawer to false when initially null', async () => {
const mockSetHideDrawer = vi.fn();
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LeftDrawerOrg
{...props}
hideDrawer={null}
setHideDrawer={mockSetHideDrawer}
/>
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
await wait();
expect(mockSetHideDrawer).toHaveBeenCalledWith(false);
expect(mockSetHideDrawer).toHaveBeenCalledTimes(1);
});

test('Should not call setHideDrawer when hideDrawer has a value', async () => {
const mockSetHideDrawer = vi.fn();
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LeftDrawerOrg
{...props}
hideDrawer={false}
setHideDrawer={mockSetHideDrawer}
/>
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
await wait();
expect(mockSetHideDrawer).not.toHaveBeenCalled();
});
});
7 changes: 7 additions & 0 deletions src/components/LeftDrawerOrg/LeftDrawerOrg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ const leftDrawerOrg = ({
() => getIdFromPath(location.pathname),
[location.pathname],
);

useEffect(() => {
if (hideDrawer === null) {
setHideDrawer(false);
}
}, []);

// Check if the current page is admin profile page

useEffect(() => {
Expand Down
137 changes: 96 additions & 41 deletions src/components/Pagination/Pagination.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,115 @@ import { createTheme, ThemeProvider } from '@mui/material/styles';
import Pagination from './Pagination';
import { store } from 'state/store';
import userEvent from '@testing-library/user-event';
import { describe, it } from 'vitest';

describe('Testing Pagination component', () => {
const props = {
count: 5,
page: 10,
rowsPerPage: 5,
onPageChange: (): number => {
return 10;
},
import { describe, it, vi, expect } from 'vitest';

describe('Pagination component tests', () => {
const mockOnPageChange = vi.fn();

const defaultProps = {
count: 20, // Total items
page: 2, // Current page
rowsPerPage: 5, // Items per page
onPageChange: mockOnPageChange, // Mocked callback for page change
};

it('Component should be rendered properly on rtl', async () => {
it('should render all pagination buttons and invoke onPageChange for navigation', async () => {
render(
<BrowserRouter>
<Provider store={store}>
<Pagination {...props} />
<Pagination {...defaultProps} />
</Provider>
</BrowserRouter>,
);

// Ensure all buttons are rendered
expect(screen.getByTestId('firstPage')).toBeInTheDocument();
expect(screen.getByTestId('previousPage')).toBeInTheDocument();
expect(screen.getByTestId('nextPage')).toBeInTheDocument();
expect(screen.getByTestId('lastPage')).toBeInTheDocument();

// Simulate button clicks and verify callback invocation
await act(async () => {
userEvent.click(screen.getByTestId('nextPage'));
});
expect(mockOnPageChange).toHaveBeenCalledWith(expect.anything(), 3); // Next page

await act(async () => {
userEvent.click(screen.getByTestId('previousPage'));
});
expect(mockOnPageChange).toHaveBeenCalledWith(expect.anything(), 1); // Previous page

await act(async () => {
userEvent.click(screen.getByTestId('firstPage'));
});
expect(mockOnPageChange).toHaveBeenCalledWith(expect.anything(), 0); // First page

await act(async () => {
await userEvent.click(screen.getByTestId(/nextPage/i));
await userEvent.click(screen.getByTestId(/previousPage/i));
userEvent.click(screen.getByTestId('lastPage'));
});
expect(mockOnPageChange).toHaveBeenCalledWith(expect.anything(), 3); // Last page
});
});

const props = {
count: 5,
page: 10,
rowsPerPage: 5,
onPageChange: (): number => {
return 10;
},
theme: { direction: 'rtl' },
};

it('Component should be rendered properly', async () => {
const theme = createTheme({
direction: 'rtl',
it('should disable navigation buttons at the boundaries', () => {
render(
<BrowserRouter>
<Provider store={store}>
<Pagination {...defaultProps} page={0} />
</Provider>
</BrowserRouter>,
);

// First and Previous buttons should be disabled on the first page
expect(screen.getByTestId('firstPage')).toBeDisabled();
expect(screen.getByTestId('previousPage')).toBeDisabled();

// Next and Last buttons should not be disabled
expect(screen.getByTestId('nextPage')).not.toBeDisabled();
expect(screen.getByTestId('lastPage')).not.toBeDisabled();
});

render(
<BrowserRouter>
<Provider store={store}>
<ThemeProvider theme={theme}>
<Pagination {...props} />
</ThemeProvider>
</Provider>
</BrowserRouter>,
);

await act(async () => {
await userEvent.click(screen.getByTestId(/nextPage/i));
await userEvent.click(screen.getByTestId(/previousPage/i));
it('should render correctly with RTL direction', async () => {
const rtlTheme = createTheme({ direction: 'rtl' });

render(
<BrowserRouter>
<Provider store={store}>
<ThemeProvider theme={rtlTheme}>
<Pagination {...defaultProps} />
</ThemeProvider>
</Provider>
</BrowserRouter>,
);

// Verify buttons render properly in RTL mode
expect(screen.getByTestId('firstPage')).toBeInTheDocument();
expect(screen.getByTestId('lastPage')).toBeInTheDocument();

// Simulate a button click in RTL mode
await act(async () => {
userEvent.click(screen.getByTestId('nextPage'));
});
expect(mockOnPageChange).toHaveBeenCalledWith(expect.anything(), 3); // Next page
});

it('should disable Next and Last buttons on the last page', () => {
render(
<BrowserRouter>
<Provider store={store}>
<Pagination
{...defaultProps}
page={Math.ceil(defaultProps.count / defaultProps.rowsPerPage) - 1}
/>
</Provider>
</BrowserRouter>,
);

// Next and Last buttons should be disabled on the last page
expect(screen.getByTestId('nextPage')).toBeDisabled();
expect(screen.getByTestId('lastPage')).toBeDisabled();

// First and Previous buttons should not be disabled
expect(screen.getByTestId('firstPage')).not.toBeDisabled();
expect(screen.getByTestId('previousPage')).not.toBeDisabled();
});
});
3 changes: 0 additions & 3 deletions src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function pagination(props: InterfaceTablePaginationActionsProps): JSX.Element {
*
* @param event - The click event.
*/
/* istanbul ignore next */
const handleFirstPageButtonClick = (
event: React.MouseEvent<HTMLButtonElement>,
): void => {
Expand All @@ -63,7 +62,6 @@ function pagination(props: InterfaceTablePaginationActionsProps): JSX.Element {
* @param event - The click event.
*/

/* istanbul ignore next */
const handleNextButtonClick = (
event: React.MouseEvent<HTMLButtonElement>,
): void => {
Expand All @@ -76,7 +74,6 @@ function pagination(props: InterfaceTablePaginationActionsProps): JSX.Element {
*
* @param event - The click event.
*/
/* istanbul ignore next */
const handleLastPageButtonClick = (
event: React.MouseEvent<HTMLButtonElement>,
): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ describe('Testing StartPostModal Component: User Portal', () => {
);
});

it('should display correct username', async () => {
renderStartPostModal(true, null);
await wait();

const userFullName = screen.getByText('Glen dsza');
expect(userFullName).toBeInTheDocument();
});

it('If user image is null then default image should be shown', async () => {
renderStartPostModal(true, null);
await wait();
Expand Down
Loading

0 comments on commit 8c8cf39

Please sign in to comment.