Skip to content

Commit

Permalink
Fix Jest, Flow, ESLint (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
borisyankov committed Aug 21, 2017
1 parent 0109d86 commit 13fdf73
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 77 deletions.
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"color": "^2.0.0",
"date-fns": "^1.28.5",
"entities": "^1.1.1",
"eslint-plugin-flowtype": "^2.35.0",
"events": "^1.1.1",
"htmlparser2": "^3.9.2",
"immutable": "^3.8.1",
Expand All @@ -47,9 +46,8 @@
"react-intl": "^2.2.3",
"react-native": "^0.47.1",
"react-native-device-info": "^0.11.0",
"react-native-drawer": "^2.3.0",
"react-native-fetch-blob": "^0.10.8",
"react-native-notifications": "^1.1.13",
"react-native-notifications": "^1.1.14",
"react-native-photo-view": "1.3.0",
"react-native-safari-view": "^2.0.0",
"react-native-sentry": "^0.17.1",
Expand All @@ -71,22 +69,23 @@
"zulip-markdown-parser": "^1.0.4"
},
"devDependencies": {
"babel-core": "^6.25.0",
"babel-core": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-jest": "^20.0.0",
"babel-plugin-transform-remove-console": "^6.8.4",
"babel-preset-react-native": "^2.0.0",
"babel-preset-react-native": "^3.0.0",
"coveralls": "^2.13.0",
"deep-freeze": "^0.0.1",
"detox": "^5.6.1",
"eslint": "^4.3.0",
"eslint": "^4.5.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-config-airbnb-base": "^11.3.1",
"eslint-config-prettier": "^2.3.0",
"eslint-plugin-flowtype": "^2.35.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jest": "^20.0.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-prettier": "^2.1.2",
"eslint-plugin-prettier": "^2.2.0",
"eslint-plugin-react": "^7.2.0",
"eslint-plugin-react-native": "^3.0.1",
"eslint-plugin-spellcheck": "0.0.6",
Expand Down
8 changes: 8 additions & 0 deletions src/baseSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ export const getOutbox = (state: GlobalState): Outbox[] => state.outbox;

export const getActiveNarrowString = (state: GlobalState): string =>
JSON.stringify(state.chat.narrow);

export const getUnreadStreams = (state: GlobalState): Object[] => state.unread.streams;

export const getUnreadPms = (state: GlobalState): Object[] => state.unread.pms;

export const getUnreadHuddles = (state: GlobalState): Object[] => state.unread.huddles;

export const getUnreadMentions = (state: GlobalState): number[] => state.unread.mentions;
5 changes: 3 additions & 2 deletions src/common/ImageAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class ImageAvatar extends PureComponent {
avatarUrl: string,
size: number,
shape: string,
children: any[],
onPress: () => void,
};

Expand All @@ -18,7 +19,7 @@ export default class ImageAvatar extends PureComponent {
};

render() {
const { avatarUrl, size, shape, onPress } = this.props;
const { avatarUrl, children, size, shape, onPress } = this.props;
const touchableStyle = {
height: size,
width: size,
Expand All @@ -34,7 +35,7 @@ export default class ImageAvatar extends PureComponent {
source={{ uri: avatarUrl }}
resizeMode="cover"
borderRadius={borderRadius}>
{this.props.children}
{children}
</ImageBackground>
</Touchable>
);
Expand Down
5 changes: 3 additions & 2 deletions src/common/TextAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export default class TextAvatar extends PureComponent {
name: string,
size: number,
shape?: string,
children?: any[],
onPress?: () => void,
};

render() {
const { name, size, shape, onPress } = this.props;
const { children, name, size, shape, onPress } = this.props;

const frameSize = {
height: size,
Expand All @@ -53,7 +54,7 @@ export default class TextAvatar extends PureComponent {
<Text style={[styles.text, textSize]}>
{initialsFromName(name)}
</Text>
{this.props.children}
{children}
</View>
</Touchable>
);
Expand Down
28 changes: 25 additions & 3 deletions src/outbox/outboxActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */
import parseMarkdown from 'zulip-markdown-parser';

import type { Dispatch, GetState, Narrow } from '../types';
import type { Dispatch, GetState, Narrow, User } from '../types';
import {
MESSAGE_SEND,
START_OUTBOX_SENDING,
Expand All @@ -10,8 +10,8 @@ import {
} from '../actionConstants';
import { getAuth } from '../selectors';
import { sendMessage as sendMessageApi } from '../api';
import { getSelfUserDetail } from '../users/userSelectors';
import { extractTypeToAndSubjectFromNarrow, isPrivateOrGroupNarrow } from '../utils/narrow';
import { getSelfUserDetail, getUserByEmail } from '../users/userSelectors';
import { isStreamNarrow, isPrivateOrGroupNarrow } from '../utils/narrow';

export const sendMessage = (params: Object) => ({
type: MESSAGE_SEND,
Expand Down Expand Up @@ -47,6 +47,28 @@ export const trySendMessages = () => (dispatch: Dispatch, getState: GetState) =>
}
};

const mapEmailsToUsers = (users, narrow) =>
narrow[0].operand.split(',').map(item => {
const user = getUserByEmail(users, item);
return { email: item, id: user.id, full_name: user.fullName };
});

const extractTypeToAndSubjectFromNarrow = (
narrow: Narrow,
users: User[],
): { type: 'private' | 'stream', display_recipient: string, subject: string } => {
if (isPrivateOrGroupNarrow(narrow)) {
return {
type: 'private',
display_recipient: mapEmailsToUsers(users, narrow),
subject: '',
};
} else if (isStreamNarrow(narrow)) {
return { type: 'stream', display_recipient: narrow[0].operand, subject: '(no topic)' };
}
return { type: 'stream', display_recipient: narrow[0].operand, subject: narrow[1].operand };
};

export const addToOutbox = (narrow: Narrow, content: string) => async (
dispatch: Dispatch,
getState: GetState,
Expand Down
14 changes: 7 additions & 7 deletions src/unread/unreadSelectors.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* @flow */
import { createSelector } from 'reselect';

import type { GlobalState } from '../types';
import { caseInsensitiveCompareObjFunc } from '../utils/misc';
import {
getMute,
getUnreadStreams,
getUnreadPms,
getUnreadHuddles,
getUnreadMentions,
} from '../baseSelectors';
import { getSubscriptionsById } from '../subscriptions/subscriptionSelectors';
import { getMute } from '../baseSelectors';
import { NULL_SUBSCRIPTION } from '../nullObjects';

export const getUnreadStreams = (state: GlobalState): Object[] => state.unread.streams;
export const getUnreadPms = (state: GlobalState): Object[] => state.unread.pms;
export const getUnreadHuddles = (state: GlobalState): Object[] => state.unread.huddles;
export const getUnreadMentions = (state: GlobalState): number[] => state.unread.mentions;

export const getUnreadByStream = createSelector(getUnreadStreams, unreadStreams =>
unreadStreams.reduce((totals, stream) => {
totals[stream.stream_id] = (totals[stream.stream_id] || 0) + stream.unread_message_ids.length;
Expand Down
25 changes: 1 addition & 24 deletions src/utils/narrow.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* @flow */
import type { Narrow, Message, User } from '../types';
import type { Narrow, Message } from '../types';
import { normalizeRecipients } from './message';
import { getUserByEmail } from '../users/userSelectors';

export const homeNarrow: Narrow = [];

Expand Down Expand Up @@ -135,25 +134,3 @@ export const narrowFromMessage = (message: Message, email: string) => {

return streamNarrow(message.display_recipient);
};

const mapEmailsToUsers = (users, narrow) =>
narrow[0].operand.split(',').map(item => {
const user = getUserByEmail(users, item);
return { email: item, id: user.id, full_name: user.fullName };
});

export const extractTypeToAndSubjectFromNarrow = (
narrow: Narrow,
users: User[],
): { type: 'private' | 'stream', display_recipient: string, subject: string } => {
if (isPrivateOrGroupNarrow(narrow)) {
return {
type: 'private',
display_recipient: mapEmailsToUsers(users, narrow),
subject: '',
};
} else if (isStreamNarrow(narrow)) {
return { type: 'stream', display_recipient: narrow[0].operand, subject: '(no topic)' };
}
return { type: 'stream', display_recipient: narrow[0].operand, subject: narrow[1].operand };
};

0 comments on commit 13fdf73

Please sign in to comment.