Skip to content

Commit

Permalink
Merge pull request #1432 from r-thomson/htmltimeelement
Browse files Browse the repository at this point in the history
feat: [#1431] Implement HTMLTimeElement
  • Loading branch information
capricorn86 committed May 14, 2024
2 parents 909069b + a7aa4d7 commit f0d6091
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/happy-dom/src/config/HTMLElementConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export default <{ [key: string]: IHTMLElementConfigEntity }>{
contentModel: HTMLElementConfigContentModelEnum.anyDescendants
},
time: {
className: 'HTMLElement',
className: 'HTMLTimeElement',
localName: 'time',
tagName: 'TIME',
contentModel: HTMLElementConfigContentModelEnum.anyDescendants
Expand Down
3 changes: 2 additions & 1 deletion packages/happy-dom/src/config/IHTMLElementTagNameMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import HTMLIFrameElement from '../nodes/html-iframe-element/HTMLIFrameElement.js
import HTMLOptGroupElement from '../nodes/html-opt-group-element/HTMLOptGroupElement.js';
import HTMLOptionElement from '../nodes/html-option-element/HTMLOptionElement.js';
import HTMLSelectElement from '../nodes/html-select-element/HTMLSelectElement.js';
import HTMLTimeElement from '../nodes/html-time-element/HTMLTimeElement.js';
import HTMLVideoElement from '../nodes/html-video-element/HTMLVideoElement.js';

// Makes it work with custom elements when they declare their own interface.
Expand Down Expand Up @@ -139,7 +140,7 @@ export default interface IHTMLElementTagNameMap extends HTMLElementTagNameMap {
tfoot: HTMLElement;
th: HTMLElement;
thead: HTMLElement;
time: HTMLElement;
time: HTMLTimeElement;
title: HTMLElement;
tr: HTMLElement;
track: HTMLElement;
Expand Down
3 changes: 2 additions & 1 deletion packages/happy-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import HTMLSlotElement from './nodes/html-slot-element/HTMLSlotElement.js';
import HTMLStyleElement from './nodes/html-style-element/HTMLStyleElement.js';
import HTMLTemplateElement from './nodes/html-template-element/HTMLTemplateElement.js';
import HTMLTextAreaElement from './nodes/html-text-area-element/HTMLTextAreaElement.js';
import HTMLTimeElement from './nodes/html-time-element/HTMLTimeElement.js';
import HTMLUnknownElement from './nodes/html-unknown-element/HTMLUnknownElement.js';
import HTMLVideoElement from './nodes/html-video-element/HTMLVideoElement.js';
import Node from './nodes/node/Node.js';
Expand Down Expand Up @@ -303,7 +304,7 @@ export {
HTMLElement as HTMLTableSectionElement,
HTMLTemplateElement,
HTMLTextAreaElement,
HTMLElement as HTMLTimeElement,
HTMLTimeElement,
HTMLElement as HTMLTitleElement,
HTMLElement as HTMLTrackElement,
HTMLElement as HTMLUListElement,
Expand Down
27 changes: 27 additions & 0 deletions packages/happy-dom/src/nodes/html-time-element/HTMLTimeElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import HTMLElement from '../html-element/HTMLElement.js';

/**
* HTML Time Element.
*
* Reference:
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLTimeElement
*/
export default class HTMLTimeElement extends HTMLElement {
/**
* Returns dateTime.
*
* @returns dateTime.
*/
public get dateTime(): string {
return this.getAttribute('dateTime') || '';
}

/**
* Sets dateTime.
*
* @param dateTime dateTime.
*/
public set dateTime(dateTime: string) {
this.setAttribute('dateTime', dateTime);
}
}
3 changes: 2 additions & 1 deletion packages/happy-dom/src/window/BrowserWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import HTMLAnchorElement from '../nodes/html-anchor-element/HTMLAnchorElement.js
import HTMLButtonElement from '../nodes/html-button-element/HTMLButtonElement.js';
import HTMLOptionElement from '../nodes/html-option-element/HTMLOptionElement.js';
import HTMLOptGroupElement from '../nodes/html-opt-group-element/HTMLOptGroupElement.js';
import HTMLTimeElement from '../nodes/html-time-element/HTMLTimeElement.js';
import WindowPageOpenUtility from './WindowPageOpenUtility.js';
import IResponseBody from '../fetch/types/IResponseBody.js';
import IResponseInit from '../fetch/types/IResponseInit.js';
Expand Down Expand Up @@ -214,6 +215,7 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
public readonly HTMLLinkElement: typeof HTMLLinkElementImplementation;
public readonly HTMLIFrameElement: typeof HTMLIFrameElementImplementation;
public readonly HTMLFormElement: typeof HTMLFormElementImplementation;
public readonly HTMLTimeElement: typeof HTMLTimeElement = HTMLTimeElement;

// Non-implemented element classes
public readonly HTMLHeadElement: typeof HTMLElement = HTMLElement;
Expand Down Expand Up @@ -254,7 +256,6 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
public readonly HTMLTableCellElement: typeof HTMLElement = HTMLElement;
public readonly HTMLTableColElement: typeof HTMLElement = HTMLElement;
public readonly HTMLTableElement: typeof HTMLElement = HTMLElement;
public readonly HTMLTimeElement: typeof HTMLElement = HTMLElement;
public readonly HTMLTableRowElement: typeof HTMLElement = HTMLElement;
public readonly HTMLTableSectionElement: typeof HTMLElement = HTMLElement;
public readonly HTMLFrameElement: typeof HTMLElement = HTMLElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { beforeEach, describe, expect, it } from 'vitest';
import Document from '../../../src/nodes/document/Document.js';
import HTMLTimeElement from '../../../src/nodes/html-time-element/HTMLTimeElement.js';
import Window from '../../../src/window/Window.js';

describe('HTMLTimeElement', () => {
let window: Window;
let document: Document;
let element: HTMLTimeElement;

beforeEach(() => {
window = new Window();
document = window.document;
element = <HTMLTimeElement>document.createElement('time');
});

describe('get dateTime()', () => {
it('Gets the attribute value "datetime".', () => {
element.setAttribute('datetime', '1969-07-20');
expect(element.dateTime).toBe('1969-07-20');
});

it('Returns "" if the "datetime" attribute is not set.', () => {
expect(element.dateTime).toBe('');
});
});

describe('set dateTime()', () => {
it('Sets the attribute value "datetime".', () => {
element.dateTime = '1969-07-20';
expect(element.getAttribute('datetime')).toBe('1969-07-20');
});
});
});

0 comments on commit f0d6091

Please sign in to comment.