mattermost-mobile/app/store/navigation_store.test.ts
Rahim Rahman 72b97f60f5
revert: floating banner & low connectivity (#9254)
* Revert "feat(MM-65625): low connectivity feature toggle in advance settings (#9191)"

This reverts commit c872e2e2b1.

* Revert "feat(MM-65145): Network connectivity/performance observer (#9173)"

This reverts commit 597e03d7d8.

* Revert "feat(MM-65625): floating banner (#9162)"

This reverts commit 5887c3ab46.

* Revert "feat(MM-65625): enhance navigation overlay management (#9165)"

This reverts commit f1554f0341.

* revert advanced.test.tsx changes
2025-11-04 07:15:51 -07:00

143 lines
5.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Screens} from '@constants';
import NavigationStore from './navigation_store';
describe('NavigationStore', () => {
beforeEach(() => {
NavigationStore.reset();
});
describe('screen management', () => {
it('should add and get screens correctly', () => {
NavigationStore.addScreenToStack(Screens.ABOUT);
NavigationStore.addScreenToStack(Screens.ACCOUNT);
expect(NavigationStore.getScreensInStack()).toEqual([Screens.ACCOUNT, Screens.ABOUT]);
expect(NavigationStore.getVisibleScreen()).toBe(Screens.ACCOUNT);
});
it('should remove screens correctly', () => {
NavigationStore.addScreenToStack(Screens.ABOUT);
NavigationStore.addScreenToStack(Screens.ACCOUNT);
NavigationStore.removeScreenFromStack(Screens.ACCOUNT);
expect(NavigationStore.getScreensInStack()).toEqual([Screens.ABOUT]);
expect(NavigationStore.getVisibleScreen()).toBe(Screens.ABOUT);
});
it('should clear screens correctly', () => {
NavigationStore.addScreenToStack(Screens.ABOUT);
NavigationStore.addScreenToStack(Screens.ACCOUNT);
NavigationStore.clearScreensFromStack();
expect(NavigationStore.getScreensInStack()).toEqual([]);
expect(NavigationStore.getVisibleScreen()).toBeUndefined();
});
it('should pop to screen correctly', () => {
NavigationStore.addScreenToStack(Screens.ABOUT);
NavigationStore.addScreenToStack(Screens.ACCOUNT);
NavigationStore.addScreenToStack(Screens.CHANNEL);
NavigationStore.popTo(Screens.ABOUT);
expect(NavigationStore.getScreensInStack()).toEqual([Screens.ABOUT]);
expect(NavigationStore.getVisibleScreen()).toBe(Screens.ABOUT);
});
});
describe('modal management', () => {
it('should add and get modals correctly', () => {
NavigationStore.addModalToStack(Screens.EDIT_POST);
NavigationStore.addModalToStack(Screens.EDIT_PROFILE);
expect(NavigationStore.getModalsInStack()).toEqual([Screens.EDIT_PROFILE, Screens.EDIT_POST]);
expect(NavigationStore.getVisibleModal()).toBe(Screens.EDIT_PROFILE);
expect(NavigationStore.hasModalsOpened()).toBe(true);
});
it('should remove modals correctly', () => {
NavigationStore.addModalToStack(Screens.EDIT_POST);
NavigationStore.addModalToStack(Screens.EDIT_PROFILE);
NavigationStore.removeModalFromStack(Screens.EDIT_PROFILE);
expect(NavigationStore.getModalsInStack()).toEqual([Screens.EDIT_POST]);
expect(NavigationStore.getVisibleModal()).toBe(Screens.EDIT_POST);
});
it('should handle duplicate modal additions', () => {
NavigationStore.addModalToStack(Screens.EDIT_POST);
NavigationStore.addModalToStack(Screens.EDIT_POST);
expect(NavigationStore.getModalsInStack()).toEqual([Screens.EDIT_POST]);
});
});
describe('tab management', () => {
it('should manage visible tab correctly', () => {
expect(NavigationStore.getVisibleTab()).toBe('Home');
NavigationStore.setVisibleTap('Channel');
expect(NavigationStore.getVisibleTab()).toBe('Channel');
});
});
describe('ToS management', () => {
it('should manage ToS state correctly', () => {
expect(NavigationStore.isToSOpen()).toBe(false);
NavigationStore.setToSOpen(true);
expect(NavigationStore.isToSOpen()).toBe(true);
NavigationStore.setToSOpen(false);
expect(NavigationStore.isToSOpen()).toBe(false);
});
});
describe('subject management', () => {
it('should notify subscribers of screen changes', () => {
const mockNext = jest.fn();
const subscription = NavigationStore.getSubject().subscribe({
next: mockNext,
});
NavigationStore.addScreenToStack(Screens.ABOUT);
expect(mockNext).toHaveBeenCalledWith(Screens.ABOUT);
NavigationStore.removeScreenFromStack(Screens.ABOUT);
expect(mockNext).toHaveBeenCalledWith(undefined);
subscription.unsubscribe();
});
});
describe('screen loading and visibility', () => {
it('should handle waitUntilScreenHasLoaded', async () => {
const promise = NavigationStore.waitUntilScreenHasLoaded(Screens.ABOUT);
NavigationStore.addScreenToStack(Screens.ABOUT);
await promise;
expect(NavigationStore.getScreensInStack()).toContain(Screens.ABOUT);
});
it('should handle waitUntilScreenIsTop', async () => {
const promise = NavigationStore.waitUntilScreenIsTop(Screens.ABOUT);
NavigationStore.addScreenToStack(Screens.CHANNEL);
NavigationStore.addScreenToStack(Screens.ABOUT);
await promise;
expect(NavigationStore.getVisibleScreen()).toBe(Screens.ABOUT);
});
it('should handle waitUntilScreensIsRemoved', async () => {
NavigationStore.addScreenToStack(Screens.ABOUT);
const promise = NavigationStore.waitUntilScreensIsRemoved(Screens.ABOUT);
NavigationStore.removeScreenFromStack(Screens.ABOUT);
await promise;
expect(NavigationStore.getScreensInStack()).not.toContain(Screens.ABOUT);
});
});
});