fix(files): harden drag-and-drop uploads
Co-authored-by: Serhii Dziupin <serkraser@gmail.com> Co-authored-by: Alan Chen <2144783+alanzchen@users.noreply.github.com>
This commit is contained in:
co-authored by
Serhii Dziupin
Alan Chen
parent
0c5e183c62
commit
99873a7b12
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
|
||||
import {
|
||||
notifyFileContentInvalidated,
|
||||
subscribeToFileContentInvalidation,
|
||||
} from './fileContentInvalidation';
|
||||
|
||||
describe('fileContentInvalidation', () => {
|
||||
test('publishes normalized paths within the captured runtime', () => {
|
||||
const received: Array<{ runtimeKey: string; paths: readonly string[] }> = [];
|
||||
const unsubscribe = subscribeToFileContentInvalidation((invalidation) => {
|
||||
received.push(invalidation);
|
||||
});
|
||||
|
||||
notifyFileContentInvalidated({
|
||||
runtimeKey: ' runtime-a ',
|
||||
paths: [' /repo/a.txt ', '/repo/a.txt', '', '/repo/b.txt'],
|
||||
});
|
||||
unsubscribe();
|
||||
|
||||
expect(received).toEqual([{
|
||||
runtimeKey: 'runtime-a',
|
||||
paths: ['/repo/a.txt', '/repo/b.txt'],
|
||||
}]);
|
||||
});
|
||||
|
||||
test('stops publishing after unsubscribe', () => {
|
||||
let calls = 0;
|
||||
const unsubscribe = subscribeToFileContentInvalidation(() => {
|
||||
calls += 1;
|
||||
});
|
||||
unsubscribe();
|
||||
|
||||
notifyFileContentInvalidated({ runtimeKey: 'runtime-a', paths: ['/repo/a.txt'] });
|
||||
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user