Various search UI improvements

This commit is contained in:
Evan Hahn 2021-11-01 13:43:02 -05:00 committed by GitHub
parent 630394d91d
commit a9cb621eb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 835 additions and 577 deletions

View file

@ -7,14 +7,41 @@ import { v4 as uuid } from 'uuid';
import { RowType } from '../../../components/ConversationList';
import { FindDirection } from '../../../components/leftPane/LeftPaneHelper';
import { getDefaultConversation } from '../../../test-both/helpers/getDefaultConversation';
import { LeftPaneSearchHelper } from '../../../components/leftPane/LeftPaneSearchHelper';
import { LeftPaneArchiveHelper } from '../../../components/leftPane/LeftPaneArchiveHelper';
describe('LeftPaneArchiveHelper', () => {
let sandbox: sinon.SinonSandbox;
const defaults = {
archivedConversations: [],
searchConversation: undefined,
searchTerm: '',
};
const searchingDefaults = {
...defaults,
searchConversation: getDefaultConversation(),
conversationResults: { isLoading: false, results: [] },
contactResults: { isLoading: false, results: [] },
messageResults: { isLoading: false, results: [] },
searchTerm: 'foo',
primarySendsSms: false,
};
beforeEach(() => {
sandbox = sinon.createSandbox();
});
afterEach(() => {
sandbox.restore();
});
describe('getBackAction', () => {
it('returns the "show inbox" action', () => {
const showInbox = sinon.fake();
const helper = new LeftPaneArchiveHelper({ archivedConversations: [] });
const helper = new LeftPaneArchiveHelper(defaults);
assert.strictEqual(helper.getBackAction({ showInbox }), showInbox);
});
@ -22,12 +49,10 @@ describe('LeftPaneArchiveHelper', () => {
describe('getRowCount', () => {
it('returns the number of archived conversations', () => {
assert.strictEqual(
new LeftPaneArchiveHelper({ archivedConversations: [] }).getRowCount(),
0
);
assert.strictEqual(new LeftPaneArchiveHelper(defaults).getRowCount(), 0);
assert.strictEqual(
new LeftPaneArchiveHelper({
...defaults,
archivedConversations: [
getDefaultConversation(),
getDefaultConversation(),
@ -36,11 +61,20 @@ describe('LeftPaneArchiveHelper', () => {
2
);
});
it('defers to the search helper if searching', () => {
sandbox.stub(LeftPaneSearchHelper.prototype, 'getRowCount').returns(123);
assert.strictEqual(
new LeftPaneArchiveHelper(searchingDefaults).getRowCount(),
123
);
});
});
describe('getRowIndexToScrollTo', () => {
it('returns undefined if no conversation is selected', () => {
const helper = new LeftPaneArchiveHelper({
...defaults,
archivedConversations: [
getDefaultConversation(),
getDefaultConversation(),
@ -52,6 +86,7 @@ describe('LeftPaneArchiveHelper', () => {
it('returns undefined if the selected conversation is not pinned or non-pinned', () => {
const helper = new LeftPaneArchiveHelper({
...defaults,
archivedConversations: [
getDefaultConversation(),
getDefaultConversation(),
@ -66,7 +101,10 @@ describe('LeftPaneArchiveHelper', () => {
getDefaultConversation(),
getDefaultConversation(),
];
const helper = new LeftPaneArchiveHelper({ archivedConversations });
const helper = new LeftPaneArchiveHelper({
...defaults,
archivedConversations,
});
assert.strictEqual(
helper.getRowIndexToScrollTo(archivedConversations[0].id),
@ -77,6 +115,23 @@ describe('LeftPaneArchiveHelper', () => {
1
);
});
it('defers to the search helper if searching', () => {
sandbox
.stub(LeftPaneSearchHelper.prototype, 'getRowIndexToScrollTo')
.returns(123);
const archivedConversations = [
getDefaultConversation(),
getDefaultConversation(),
];
const helper = new LeftPaneArchiveHelper(searchingDefaults);
assert.strictEqual(
helper.getRowIndexToScrollTo(archivedConversations[0].id),
123
);
});
});
describe('getRow', () => {
@ -85,7 +140,10 @@ describe('LeftPaneArchiveHelper', () => {
getDefaultConversation(),
getDefaultConversation(),
];
const helper = new LeftPaneArchiveHelper({ archivedConversations });
const helper = new LeftPaneArchiveHelper({
...defaults,
archivedConversations,
});
assert.deepEqual(helper.getRow(0), {
type: RowType.Conversation,
@ -96,6 +154,18 @@ describe('LeftPaneArchiveHelper', () => {
conversation: archivedConversations[1],
});
});
it('defers to the search helper if searching', () => {
sandbox
.stub(LeftPaneSearchHelper.prototype, 'getRow')
.returns({ type: RowType.SearchResultsLoadingFakeHeader });
const helper = new LeftPaneArchiveHelper(searchingDefaults);
assert.deepEqual(helper.getRow(0), {
type: RowType.SearchResultsLoadingFakeHeader,
});
});
});
describe('getConversationAndMessageAtIndex', () => {
@ -104,7 +174,10 @@ describe('LeftPaneArchiveHelper', () => {
getDefaultConversation(),
getDefaultConversation(),
];
const helper = new LeftPaneArchiveHelper({ archivedConversations });
const helper = new LeftPaneArchiveHelper({
...defaults,
archivedConversations,
});
assert.strictEqual(
helper.getConversationAndMessageAtIndex(0)?.conversationId,
@ -121,7 +194,10 @@ describe('LeftPaneArchiveHelper', () => {
getDefaultConversation(),
getDefaultConversation(),
];
const helper = new LeftPaneArchiveHelper({ archivedConversations });
const helper = new LeftPaneArchiveHelper({
...defaults,
archivedConversations,
});
assert.strictEqual(
helper.getConversationAndMessageAtIndex(2)?.conversationId,
@ -141,12 +217,27 @@ describe('LeftPaneArchiveHelper', () => {
});
it('returns undefined if there are no archived conversations', () => {
const helper = new LeftPaneArchiveHelper({ archivedConversations: [] });
const helper = new LeftPaneArchiveHelper(defaults);
assert.isUndefined(helper.getConversationAndMessageAtIndex(0));
assert.isUndefined(helper.getConversationAndMessageAtIndex(1));
assert.isUndefined(helper.getConversationAndMessageAtIndex(-1));
});
it('defers to the search helper if searching', () => {
sandbox
.stub(
LeftPaneSearchHelper.prototype,
'getConversationAndMessageAtIndex'
)
.returns({ conversationId: 'abc123' });
const helper = new LeftPaneArchiveHelper(searchingDefaults);
assert.deepEqual(helper.getConversationAndMessageAtIndex(999), {
conversationId: 'abc123',
});
});
});
describe('getConversationAndMessageInDirection', () => {
@ -155,7 +246,10 @@ describe('LeftPaneArchiveHelper', () => {
getDefaultConversation(),
getDefaultConversation(),
];
const helper = new LeftPaneArchiveHelper({ archivedConversations });
const helper = new LeftPaneArchiveHelper({
...defaults,
archivedConversations,
});
assert.deepEqual(
helper.getConversationAndMessageInDirection(
@ -168,11 +262,37 @@ describe('LeftPaneArchiveHelper', () => {
});
// Additional tests are found with `getConversationInDirection`.
it('defers to the search helper if searching', () => {
sandbox
.stub(
LeftPaneSearchHelper.prototype,
'getConversationAndMessageInDirection'
)
.returns({ conversationId: 'abc123' });
const helper = new LeftPaneArchiveHelper(searchingDefaults);
assert.deepEqual(
helper.getConversationAndMessageInDirection(
{
direction: FindDirection.Down,
unreadOnly: false,
},
getDefaultConversation().id,
undefined
),
{
conversationId: 'abc123',
}
);
});
});
describe('shouldRecomputeRowHeights', () => {
it('always returns false because row heights are constant', () => {
it('returns false when not searching because row heights are constant', () => {
const helper = new LeftPaneArchiveHelper({
...defaults,
archivedConversations: [
getDefaultConversation(),
getDefaultConversation(),
@ -181,11 +301,13 @@ describe('LeftPaneArchiveHelper', () => {
assert.isFalse(
helper.shouldRecomputeRowHeights({
...defaults,
archivedConversations: [getDefaultConversation()],
})
);
assert.isFalse(
helper.shouldRecomputeRowHeights({
...defaults,
archivedConversations: [
getDefaultConversation(),
getDefaultConversation(),
@ -193,5 +315,27 @@ describe('LeftPaneArchiveHelper', () => {
})
);
});
it('returns true when going from searching → not searching', () => {
const helper = new LeftPaneArchiveHelper(defaults);
assert.isTrue(helper.shouldRecomputeRowHeights(searchingDefaults));
});
it('returns true when going from not searching → searching', () => {
const helper = new LeftPaneArchiveHelper(searchingDefaults);
assert.isTrue(helper.shouldRecomputeRowHeights(defaults));
});
it('defers to the search helper if searching', () => {
sandbox
.stub(LeftPaneSearchHelper.prototype, 'shouldRecomputeRowHeights')
.returns(true);
const helper = new LeftPaneArchiveHelper(searchingDefaults);
assert.isTrue(helper.shouldRecomputeRowHeights(searchingDefaults));
});
});
});