Spaces:
Running
Running
File size: 1,121 Bytes
d0878a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import { pinElementToScrollerTop, findLatestUserMessage } from './pinLatestQuestion';
describe('pin latest question', () => {
test('scrolls so the question sits at the top of the scroller', () => {
const scrollTo = jest.fn();
const scroller = {
scrollTop: 40,
scrollTo,
getBoundingClientRect: () => ({ top: 100, bottom: 700 }),
};
const element = {
getBoundingClientRect: () => ({ top: 220, bottom: 280 }),
};
expect(pinElementToScrollerTop(scroller, element, { behavior: 'auto' })).toBe(true);
expect(scrollTo).toHaveBeenCalledWith({ top: 160, behavior: 'auto' });
});
test('finds the newest real user question, skipping reference snippets', () => {
const latest = findLatestUserMessage([
{ id: '1', type: 'user', content: 'old' },
{ id: '2', type: 'advisor', content: 'ans' },
{ id: '3', type: 'user', content: 'new question' },
{ id: '4', type: 'user', content: 'Here are references', isReferenceSnippet: true },
]);
expect(latest).toMatchObject({ id: '3', content: 'new question' });
});
});
|