Skip to content

Commit

Permalink
#450@trivial: Minor fixes on HTMLDialogElement.
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 committed Jun 30, 2022
1 parent eaaf255 commit a61c137
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
Expand Up @@ -21,7 +21,6 @@ export default [
'HTMLDataElement',
'HTMLDataListElement',
'HTMLDetailsElement',
'HTMLDialogElement',
'HTMLDirectoryElement',
'HTMLFieldSetElement',
'HTMLFontElement',
Expand Down
Expand Up @@ -9,12 +9,7 @@ import IHTMLDialogElement from './IHTMLDialogElement';
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement.
*/
export default class HTMLDialogElement extends HTMLElement implements IHTMLDialogElement {
/**
* Returns returnValue.
*
* @returns ReturnValue.
*/
public returnValue: string;
public returnValue = '';

/**
* Returns open.
Expand All @@ -28,12 +23,12 @@ export default class HTMLDialogElement extends HTMLElement implements IHTMLDialo
/**
* Closes the dialog.
*
* @param returnValue ReturnValue.
* @param [returnValue] ReturnValue.
*/
public close(returnValue?: string): void {
public close(returnValue = ''): void {
this.removeAttributeNS(null, 'open');
this.returnValue = returnValue;
this.dispatchEvent(new Event('close', { bubbles: false, cancelable: false }));
this.dispatchEvent(new Event('close'));
}

/**
Expand Down
Expand Up @@ -9,7 +9,21 @@ import IHTMLElement from '../html-element/IHTMLElement';
export default interface IHTMLDialogElement extends IHTMLElement {
open: boolean;
returnValue: string;

/**
* Closes the dialog.
*
* @param [returnValue] ReturnValue.
*/
close(returnValue?: string): void;

/**
* Shows the modal.
*/
showModal(): void;

/**
* Shows the dialog.
*/
show(): void;
}
@@ -1,20 +1,21 @@
import { Event } from 'src';
import Document from '../../../src/nodes/document/Document';
import HTMLDialogElement from '../../../src/nodes/html-dialog-element/HTMLDialogElement';
import Event from '../../../src/event/Event';
import IHTMLDialogElement from '../../../src/nodes/html-dialog-element/IHTMLDialogElement';
import Window from '../../../src/window/Window';
import IWindow from '../../../src/window/IWindow';
import IDocument from '../../../src/nodes/document/IDocument';

describe('HTMLDialogElement', () => {
let window: Window;
let document: Document;
let element: HTMLDialogElement;
let window: IWindow;
let document: IDocument;
let element: IHTMLDialogElement;

beforeEach(() => {
window = new Window();
document = window.document;
element = <HTMLDialogElement>document.createElement('dialog');
element = <IHTMLDialogElement>document.createElement('dialog');
});

describe('open', () => {
describe('get open()', () => {
it('Should be closed by default', () => {
expect(element.open).toBe(false);
});
Expand All @@ -30,23 +31,25 @@ describe('HTMLDialogElement', () => {
});
});

describe('returnValue', () => {
it('Should be undefined by default', () => {
expect(element.returnValue).toBe(undefined);
describe('get returnValue()', () => {
it('Should be empty string by default', () => {
expect(element.returnValue).toBe('');
});

it('Should be set when close has been called with a return value', () => {
element.close('foo');
expect(element.returnValue).toBe('foo');
});
});

describe('set returnValue()', () => {
it('Should be possible to set manually', () => {
element.returnValue = 'foo';
expect(element.returnValue).toBe('foo');
});
});

describe('close', () => {
describe('close()', () => {
it('Should be possible to close an open dialog', () => {
element.show();
element.close();
Expand Down Expand Up @@ -92,15 +95,15 @@ describe('HTMLDialogElement', () => {
});
});

describe('showModal', () => {
describe('showModal()', () => {
it('Should be possible to show a modal dialog', () => {
element.showModal();
expect(element.open).toBe(true);
expect(element.getAttributeNS(null, 'open')).toBe('');
});
});

describe('show', () => {
describe('show()', () => {
it('Should be possible to show a dialog', () => {
element.show();
expect(element.open).toBe(true);
Expand Down

0 comments on commit a61c137

Please sign in to comment.