Skip to content

Commit

Permalink
chore: [capricorn86#1534] Adds unit tests and adds some additional lo…
Browse files Browse the repository at this point in the history
…gic according to the spec
  • Loading branch information
capricorn86 committed Nov 3, 2024
1 parent 2e79fda commit e87ffc8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export default class HTMLDetailsElement extends HTMLElement {
const returnValue = super.dispatchEvent(event);

if (
!event[PropertySymbol.defaultPrevented] &&
event[PropertySymbol.target]?.[PropertySymbol.localName] === 'summary' &&
event.type === 'click' &&
event.eventPhase === EventPhaseEnum.bubbling &&
event instanceof MouseEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Window from '../../../src/window/Window.js';
import Document from '../../../src/nodes/document/Document.js';
import { beforeEach, describe, it, expect, vi } from 'vitest';
import Event from '../../../src/event/Event.js';
import MouseEvent from '../../../src/event/events/MouseEvent.js';

describe('HTMLDetailsElement', () => {
let window: Window;
Expand Down Expand Up @@ -51,5 +52,21 @@ describe('HTMLDetailsElement', () => {
element.open = false;
expect((<Event>(<unknown>triggeredEvent)).type).toBe('toggle');
});

it('Should not toggle the open state when a click event is dispatched directly on the details element', () => {
element.dispatchEvent(new MouseEvent('click'));
expect(element.open).toBe(false);
});

it('Should toggle the "open" attribute when a click event is dispatched on a summary element, which is a child of the details element', () => {
const summary = document.createElement('summary');
element.appendChild(summary);

summary.click();
expect(element.open).toBe(true);

summary.click();
expect(element.open).toBe(false);
});
});
});

0 comments on commit e87ffc8

Please sign in to comment.