Skip to content

Commit

Permalink
navSelectors [nfc]: Remove now-unused getChatScreenParams and its hel…
Browse files Browse the repository at this point in the history
…pers.

navSelectors and navActions are kind of relics from before zulip#3804,
and we already have zulip#4417 for removing most or all of navActions.

Help along the removal of navSelectors by removing these things that
we stopped using in a recent commit.
  • Loading branch information
chrisbobbe committed Sep 10, 2021
1 parent eb5348c commit ca82cda
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 72 deletions.
61 changes: 1 addition & 60 deletions src/nav/__tests__/navSelectors-test.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,8 @@
import deepFreeze from 'deep-freeze';

import {
getCurrentRouteName,
getCurrentRouteParams,
getChatScreenParams,
getSameRoutesCount,
} from '../navSelectors';
import { getSameRoutesCount } from '../navSelectors';
import * as NavigationService from '../NavigationService';

describe('getCurrentRouteName', () => {
test('return name of the current route', () => {
NavigationService.getState = jest.fn().mockReturnValue(
deepFreeze({
index: 1,
routes: [
{ name: 'first', params: { email: 'a@a.com' } },
{ name: 'second', params: { email: 'b@a.com' } },
],
}),
);

const expectedResult = 'second';

const actualResult = getCurrentRouteName();

expect(actualResult).toEqual(expectedResult);
});
});

describe('getCurrentRouteParams', () => {
test('return params of the current route', () => {
NavigationService.getState = jest.fn().mockReturnValue(
deepFreeze({
index: 1,
routes: [
{ name: 'first', params: { email: 'a@a.com' } },
{ name: 'second', params: { email: 'b@a.com' } },
],
}),
);
const expectedResult = { email: 'b@a.com' };

const actualResult = getCurrentRouteParams();

expect(actualResult).toEqual(expectedResult);
});
});

describe('getChatScreenParams', () => {
test('when no params are passed do not return "undefined"', () => {
NavigationService.getState = jest.fn().mockReturnValue(
deepFreeze({
index: 0,
routes: [{ name: 'chat' }],
}),
);

const actualResult = getChatScreenParams();

expect(actualResult).toBeDefined();
});
});

describe('getSameRoutesCount', () => {
test('if no routes the count of same routes is 0', () => {
NavigationService.getState = jest.fn().mockReturnValue(
Expand Down
13 changes: 1 addition & 12 deletions src/nav/navSelectors.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
/* @flow strict-local */
import type { NavigationState, Route, ScreenParams } from '@react-navigation/native';
import type { NavigationState, Route } from '@react-navigation/native';

import * as NavigationService from './NavigationService';

export const getNavState = (): NavigationState => NavigationService.getState();

export const getNavigationRoutes = (): $ReadOnlyArray<Route<string>> => getNavState().routes;

const getNavigationIndex = () => getNavState().index;

const getCurrentRoute = (): void | Route<string> => getNavigationRoutes()[getNavigationIndex()];

export const getCurrentRouteName = (): void | string => getCurrentRoute()?.name;

export const getCurrentRouteParams = (): void | ScreenParams => getCurrentRoute()?.params;

export const getChatScreenParams = (): ScreenParams | {| narrow: void |} =>
getCurrentRouteParams() ?? { narrow: undefined };

export const getSameRoutesCount = (): number => {
const routes = getNavigationRoutes();
let i = routes.length - 1;
Expand Down

0 comments on commit ca82cda

Please sign in to comment.