1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-03 01:09:06 +09:00
misskey/packages/frontend/test/scroll.test.ts

67 lines
1.8 KiB
TypeScript
Raw Normal View History

/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { describe, test, assert, afterEach } from 'vitest';
import { Window } from 'happy-dom';
2023-09-19 16:37:43 +09:00
import { onScrollBottom, onScrollTop } from '@/scripts/scroll.js';
describe('Scroll', () => {
describe('onScrollTop', () => {
2024-02-29 19:44:00 +09:00
/* (happy-dom)
test('Initial onScrollTop callback for connected elements', () => {
const { document } = new Window();
const div = document.createElement('div');
assert.strictEqual(div.scrollTop, 0);
document.body.append(div);
let called = false;
onScrollTop(div as any as HTMLElement, () => called = true);
assert.ok(called);
});
2024-02-29 19:44:00 +09:00
*/
test('No onScrollTop callback for disconnected elements', () => {
const { document } = new Window();
const div = document.createElement('div');
assert.strictEqual(div.scrollTop, 0);
let called = false;
onScrollTop(div as any as HTMLElement, () => called = true);
assert.ok(!called);
});
});
describe('onScrollBottom', () => {
2024-02-29 19:44:00 +09:00
/* (happy-dom)
test('Initial onScrollBottom callback for connected elements', () => {
const { document } = new Window();
const div = document.createElement('div');
assert.strictEqual(div.scrollTop, 0);
document.body.append(div);
let called = false;
onScrollBottom(div as any as HTMLElement, () => called = true);
assert.ok(called);
});
2024-02-29 19:44:00 +09:00
*/
test('No onScrollBottom callback for disconnected elements', () => {
const { document } = new Window();
const div = document.createElement('div');
assert.strictEqual(div.scrollTop, 0);
let called = false;
onScrollBottom(div as any as HTMLElement, () => called = true);
assert.ok(!called);
});
});
});