Tests for Util.scrollToBottom

pull/1570/head
Rick Carlino 2019-11-13 10:14:52 -06:00
parent b6d3852a0f
commit dd077d0cf7
2 changed files with 25 additions and 1 deletions

View File

@ -3,6 +3,31 @@ import { times } from "lodash";
import { fakeTimeSettings } from "../../__test_support__/fake_time_settings";
describe("util", () => {
describe("scrollToBottom", () => {
it("returns early if element is not found", () => {
document.body.innerHTML =
"<div>" +
" <button id=\"button\" />" +
"</div>";
jest.useFakeTimers();
Util.scrollToBottom("wow");
jest.runAllTimers();
expect(setTimeout).toHaveBeenCalledTimes(0);
});
it("scrolls to bottom when an element is found", () => {
document.body.innerHTML =
"<div>" +
" <span id=\"wow\" />" +
" <button id=\"button\" />" +
"</div>";
jest.useFakeTimers();
Util.scrollToBottom("wow");
jest.runAllTimers();
expect(setTimeout).toHaveBeenCalledTimes(1);
});
});
describe("safeStringFetch", () => {
const data = {
// tslint:disable-next-line:no-null-keyword

View File

@ -172,7 +172,6 @@ export const timestamp = (date = new Date()) => Math.round(date.getTime());
export function scrollToBottom(elementId: string) {
const elToScroll = document.getElementById(elementId);
if (!elToScroll) { return; }
// Wait for the new element height and scroll to the bottom.
setTimeout(() => elToScroll.scrollTop = elToScroll.scrollHeight, 1);
}