2023-08-13 12:22:57 +00:00
|
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-08-13 12:22:57 +00:00
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { describe, test, assert, afterEach } from 'vitest';
|
|
|
|
|
import { Window } from 'happy-dom';
|
2024-08-31 00:42:44 +00:00
|
|
|
|
import { onScrollBottom, onScrollTop } from '@@/js/scroll.js';
|
2023-08-13 12:22:57 +00:00
|
|
|
|
|
|
|
|
|
describe('Scroll', () => {
|
|
|
|
|
describe('onScrollTop', () => {
|
2024-02-29 10:44:00 +00:00
|
|
|
|
/* 動作しない(happy-domのバグ?)
|
2023-08-13 12:22:57 +00:00
|
|
|
|
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 10:44:00 +00:00
|
|
|
|
*/
|
2023-08-13 12:22:57 +00: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 10:44:00 +00:00
|
|
|
|
/* 動作しない(happy-domのバグ?)
|
2023-08-13 12:22:57 +00:00
|
|
|
|
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 10:44:00 +00:00
|
|
|
|
*/
|
2023-08-13 12:22:57 +00: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);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|