forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not add message to state if not caught up (zulip#1261)
- Loading branch information
1 parent
1030ed9
commit e09648c
Showing
6 changed files
with
69 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,24 @@ describe('chatReducers', () => { | |
}); | ||
|
||
describe('EVENT_NEW_MESSAGE', () => { | ||
test('if not caught up in narrow, do not add message', () => { | ||
const initialState = deepFreeze({ | ||
messages: { | ||
[homeNarrowStr]: [{ id: 1 }, { id: 2 }], | ||
}, | ||
}); | ||
|
||
const action = deepFreeze({ | ||
type: EVENT_NEW_MESSAGE, | ||
message: { id: 3 }, | ||
caughtUp: {}, | ||
}); | ||
|
||
const newState = chatReducers(initialState, action); | ||
|
||
expect(newState).toBe(initialState); | ||
}); | ||
|
||
test('appends message to state producing a copy of messages', () => { | ||
const initialState = deepFreeze({ | ||
messages: { | ||
|
@@ -62,6 +80,12 @@ describe('chatReducers', () => { | |
const action = deepFreeze({ | ||
type: EVENT_NEW_MESSAGE, | ||
message: { id: 3 }, | ||
caughtUp: { | ||
[homeNarrowStr]: { | ||
older: false, | ||
newer: true, | ||
}, | ||
}, | ||
}); | ||
|
||
const expectedState = { | ||
|
@@ -87,14 +111,20 @@ describe('chatReducers', () => { | |
const action = deepFreeze({ | ||
type: EVENT_NEW_MESSAGE, | ||
message: { id: 2 }, | ||
caughtUp: { | ||
[homeNarrowStr]: { | ||
older: false, | ||
newer: true, | ||
}, | ||
}, | ||
}); | ||
|
||
const newState = chatReducers(initialState, action); | ||
|
||
expect(newState).toBe(initialState); | ||
}); | ||
|
||
test('Message sent to self is stored correctly', () => { | ||
test('message sent to self is stored correctly', () => { | ||
const narrowWithSelfStr = JSON.stringify(privateNarrow('[email protected]')); | ||
const initialState = deepFreeze({ | ||
messages: { | ||
|
@@ -111,6 +141,10 @@ describe('chatReducers', () => { | |
type: EVENT_NEW_MESSAGE, | ||
ownEmail: '[email protected]', | ||
message, | ||
caughtUp: { | ||
[homeNarrowStr]: { older: false, newer: true }, | ||
[narrowWithSelfStr]: { older: false, newer: true }, | ||
}, | ||
}); | ||
|
||
const expectedState = { | ||
|
@@ -126,7 +160,7 @@ describe('chatReducers', () => { | |
expect(newState).not.toBe(initialState); | ||
}); | ||
|
||
test('appends stream message to all cached narrows that match', () => { | ||
test('appends stream message to all cached narrows that match and are caught up', () => { | ||
const initialState = deepFreeze({ | ||
messages: { | ||
[homeNarrowStr]: [{ id: 1 }, { id: 2 }], | ||
|
@@ -147,6 +181,11 @@ describe('chatReducers', () => { | |
const action = deepFreeze({ | ||
type: EVENT_NEW_MESSAGE, | ||
message, | ||
caughtUp: { | ||
[homeNarrowStr]: { older: false, newer: true }, | ||
[streamNarrowStr]: { older: false, newer: true }, | ||
[topicNarrowStr]: { older: false, newer: true }, | ||
}, | ||
}); | ||
|
||
const expectedState = { | ||
|
@@ -182,6 +221,9 @@ describe('chatReducers', () => { | |
const action = deepFreeze({ | ||
type: EVENT_NEW_MESSAGE, | ||
message, | ||
caughtUp: { | ||
[homeNarrowStr]: { older: false, newer: true }, | ||
}, | ||
}); | ||
|
||
const expectedState = { | ||
|
@@ -218,6 +260,11 @@ describe('chatReducers', () => { | |
type: EVENT_NEW_MESSAGE, | ||
message, | ||
ownEmail: '[email protected]', | ||
caughtUp: { | ||
[homeNarrowStr]: { older: false, newer: true }, | ||
[allPrivateNarrowStr]: { older: false, newer: true }, | ||
[privateNarrowStr]: { older: false, newer: true }, | ||
}, | ||
}); | ||
|
||
const expectedState = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import { | |
isPrivateOrGroupNarrow, | ||
isMessageInNarrow, | ||
isStreamOrTopicNarrow, | ||
narrowFromMessage, | ||
getNarrowFromMessage, | ||
} from '../narrow'; | ||
|
||
describe('homeNarrow', () => { | ||
|
@@ -274,7 +274,7 @@ describe('isMessageInNarrow', () => { | |
}); | ||
}); | ||
|
||
describe('narrowFromMessage', () => { | ||
describe('getNarrowFromMessage', () => { | ||
test('message with single recipient, returns a private narrow', () => { | ||
const message = { | ||
display_recipient: [{ email: '[email protected]' }], | ||
|
@@ -284,7 +284,7 @@ describe('narrowFromMessage', () => { | |
}; | ||
const expectedNarrow = privateNarrow('[email protected]'); | ||
|
||
const actualNarrow = narrowFromMessage(message, auth.email); | ||
const actualNarrow = getNarrowFromMessage(message, auth.email); | ||
|
||
expect(actualNarrow).toEqual(expectedNarrow); | ||
}); | ||
|
@@ -298,7 +298,7 @@ describe('narrowFromMessage', () => { | |
}; | ||
const expectedNarrow = groupNarrow(['[email protected]', '[email protected]']); | ||
|
||
const actualNarrow = narrowFromMessage(message, auth.email); | ||
const actualNarrow = getNarrowFromMessage(message, auth.email); | ||
|
||
expect(actualNarrow).toEqual(expectedNarrow); | ||
}); | ||
|
@@ -309,7 +309,7 @@ describe('narrowFromMessage', () => { | |
}; | ||
const expectedNarrow = streamNarrow('stream'); | ||
|
||
const actualNarrow = narrowFromMessage(message); | ||
const actualNarrow = getNarrowFromMessage(message); | ||
|
||
expect(actualNarrow).toEqual(expectedNarrow); | ||
}); | ||
|
@@ -321,7 +321,7 @@ describe('narrowFromMessage', () => { | |
}; | ||
const expectedNarrow = topicNarrow('stream', 'subject'); | ||
|
||
const actualNarrow = narrowFromMessage(message); | ||
const actualNarrow = getNarrowFromMessage(message); | ||
|
||
expect(actualNarrow).toEqual(expectedNarrow); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters