Filter chats by Unread
This commit is contained in:
parent
45e9c07125
commit
a56e7d0ade
27 changed files with 883 additions and 438 deletions
|
@ -9,6 +9,18 @@ import { getDefaultConversation } from '../../../test-both/helpers/getDefaultCon
|
|||
|
||||
import { LeftPaneSearchHelper } from '../../../components/leftPane/LeftPaneSearchHelper';
|
||||
|
||||
const baseSearchHelperArgs = {
|
||||
conversationResults: { isLoading: false, results: [] },
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
filterByUnread: false,
|
||||
messageResults: { isLoading: false, results: [] },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
};
|
||||
describe('LeftPaneSearchHelper', () => {
|
||||
const fakeMessage = () => ({
|
||||
id: uuid(),
|
||||
|
@ -18,17 +30,7 @@ describe('LeftPaneSearchHelper', () => {
|
|||
|
||||
describe('getBackAction', () => {
|
||||
it('returns undefined; going back is handled elsewhere in the app', () => {
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
conversationResults: { isLoading: false, results: [] },
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
messageResults: { isLoading: false, results: [] },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
const helper = new LeftPaneSearchHelper(baseSearchHelperArgs);
|
||||
|
||||
assert.isUndefined(
|
||||
helper.getBackAction({
|
||||
|
@ -44,46 +46,31 @@ describe('LeftPaneSearchHelper', () => {
|
|||
it('returns 100 if any results are loading', () => {
|
||||
assert.strictEqual(
|
||||
new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: { isLoading: true },
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: true },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
}).getRowCount(),
|
||||
100
|
||||
);
|
||||
assert.strictEqual(
|
||||
new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: true },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
}).getRowCount(),
|
||||
100
|
||||
);
|
||||
assert.strictEqual(
|
||||
new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: { isLoading: true },
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: false, results: [fakeMessage()] },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
}).getRowCount(),
|
||||
100
|
||||
);
|
||||
|
@ -100,6 +87,7 @@ describe('LeftPaneSearchHelper', () => {
|
|||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
filterByUnread: false,
|
||||
});
|
||||
|
||||
assert.strictEqual(helper.getRowCount(), 0);
|
||||
|
@ -107,18 +95,13 @@ describe('LeftPaneSearchHelper', () => {
|
|||
|
||||
it('returns 1 + the number of results, dropping empty sections', () => {
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
messageResults: { isLoading: false, results: [fakeMessage()] },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
|
||||
assert.strictEqual(helper.getRowCount(), 5);
|
||||
|
@ -129,40 +112,25 @@ describe('LeftPaneSearchHelper', () => {
|
|||
it('returns a "loading search results" row if any results are loading', () => {
|
||||
const helpers = [
|
||||
new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: { isLoading: true },
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: true },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
}),
|
||||
new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: true },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
}),
|
||||
new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: { isLoading: true },
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: false, results: [fakeMessage()] },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
}),
|
||||
];
|
||||
|
||||
|
@ -188,18 +156,13 @@ describe('LeftPaneSearchHelper', () => {
|
|||
const messages = [fakeMessage(), fakeMessage()];
|
||||
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: conversations,
|
||||
},
|
||||
contactResults: { isLoading: false, results: contacts },
|
||||
messageResults: { isLoading: false, results: messages },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
|
@ -235,18 +198,9 @@ describe('LeftPaneSearchHelper', () => {
|
|||
const messages = [fakeMessage(), fakeMessage()];
|
||||
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [],
|
||||
},
|
||||
...baseSearchHelperArgs,
|
||||
contactResults: { isLoading: false, results: contacts },
|
||||
messageResults: { isLoading: false, results: messages },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
|
||||
assert.deepEqual(_testHeaderText(helper.getRow(0)), 'icu:contactsHeader');
|
||||
|
@ -273,18 +227,12 @@ describe('LeftPaneSearchHelper', () => {
|
|||
const messages = [fakeMessage(), fakeMessage()];
|
||||
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: conversations,
|
||||
},
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
messageResults: { isLoading: false, results: messages },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
|
@ -316,18 +264,12 @@ describe('LeftPaneSearchHelper', () => {
|
|||
const contacts = [getDefaultConversation()];
|
||||
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: conversations,
|
||||
},
|
||||
contactResults: { isLoading: false, results: contacts },
|
||||
messageResults: { isLoading: false, results: [] },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
|
@ -354,40 +296,25 @@ describe('LeftPaneSearchHelper', () => {
|
|||
it('returns false if any results are loading', () => {
|
||||
const helpers = [
|
||||
new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: { isLoading: true },
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: true },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
}),
|
||||
new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: true },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
}),
|
||||
new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: { isLoading: true },
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: false, results: [fakeMessage()] },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
}),
|
||||
];
|
||||
|
||||
|
@ -398,21 +325,15 @@ describe('LeftPaneSearchHelper', () => {
|
|||
|
||||
it('returns true if all results have loaded', () => {
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
messageResults: {
|
||||
isLoading: false,
|
||||
results: [fakeMessage(), fakeMessage(), fakeMessage()],
|
||||
},
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
assert.isTrue(helper.isScrollable());
|
||||
});
|
||||
|
@ -421,25 +342,20 @@ describe('LeftPaneSearchHelper', () => {
|
|||
describe('shouldRecomputeRowHeights', () => {
|
||||
it("returns false if the number of results doesn't change", () => {
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
messageResults: {
|
||||
isLoading: false,
|
||||
results: [fakeMessage(), fakeMessage(), fakeMessage()],
|
||||
},
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
|
||||
assert.isFalse(
|
||||
helper.shouldRecomputeRowHeights({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
|
@ -449,108 +365,68 @@ describe('LeftPaneSearchHelper', () => {
|
|||
isLoading: false,
|
||||
results: [fakeMessage(), fakeMessage(), fakeMessage()],
|
||||
},
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'bar',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('returns false when a section completes loading, but not all sections are done (because the pane is still loading overall)', () => {
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: { isLoading: true },
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: true },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
|
||||
assert.isFalse(
|
||||
helper.shouldRecomputeRowHeights({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: true },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'bar',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('returns true when all sections finish loading', () => {
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: { isLoading: true },
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: false, results: [fakeMessage()] },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
|
||||
assert.isTrue(
|
||||
helper.shouldRecomputeRowHeights({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
messageResults: { isLoading: false, results: [fakeMessage()] },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('returns true if the number of results in a section changes', () => {
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
messageResults: { isLoading: false, results: [] },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
|
||||
assert.isTrue(
|
||||
helper.shouldRecomputeRowHeights({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: { isLoading: true },
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'bar',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -560,21 +436,15 @@ describe('LeftPaneSearchHelper', () => {
|
|||
it('returns correct conversation at given index', () => {
|
||||
const expected = getDefaultConversation();
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [expected, getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
messageResults: {
|
||||
isLoading: false,
|
||||
results: [fakeMessage(), fakeMessage(), fakeMessage()],
|
||||
},
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
assert.strictEqual(
|
||||
helper.getConversationAndMessageAtIndex(0)?.conversationId,
|
||||
|
@ -585,6 +455,7 @@ describe('LeftPaneSearchHelper', () => {
|
|||
it('returns correct contact at given index', () => {
|
||||
const expected = getDefaultConversation();
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
|
@ -597,12 +468,6 @@ describe('LeftPaneSearchHelper', () => {
|
|||
isLoading: false,
|
||||
results: [fakeMessage(), fakeMessage(), fakeMessage()],
|
||||
},
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
assert.strictEqual(
|
||||
helper.getConversationAndMessageAtIndex(2)?.conversationId,
|
||||
|
@ -613,21 +478,15 @@ describe('LeftPaneSearchHelper', () => {
|
|||
it('returns correct message at given index', () => {
|
||||
const expected = fakeMessage();
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
messageResults: {
|
||||
isLoading: false,
|
||||
results: [fakeMessage(), fakeMessage(), expected],
|
||||
},
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
assert.strictEqual(
|
||||
helper.getConversationAndMessageAtIndex(4)?.messageId,
|
||||
|
@ -638,18 +497,13 @@ describe('LeftPaneSearchHelper', () => {
|
|||
it('returns correct message at given index skipping not loaded results', () => {
|
||||
const expected = fakeMessage();
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: { isLoading: true },
|
||||
contactResults: { isLoading: true },
|
||||
messageResults: {
|
||||
isLoading: false,
|
||||
results: [fakeMessage(), expected, fakeMessage()],
|
||||
},
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
assert.strictEqual(
|
||||
helper.getConversationAndMessageAtIndex(1)?.messageId,
|
||||
|
@ -659,21 +513,15 @@ describe('LeftPaneSearchHelper', () => {
|
|||
|
||||
it('returns undefined if search candidate with given index does not exist', () => {
|
||||
const helper = new LeftPaneSearchHelper({
|
||||
...baseSearchHelperArgs,
|
||||
conversationResults: {
|
||||
isLoading: false,
|
||||
results: [getDefaultConversation(), getDefaultConversation()],
|
||||
},
|
||||
contactResults: { isLoading: false, results: [] },
|
||||
messageResults: {
|
||||
isLoading: false,
|
||||
results: [fakeMessage(), fakeMessage(), fakeMessage()],
|
||||
},
|
||||
isSearchingGlobally: true,
|
||||
searchTerm: 'foo',
|
||||
primarySendsSms: false,
|
||||
searchConversation: undefined,
|
||||
searchDisabled: false,
|
||||
startSearchCounter: 0,
|
||||
});
|
||||
assert.isUndefined(
|
||||
helper.getConversationAndMessageAtIndex(100)?.messageId
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue