Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
135 lines
4.7 KiB
TypeScript
135 lines
4.7 KiB
TypeScript
import { mockAppRoot } from '@rocket.chat/mock-providers';
|
|
import { useCurrentRoutePath, useRouter } from '@rocket.chat/ui-contexts';
|
|
import { render } from '@testing-library/react';
|
|
import type { ReactNode } from 'react';
|
|
|
|
import LayoutWithSidebar from './LayoutWithSidebar';
|
|
|
|
jest.mock('@rocket.chat/ui-contexts', () => ({
|
|
...jest.requireActual('@rocket.chat/ui-contexts'),
|
|
useCurrentRoutePath: jest.fn(),
|
|
useRouter: jest.fn(),
|
|
}));
|
|
|
|
jest.mock('../../../navbar', () => () => <div>NavBar</div>);
|
|
jest.mock('../../../sidebar', () => () => <div>Sidebar</div>);
|
|
jest.mock('../../navigation', () => () => <div>NavigationRegion</div>);
|
|
jest.mock('./AccessibilityShortcut', () => () => <div>AccessibilityShortcut</div>);
|
|
jest.mock('../../navigation/providers/RoomsNavigationProvider', () => ({
|
|
__esModule: true,
|
|
default: ({ children }: { children: ReactNode }) => <>{children}</>,
|
|
}));
|
|
|
|
jest.mock('@rocket.chat/ui-client', () => ({
|
|
...jest.requireActual('@rocket.chat/ui-client'),
|
|
FeaturePreview: ({ children }: { children: ReactNode }) => <>{children}</>,
|
|
FeaturePreviewOn: ({ children }: { children: ReactNode }) => <>{children}</>,
|
|
FeaturePreviewOff: ({ children }: { children: ReactNode }) => <>{children}</>,
|
|
}));
|
|
|
|
const mockedUseCurrentRoutePath = useCurrentRoutePath as jest.MockedFunction<typeof useCurrentRoutePath>;
|
|
const mockedUseRouter = useRouter as jest.MockedFunction<typeof useRouter>;
|
|
|
|
describe('LayoutWithSidebar - First_Channel_After_Login navigation', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
const setupRouterMock = () => {
|
|
const navigate = jest.fn();
|
|
mockedUseRouter.mockReturnValue({ navigate } as any);
|
|
return navigate;
|
|
};
|
|
|
|
it('redirects to First_Channel_After_Login on "/"', () => {
|
|
const navigate = setupRouterMock();
|
|
mockedUseCurrentRoutePath.mockReturnValue('/');
|
|
|
|
render(<LayoutWithSidebar>content</LayoutWithSidebar>, {
|
|
wrapper: mockAppRoot().withSetting('First_Channel_After_Login', 'general').build(),
|
|
});
|
|
|
|
expect(navigate).toHaveBeenCalledWith({ name: '/channel/general' });
|
|
});
|
|
|
|
it('strips leading "#" from First_Channel_After_Login before redirecting', () => {
|
|
const navigate = setupRouterMock();
|
|
mockedUseCurrentRoutePath.mockReturnValue('/');
|
|
|
|
render(<LayoutWithSidebar>content</LayoutWithSidebar>, {
|
|
wrapper: mockAppRoot().withSetting('First_Channel_After_Login', '#general').build(),
|
|
});
|
|
|
|
expect(navigate).toHaveBeenCalledWith({ name: '/channel/general' });
|
|
});
|
|
|
|
it('does NOT redirect if First_Channel_After_Login starts with "?"', () => {
|
|
const navigate = setupRouterMock();
|
|
mockedUseCurrentRoutePath.mockReturnValue('/');
|
|
|
|
render(<LayoutWithSidebar>content</LayoutWithSidebar>, {
|
|
wrapper: mockAppRoot().withSetting('First_Channel_After_Login', '?general').build(),
|
|
});
|
|
|
|
expect(navigate).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('does NOT redirect if First_Channel_After_Login starts with "##"', () => {
|
|
const navigate = setupRouterMock();
|
|
mockedUseCurrentRoutePath.mockReturnValue('/');
|
|
|
|
render(<LayoutWithSidebar>content</LayoutWithSidebar>, {
|
|
wrapper: mockAppRoot().withSetting('First_Channel_After_Login', '##general').build(),
|
|
});
|
|
|
|
expect(navigate).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('redirects when route is "/home"', () => {
|
|
const navigate = setupRouterMock();
|
|
mockedUseCurrentRoutePath.mockReturnValue('/home');
|
|
|
|
render(<LayoutWithSidebar>content</LayoutWithSidebar>, {
|
|
wrapper: mockAppRoot().withSetting('First_Channel_After_Login', 'general').build(),
|
|
});
|
|
|
|
expect(navigate).toHaveBeenCalled();
|
|
});
|
|
|
|
it('does NOT redirect if First_Channel_After_Login is empty', () => {
|
|
const navigate = setupRouterMock();
|
|
mockedUseCurrentRoutePath.mockReturnValue('/');
|
|
|
|
render(<LayoutWithSidebar>content</LayoutWithSidebar>, {
|
|
wrapper: mockAppRoot().withSetting('First_Channel_After_Login', '').build(),
|
|
});
|
|
|
|
expect(navigate).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('does NOT redirect on non-home routes (e.g. /admin)', () => {
|
|
const navigate = setupRouterMock();
|
|
mockedUseCurrentRoutePath.mockReturnValue('/admin' as any);
|
|
|
|
render(<LayoutWithSidebar>content</LayoutWithSidebar>, {
|
|
wrapper: mockAppRoot().withSetting('First_Channel_After_Login', 'general').build(),
|
|
});
|
|
|
|
expect(navigate).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('redirects only once even if component re-renders', () => {
|
|
const navigate = setupRouterMock();
|
|
mockedUseCurrentRoutePath.mockReturnValue('/');
|
|
|
|
const { rerender } = render(<LayoutWithSidebar>content</LayoutWithSidebar>, {
|
|
wrapper: mockAppRoot().withSetting('First_Channel_After_Login', 'general').build(),
|
|
});
|
|
|
|
rerender(<LayoutWithSidebar>content again</LayoutWithSidebar>);
|
|
|
|
expect(navigate).toHaveBeenCalledTimes(1);
|
|
expect(navigate).toHaveBeenCalledWith({ name: '/channel/general' });
|
|
});
|
|
});
|