Improve Android mailbox navigation and pagination
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -31,7 +31,7 @@ function harness({ platform = 'android', cached, sync }) {
|
||||
if (cached) bridge.getCachedFolder = cached;
|
||||
const context = {
|
||||
window: { daybreakMail: bridge },
|
||||
document: { body: { classList: { remove: value => classes.delete(value), contains: value => classes.has(value) } } },
|
||||
document: { visibilityState: 'visible', body: { classList: { remove: value => classes.delete(value), contains: value => classes.has(value) } } },
|
||||
rendererState: state,
|
||||
mailFeatureState: feature,
|
||||
selectMailUi: selector => {
|
||||
@@ -41,6 +41,7 @@ function harness({ platform = 'android', cached, sync }) {
|
||||
appShell: {
|
||||
renderList: () => renders.push(messages.map(message => message.id)),
|
||||
openMessage: id => opened.push(id),
|
||||
getReaderListPosition: () => 0,
|
||||
emptyReader: () => 'empty'
|
||||
},
|
||||
mailSearchFilters: () => ({}),
|
||||
@@ -224,6 +225,81 @@ test('scrolling to the end appends one page and retains the scroll position', as
|
||||
assert.deepEqual(offsets, [2]);
|
||||
});
|
||||
|
||||
test('Android background refresh waits while browsing and runs at the top', async () => {
|
||||
const offsets = [];
|
||||
const ui = harness({ sync: async (_folder, offset) => {
|
||||
offsets.push(offset);
|
||||
return { messages: result([1, 2]).messages, total: 40, start: 21, end: 22 };
|
||||
} });
|
||||
ui.state.messages.push(...result([1, 2, 3]).messages);
|
||||
ui.feature.total = 40;
|
||||
ui.feature.nextOffset = 40;
|
||||
const list = ui.context.selectMailUi('#message-list');
|
||||
Object.assign(list, { clientHeight: 300, scrollHeight: 1000, scrollTop: 700 });
|
||||
ui.context.requestBackgroundMailboxRefresh();
|
||||
ui.context.requestBackgroundMailboxRefresh({ offset: 0 });
|
||||
assert.deepEqual(offsets, []);
|
||||
assert.equal(ui.feature.browseRefreshPending, true);
|
||||
assert.match(ui.elements.get('#mail-status').textContent, /Updates paused/);
|
||||
assert.deepEqual(ui.state.messages.map(message => message.id), [1, 2, 3]);
|
||||
list.scrollTop = 0;
|
||||
ui.context.handleMessageListScroll();
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
assert.deepEqual(offsets, [0]);
|
||||
assert.equal(ui.feature.browseRefreshPending, false);
|
||||
assert.deepEqual(ui.state.messages.map(message => message.id), [1, 2]);
|
||||
});
|
||||
|
||||
test('automatic refresh is deferred during an Android page fetch and manual refresh remains available', async () => {
|
||||
const page = deferred();
|
||||
const offsets = [];
|
||||
const ui = harness({ sync: (_folder, offset) => {
|
||||
offsets.push(offset);
|
||||
return offsets.length === 1 ? page.promise : Promise.resolve(result([1]));
|
||||
} });
|
||||
ui.state.messages.push(...result([1, 2]).messages);
|
||||
ui.feature.total = 40;
|
||||
ui.feature.nextOffset = 20;
|
||||
const list = ui.context.selectMailUi('#message-list');
|
||||
Object.assign(list, { clientHeight: 300, scrollHeight: 1000, scrollTop: 700 });
|
||||
const pending = ui.context.syncMailbox(false, { append: true });
|
||||
assert.match(ui.elements.get('#mail-status').textContent, /Loading more/);
|
||||
ui.context.requestBackgroundMailboxRefresh({ offset: 0 });
|
||||
list.scrollHeight = 1400;
|
||||
page.resolve({ messages: result([3, 4]).messages, total: 40, start: 1, end: 2 });
|
||||
await pending;
|
||||
assert.deepEqual(offsets, [20]);
|
||||
assert.deepEqual(ui.state.messages.map(message => message.id), [1, 2, 3, 4]);
|
||||
assert.match(ui.elements.get('#mail-status').textContent, /Updates paused/);
|
||||
await ui.context.syncMailbox(true, { offset: 0 });
|
||||
assert.deepEqual(offsets, [20, 0]);
|
||||
assert.equal(ui.feature.browseRefreshPending, false);
|
||||
});
|
||||
|
||||
test('desktop background refresh remains immediate while scrolled down', async () => {
|
||||
const offsets = [];
|
||||
const ui = harness({ platform: 'desktop', sync: async (_folder, offset) => {
|
||||
offsets.push(offset);
|
||||
return result([1]);
|
||||
} });
|
||||
Object.assign(ui.context.selectMailUi('#message-list'), { scrollTop: 700, scrollHeight: 1000, clientHeight: 300 });
|
||||
ui.context.requestBackgroundMailboxRefresh({ offset: 0 });
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
assert.deepEqual(offsets, [0]);
|
||||
});
|
||||
|
||||
test('Android defers background refresh when the hidden reader list was scrolled', () => {
|
||||
let calls = 0;
|
||||
const ui = harness({ sync: async () => { calls++; return result([1]); } });
|
||||
ui.context.appShell.getReaderListPosition = () => 500;
|
||||
ui.classes.add('reader-open');
|
||||
Object.assign(ui.context.selectMailUi('#message-list'), { scrollTop: 0 });
|
||||
ui.feature.nextOffset = 20;
|
||||
ui.context.requestBackgroundMailboxRefresh();
|
||||
assert.equal(calls, 0);
|
||||
assert.equal(ui.feature.browseRefreshPending, true);
|
||||
});
|
||||
|
||||
test('short lists continue loading until the viewport is filled', async () => {
|
||||
let calls = 0;
|
||||
const ui = harness({ sync: async () => {
|
||||
|
||||
Reference in New Issue
Block a user