Skip to content

Commit 9f982a4

Browse files
committed
add tests
1 parent 4b14e41 commit 9f982a4

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/shared/text/text.component.spec.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,86 @@ describe('TextComponent', () => {
15571557

15581558
TestEnvironment.waitForPresenceTimer();
15591559
}));
1560+
1561+
describe('Text selection behavior', () => {
1562+
it('should track shift key state correctly', fakeAsync(() => {
1563+
const env: TestEnvironment = new TestEnvironment();
1564+
1565+
// Initially shift key should be false
1566+
expect((env.component as any).isShiftDown).toBe(false);
1567+
1568+
// Simulate shift key down
1569+
const keyDownEvent = new KeyboardEvent('keydown', { shiftKey: true });
1570+
document.dispatchEvent(keyDownEvent);
1571+
tick();
1572+
1573+
expect((env.component as any).isShiftDown).toBe(true);
1574+
1575+
// Simulate shift key up
1576+
const keyUpEvent = new KeyboardEvent('keyup', { shiftKey: false });
1577+
document.dispatchEvent(keyUpEvent);
1578+
tick();
1579+
1580+
expect((env.component as any).isShiftDown).toBe(false);
1581+
}));
1582+
1583+
it('should not call update() during selection expansion (shift down)', fakeAsync(() => {
1584+
const env: TestEnvironment = new TestEnvironment();
1585+
env.component.onEditorCreated(new MockQuill('quill-editor'));
1586+
env.waitForEditor();
1587+
1588+
spyOn(env.component, 'update' as any);
1589+
1590+
// Simulate shift key down
1591+
(env.component as any).isShiftDown = true;
1592+
1593+
// Call onSelectionChanged with a selection (length > 0)
1594+
const range: QuillRange = { index: 5, length: 3 };
1595+
env.component.onSelectionChanged(range);
1596+
tick();
1597+
1598+
// update() should not have been called
1599+
expect(env.component['update']).not.toHaveBeenCalled();
1600+
}));
1601+
1602+
it('should call update() when shift key is released', fakeAsync(() => {
1603+
const env: TestEnvironment = new TestEnvironment();
1604+
env.component.onEditorCreated(new MockQuill('quill-editor'));
1605+
env.waitForEditor();
1606+
1607+
spyOn(env.component, 'update' as any);
1608+
1609+
// Set shift key down initially
1610+
(env.component as any).isShiftDown = true;
1611+
1612+
// Simulate shift key release
1613+
const keyUpEvent = new KeyboardEvent('keyup', { shiftKey: false });
1614+
document.dispatchEvent(keyUpEvent);
1615+
tick();
1616+
1617+
// update() should have been called once
1618+
expect(env.component['update']).toHaveBeenCalledTimes(1);
1619+
}));
1620+
1621+
it('should call update() when no selection is active (cursor only)', fakeAsync(() => {
1622+
const env: TestEnvironment = new TestEnvironment();
1623+
env.component.onEditorCreated(new MockQuill('quill-editor'));
1624+
env.waitForEditor();
1625+
1626+
spyOn(env.component, 'update' as any);
1627+
1628+
// Simulate shift key not pressed
1629+
(env.component as any).isShiftDown = false;
1630+
1631+
// Call onSelectionChanged with cursor only (length = 0)
1632+
const range: QuillRange = { index: 5, length: 0 };
1633+
env.component.onSelectionChanged(range);
1634+
tick();
1635+
1636+
// update() should have been called
1637+
expect(env.component['update']).toHaveBeenCalledTimes(1);
1638+
}));
1639+
});
15601640
});
15611641

15621642
class MockDragEvent extends DragEvent {

0 commit comments

Comments
 (0)