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 Jul 26, 2021
1 parent 34ecaf8 commit 2b84f11
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 70 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
10 changes: 0 additions & 10 deletions src/nav/navSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ 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 = () => getCurrentRoute()?.name;

export const getCurrentRouteParams = () => getCurrentRoute()?.params;

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

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

0 comments on commit 2b84f11

Please sign in to comment.