Skip to content

Commit

Permalink
Updates to tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerwolff committed Nov 28, 2024
1 parent 79f44f7 commit d53017f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
48 changes: 47 additions & 1 deletion tests/accessibility/AccessibilitySystem.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ describe('AccessibilitySystem', () =>
const system = new AccessibilitySystem(renderer, {
phone: true,
} as any);

system.init({});
const hookDiv = system.hookDiv;

expect(hookDiv).toBeInstanceOf(HTMLElement);
Expand All @@ -28,16 +30,42 @@ describe('AccessibilitySystem', () =>
renderer.destroy();
});

it('should activate when tab is pressed and deactivate when mouse moved', async () =>
it('should respect activation configuration options', async () =>
{
const renderer = await getWebGLRenderer();
const system = new AccessibilitySystem(renderer);

system.init({
accessibilityOptions: {
enabledByDefault: true,
activateOnTab: false,
},
});

expect(system.isActive).toBe(true);

// Tab press should not activate when activateOnTab is false
system.setAccessibilityEnabled(false);
system['_onKeyDown'](new KeyboardEvent('keydown', { keyCode: 9, key: 'tab' }));
expect(system.isActive).toBe(false);

renderer.destroy();
});

it('should activate when tab is pressed by default', async () =>
{
const renderer = await getWebGLRenderer();
const system = new AccessibilitySystem(renderer);

system.init({});

system['_onKeyDown'](new KeyboardEvent('keydown', { keyCode: 9, key: 'tab' }));
expect(system.isActive).toBe(true);

system['_onMouseMove'](new MouseEvent('mousemove', { movementX: 10, movementY: 10 }));
expect(system.isActive).toBe(false);

renderer.destroy();
});

it('should not crash when scene graph contains Containers without children', async () =>
Expand All @@ -52,9 +80,27 @@ describe('AccessibilitySystem', () =>
const stage = new Container().addChild(new CompleteContainer());
const system = new AccessibilitySystem(renderer);

system.init({});

system['_onKeyDown'](new KeyboardEvent('keydown', { keyCode: 9, key: 'tab' }));

expect(() => renderer.render(stage)).not.toThrow();
expect(system.isActive).toBe(true);
});

it('should allow programmatic control of accessibility', async () =>
{
const renderer = await getWebGLRenderer();
const system = new AccessibilitySystem(renderer);

system.init({});

system.setAccessibilityEnabled(true);
expect(system.isActive).toBe(true);

system.setAccessibilityEnabled(false);
expect(system.isActive).toBe(false);

renderer.destroy();
});
});
1 change: 1 addition & 0 deletions tests/accessibility/accessibleTarget.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('accessibleTarget', () =>
expect(obj.accessible).toBeBoolean();
expect(obj.accessible).toBe(false);
expect(obj.accessibleTitle).toBeNull();
expect(obj.accessibleType).toBe('button');
expect(obj.accessibleHint).toBeNull();
expect(obj.tabIndex).toEqual(0);
});
Expand Down

0 comments on commit d53017f

Please sign in to comment.