Skip to content

Commit

Permalink
support for audio element
Browse files Browse the repository at this point in the history
  • Loading branch information
JesperZachrisson committed Nov 28, 2023
1 parent 12bd63a commit e39fa1a
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

## 15.3.0

- Support audio element

## 15.2.1

- Bugfix in IntersectionObserver

## 15.2.0

- Make type declaration a module
Expand Down
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- version -->
# 15.2.1 API Reference
# 15.3.0 API Reference
<!-- versionstop -->

<!-- toc -->
Expand Down
23 changes: 23 additions & 0 deletions lib/HTMLAudioElement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

const HTMLElement = require("./HTMLElement.js");

module.exports = class HTMLAudioElement extends HTMLElement {
constructor(document, $elm) {
super(document, $elm);
this.paused = true;
this.duration = 0;
this.currentTime = 0;
this.volume = 1;
}
play() {
this.paused = false;
return Promise.resolve(undefined);
}
pause() {
this.paused = true;
}
_setDuration(duration) {
this.duration = duration;
}
};
2 changes: 2 additions & 0 deletions lib/elementFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const DocumentType = require("./DocumentType.js");
const HTMLElement = require("./HTMLElement.js");
const HTMLAnchorElement = require("./HTMLAnchorElement.js");
const HTMLAudioElement = require("./HTMLAudioElement.js");
const HTMLButtonElement = require("./HTMLButtonElement.js");
const HTMLDialogElement = require("./HTMLDialogElement.js");
const HTMLFieldSetElement = require("./HTMLFieldSetElement.js");
Expand All @@ -25,6 +26,7 @@ module.exports = class ElementFactory {
this.document = document;
this.definitions = {
a: HTMLAnchorElement,
audio: HTMLAudioElement,
button: HTMLButtonElement,
dialog: HTMLDialogElement,
fieldset: HTMLFieldSetElement,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expressen/tallahassee",
"version": "15.2.1",
"version": "15.3.0",
"description": "Lightweight client testing framework",
"main": "index.js",
"license": "BSD-3-Clause",
Expand Down
63 changes: 63 additions & 0 deletions test/elements-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const HTMLAnchorElement = require("../lib/HTMLAnchorElement.js");
const HTMLFormElement = require("../lib/HTMLFormElement.js");
const { Document } = require("../lib/index.js");
const { Event } = require("../lib/Events.js");
const { expect } = require("chai");

const elementProperties = [
"children",
Expand Down Expand Up @@ -1392,6 +1393,68 @@ describe("elements", () => {
});
});

describe("audio element", () => {
let document;
beforeEach(() => {
document = new Document({
text: `
<html>
<body>
<h2>Test <b>title</b></h2>
<audio id="audio-element"></audio>
</body>
</html>`,
});
});

it("has the expected properties", () => {
const audioElement = document.getElementById("audio-element");
expect(audioElement).to.have.property("paused", true);
expect(audioElement).to.have.property("duration", 0);
expect(audioElement).to.have.property("currentTime", 0);
expect(audioElement).to.have.property("volume", 1);
});

it("has a play method", () => {
const audioElement = document.getElementById("audio-element");
expect(typeof audioElement.play === "function").to.be.true;
});

it("the play method sets paused to false and returns a resolved promise", (done) => {
const audioElement = document.getElementById("audio-element");
const returnValue = audioElement.play();
expect(audioElement).to.have.property("paused", false);
expect(returnValue instanceof Promise).to.be.true;
returnValue.then((value) => {
expect(value).to.be.undefined;
done();
});
});

it("has a pause method", () => {
const audioElement = document.getElementById("audio-element");
expect(typeof audioElement.pause === "function").to.be.true;
});

it("the pause method sets paused to true and returns undefined", () => {
const audioElement = document.getElementById("audio-element");
const returnValue = audioElement.pause();
expect(audioElement).to.have.property("paused", true);
expect(returnValue).to.be.undefined;
});

it("has a _setDuration method", () => {
const audioElement = document.getElementById("audio-element");
expect(typeof audioElement._setDuration === "function").to.be.true;
});

it("the _setDuration method sets the duration in seconds", () => {
const audioElement = document.getElementById("audio-element");
audioElement._setDuration(50);
expect(audioElement).to.have.property("duration", 50);
});
});

describe("template element", () => {
let document;
beforeEach(() => {
Expand Down

0 comments on commit e39fa1a

Please sign in to comment.