2017-10-04 07:44:08 +00:00
|
|
|
describe("The enumeration object", function () {
|
|
|
|
it("BackgroundType should exist", function () {
|
|
|
|
expect(BackgroundType).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("GradientType should exist", function () {
|
|
|
|
expect(GradientType).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("HorizontalAlign should exist", function () {
|
|
|
|
expect(HorizontalAlign).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("VerticalAlign should exist", function () {
|
|
|
|
expect(VerticalAlign).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("AudioState should exist", function () {
|
|
|
|
expect(AudioState).toBeDefined();
|
|
|
|
});
|
2019-01-24 09:49:45 +00:00
|
|
|
|
|
|
|
it("TransitionState should exist", function(){
|
|
|
|
expect(TransitionState).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("AnimationState should exist", function(){
|
|
|
|
expect(AnimationState).toBeDefined();
|
|
|
|
});
|
2017-10-04 07:44:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("The function", function () {
|
|
|
|
it("$() should return the right element", function () {
|
|
|
|
var div = document.createElement("div");
|
|
|
|
div.setAttribute("id", "dollar-test");
|
|
|
|
document.body.appendChild(div);
|
|
|
|
expect($("#dollar-test")[0]).toBe(div);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("_buildLinearGradient() should build the correct string", function () {
|
|
|
|
var gradient = _buildLinearGradient("left top", "left bottom", "#000", "#fff");
|
|
|
|
expect(gradient).toBe("-webkit-gradient(linear, left top, left bottom, from(#000), to(#fff)) fixed");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("_buildRadialGradient() should build the correct string", function () {
|
|
|
|
var gradient = _buildRadialGradient(10, "#000", "#fff");
|
|
|
|
expect(gradient).toBe("-webkit-gradient(radial, 10 50%, 100, 10 50%, 10, from(#000), to(#fff)) fixed");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("_getStyle should return the correct style on an element", function () {
|
|
|
|
var div = document.createElement("div");
|
|
|
|
div.style.setProperty("width", "100px");
|
|
|
|
div.setAttribute("id", "style-test");
|
|
|
|
document.body.appendChild(div);
|
|
|
|
expect(_getStyle($("#style-test")[0], "width")).toBe("100px");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("_nl2br should turn UNIX newlines into <br> tags", function () {
|
|
|
|
var text = "Amazing grace, how sweet the sound\nThat saved a wretch like me";
|
|
|
|
expect(_nl2br(text)).toEqual("Amazing grace, how sweet the sound<br>That saved a wretch like me");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("_nl2br should turn Windows newlines into <br> tags", function () {
|
|
|
|
var text = "Amazing grace, how sweet the sound\r\nThat saved a wretch like me";
|
|
|
|
expect(_nl2br(text)).toEqual("Amazing grace, how sweet the sound<br>That saved a wretch like me");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("_prepareText should turn verse text into a paragraph", function () {
|
|
|
|
var text = "Amazing grace, how sweet the sound\nThat saved a wretch like me";
|
|
|
|
expect(_prepareText(text)).toEqual("<p>Amazing grace, how sweet the sound<br>That saved a wretch like me</p>");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("The Display object", function () {
|
|
|
|
it("should start with a blank _slides object", function () {
|
|
|
|
expect(Display._slides).toEqual({});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should have the correct Reveal config", function () {
|
|
|
|
expect(Display._revealConfig).toEqual({
|
|
|
|
margin: 0.0,
|
|
|
|
minScale: 1.0,
|
|
|
|
maxScale: 1.0,
|
|
|
|
controls: false,
|
|
|
|
progress: false,
|
|
|
|
history: false,
|
|
|
|
overview: false,
|
|
|
|
center: false,
|
|
|
|
help: false,
|
2019-01-16 06:15:21 +00:00
|
|
|
transition: "none",
|
|
|
|
backgroundTransition: "none",
|
2017-10-04 07:44:08 +00:00
|
|
|
viewDistance: 9999,
|
|
|
|
width: "100%",
|
|
|
|
height: "100%"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should have an init() method", function () {
|
|
|
|
expect(Display.init).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should initialise Reveal when init is called", function () {
|
|
|
|
spyOn(Reveal, "initialize");
|
|
|
|
Display.init();
|
|
|
|
expect(Reveal.initialize).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should have a reinit() method", function () {
|
|
|
|
expect(Display.reinit).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should re-initialise Reveal when reinit is called", function () {
|
|
|
|
spyOn(Reveal, "reinitialize");
|
|
|
|
Display.reinit();
|
|
|
|
expect(Reveal.reinitialize).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should have a setTransition() method", function () {
|
|
|
|
expect(Display.setTransition).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should have a correctly functioning setTransition() method", function () {
|
|
|
|
spyOn(Reveal, "configure");
|
|
|
|
Display.setTransition("fade");
|
|
|
|
expect(Reveal.configure).toHaveBeenCalledWith({"transition": "fade"});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should have a correctly functioning clearSlides() method", function () {
|
|
|
|
expect(Display.clearSlides).toBeDefined();
|
|
|
|
|
|
|
|
document.body.innerHTML = "";
|
|
|
|
var slidesDiv = document.createElement("div");
|
|
|
|
slidesDiv.setAttribute("class", "slides");
|
|
|
|
slidesDiv.innerHTML = "<section><p></p></section>";
|
|
|
|
document.body.appendChild(slidesDiv);
|
|
|
|
|
|
|
|
Display.clearSlides();
|
|
|
|
expect($(".slides")[0].innerHTML).toEqual("");
|
|
|
|
expect(Display._slides).toEqual({});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should have a correct goToSlide() method", function () {
|
|
|
|
spyOn(Reveal, "slide");
|
|
|
|
spyOn(Display, "_slides");
|
|
|
|
Display._slides["v1"] = 0;
|
|
|
|
|
|
|
|
Display.goToSlide("v1");
|
|
|
|
expect(Reveal.slide).toHaveBeenCalledWith(0);
|
|
|
|
});
|
2019-01-24 09:49:45 +00:00
|
|
|
|
|
|
|
it("should have an alert() method", function () {
|
|
|
|
expect(Display.alert).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2019-02-12 10:08:25 +00:00
|
|
|
describe("Display.alert", function () {
|
2019-03-29 12:36:32 +00:00
|
|
|
var alertBackground, alertText, settings;
|
2019-02-12 10:08:25 +00:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
document.body.innerHTML = "";
|
|
|
|
alertBackground = document.createElement("div");
|
|
|
|
alertBackground.setAttribute("id", "alert-background");
|
|
|
|
document.body.appendChild(alertBackground);
|
2019-03-29 12:36:32 +00:00
|
|
|
alertText = document.createElement("p");
|
|
|
|
alertText.setAttribute("id","alert");
|
|
|
|
alertBackground.appendChild(alertText);
|
2019-02-22 11:31:38 +00:00
|
|
|
settings = '{ \
|
|
|
|
"location": 1, "font_face": "Segoe UI, Tahoma, Geneva, Verdana, sans-serif", \
|
2019-03-12 19:37:07 +00:00
|
|
|
"font_size": 40, "font_color": "#ffffff", "background_color": "#660000", \
|
2019-03-29 12:36:32 +00:00
|
|
|
"timeout": 5, "repeat": 1, "scroll": true \
|
2019-02-22 11:31:38 +00:00
|
|
|
}';
|
2019-02-12 10:08:25 +00:00
|
|
|
});
|
2019-01-24 09:49:45 +00:00
|
|
|
|
2019-02-12 10:08:25 +00:00
|
|
|
it("should return null if called without any text", function () {
|
2019-02-22 11:31:38 +00:00
|
|
|
expect(Display.alert("",settings)).toBeNull();
|
2019-02-12 10:08:25 +00:00
|
|
|
});
|
2019-01-24 09:49:45 +00:00
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
it("should set the correct alert text", function () {
|
2019-03-29 14:18:54 +00:00
|
|
|
spyOn(Display, "setAlertKeyframes");
|
2019-02-22 11:31:38 +00:00
|
|
|
Display.alert("OPEN-LP-3.0 Alert Test", settings);
|
2019-03-29 14:18:54 +00:00
|
|
|
|
|
|
|
expect(alertText.innerHTML).toEqual("OPEN-LP-3.0 Alert Test");
|
2019-02-12 10:08:25 +00:00
|
|
|
});
|
2019-01-24 09:49:45 +00:00
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
it("should call the addAlertToQueue method if an alert is displaying", function () {
|
2019-03-29 14:18:54 +00:00
|
|
|
spyOn(Display, "addAlertToQueue");
|
|
|
|
spyOn(Display, "setAlertKeyframes");
|
2019-03-06 10:05:28 +00:00
|
|
|
Display._alerts = [];
|
|
|
|
Display._alertState = AlertState.Displaying;
|
2019-03-29 12:36:32 +00:00
|
|
|
var text = "Testing alert queue";
|
|
|
|
|
|
|
|
Display.alert(text, settings);
|
|
|
|
|
|
|
|
expect(Display.addAlertToQueue).toHaveBeenCalledWith(text, settings);
|
2019-03-04 10:29:08 +00:00
|
|
|
});
|
2019-03-17 19:05:31 +00:00
|
|
|
|
|
|
|
it("should set the alert settings correctly", function() {
|
2019-03-29 14:18:54 +00:00
|
|
|
spyOn(Display, "setAlertKeyframes");
|
2019-03-17 19:05:31 +00:00
|
|
|
Display.alert("Testing settings", settings);
|
2019-03-29 12:36:32 +00:00
|
|
|
|
2019-03-17 19:05:31 +00:00
|
|
|
expect(Display._alertSettings).toEqual(JSON.parse(settings));
|
|
|
|
});
|
2019-02-06 20:33:16 +00:00
|
|
|
});
|
|
|
|
|
2019-03-17 19:05:31 +00:00
|
|
|
describe("Display.showAlertBackground", function () {
|
2019-02-06 20:33:16 +00:00
|
|
|
|
2019-03-17 19:05:31 +00:00
|
|
|
var alertBackground, css, settings, style;
|
2019-03-06 10:05:28 +00:00
|
|
|
beforeEach(function () {
|
2019-02-12 10:08:25 +00:00
|
|
|
document.body.innerHTML = "";
|
2019-03-01 12:39:29 +00:00
|
|
|
style = document.createElement("style");
|
|
|
|
style.type = "text/css";
|
2019-03-17 19:05:31 +00:00
|
|
|
css = '.bg-default { position: absolute; margin: 0; padding: 0; left: 0; z-index: 10; \
|
2019-03-01 12:39:29 +00:00
|
|
|
width: 100%; height: 0%; vertical-align: middle; overflow: hidden; visibility:hidden; \
|
|
|
|
}';
|
|
|
|
settings = {
|
|
|
|
"location": 2, "font_face": "Tahoma", "font_size": 40,
|
2019-03-12 19:37:07 +00:00
|
|
|
"font_color": "rgb(255, 255, 255)", "background_color": "rgb(102, 0, 0)",
|
|
|
|
"timeout": 5, "repeat": 1, "scrolling_text": true
|
2019-03-01 12:39:29 +00:00
|
|
|
};
|
|
|
|
style.innerHTML = css;
|
|
|
|
document.head.appendChild(style);
|
2019-02-12 10:08:25 +00:00
|
|
|
alertBackground = document.createElement("div");
|
|
|
|
alertBackground.setAttribute("id", "alert-background");
|
2019-03-17 19:05:31 +00:00
|
|
|
alertBackground.setAttribute("class", "bg-default");
|
|
|
|
document.body.appendChild(alertBackground);
|
2019-03-06 10:05:28 +00:00
|
|
|
Display._alertState = AlertState.NotDisplaying;
|
2019-02-12 10:08:25 +00:00
|
|
|
});
|
2019-02-06 20:33:16 +00:00
|
|
|
|
2019-03-06 10:05:28 +00:00
|
|
|
it("should set the correct transition state", function () {
|
2019-03-17 19:05:31 +00:00
|
|
|
Display.showAlertBackground(settings);
|
2019-03-06 10:05:28 +00:00
|
|
|
expect(Display._transitionState).toEqual(TransitionState.EntranceTransition);
|
2019-03-29 14:18:54 +00:00
|
|
|
});
|
2019-03-06 10:05:28 +00:00
|
|
|
|
2019-03-17 19:05:31 +00:00
|
|
|
it("should apply the styles correctly when showAlertBackground is called", function (done) {
|
|
|
|
Display.showAlertBackground(settings);
|
|
|
|
expect(alertBackground.className).toBe("bg-default bottom");
|
2019-02-22 11:31:38 +00:00
|
|
|
|
2019-03-17 19:05:31 +00:00
|
|
|
setTimeout(function () {
|
2019-03-06 10:05:28 +00:00
|
|
|
expect(alertBackground.style.backgroundColor).toEqual(settings.background_color);
|
2019-03-29 14:18:54 +00:00
|
|
|
expect(alertBackground.classList.contains("show")).toBe(true);
|
|
|
|
expect(alertBackground.style.transition).toEqual("min-height 1s linear");
|
2019-03-01 12:39:29 +00:00
|
|
|
done();
|
2019-03-06 10:05:28 +00:00
|
|
|
}, 50);
|
2019-03-29 12:36:32 +00:00
|
|
|
});
|
2017-10-04 07:44:08 +00:00
|
|
|
});
|
|
|
|
|
2019-03-17 19:05:31 +00:00
|
|
|
describe("Display.hideAlertBackground", function () {
|
2019-02-12 10:08:25 +00:00
|
|
|
var alertBackground;
|
2019-03-29 12:36:32 +00:00
|
|
|
beforeEach( function() {
|
2019-02-12 10:08:25 +00:00
|
|
|
document.body.innerHTML = "";
|
|
|
|
alertBackground = document.createElement("div");
|
2019-03-29 12:36:32 +00:00
|
|
|
alertBackground.setAttribute("id", "alert-background");
|
|
|
|
document.body.appendChild(alertBackground);
|
2019-03-06 10:05:28 +00:00
|
|
|
});
|
2019-03-29 12:36:32 +00:00
|
|
|
|
|
|
|
it("reset the background to default once an alert has been displayed", function() {
|
2019-04-02 19:08:27 +00:00
|
|
|
//spyOn(Display, "showNextAlert");
|
2019-03-17 19:05:31 +00:00
|
|
|
Display.hideAlertBackground();
|
2019-03-29 12:36:32 +00:00
|
|
|
|
2019-03-06 10:05:28 +00:00
|
|
|
expect(Display._transitionState).toEqual(TransitionState.ExitTransition);
|
2019-03-29 12:36:32 +00:00
|
|
|
expect(Display._alertState).toEqual(AlertState.NotDisplaying);
|
2019-03-29 14:18:54 +00:00
|
|
|
expect(alertBackground.style.transition).toEqual("min-height 1s linear");
|
|
|
|
expect(alertBackground.className).toEqual("hide");
|
2019-02-12 10:08:25 +00:00
|
|
|
});
|
2019-02-06 20:33:16 +00:00
|
|
|
});
|
2019-01-24 09:49:45 +00:00
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
describe("Display.setAlertText", function() {
|
|
|
|
var alertText;
|
|
|
|
beforeEach( function() {
|
|
|
|
document.body.innerHTML = "";
|
|
|
|
alertText = document.createElement("p");
|
|
|
|
alertText.setAttribute("id", "alert");
|
|
|
|
document.body.appendChild(alertText);
|
2019-03-06 10:05:28 +00:00
|
|
|
});
|
2019-03-29 12:36:32 +00:00
|
|
|
it("should set the alert text correctly", function () {
|
|
|
|
Display.setAlertText("OpenLP Alert Text");
|
2019-03-06 10:05:28 +00:00
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
expect(alertText.textContent).toEqual("OpenLP Alert Text");
|
2019-03-06 10:05:28 +00:00
|
|
|
});
|
|
|
|
});
|
2019-01-24 09:49:45 +00:00
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
describe("Display.setAlertLocation", function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
document.body.innerHTML = "";
|
|
|
|
alertBackground = document.createElement("p");
|
|
|
|
alertBackground.setAttribute("id","alert-background");
|
|
|
|
alertBackground.setAttribute("class","bg-default");
|
2019-03-15 14:46:26 +00:00
|
|
|
document.body.appendChild(alertBackground);
|
|
|
|
});
|
2019-03-29 12:36:32 +00:00
|
|
|
it("should set the correct class when location is top of the page", function () {
|
|
|
|
Display.setAlertLocation(0);
|
2019-03-15 14:46:26 +00:00
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
expect(alertBackground.className).toEqual("bg-default top");
|
|
|
|
});
|
2019-03-15 14:46:26 +00:00
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
it("should set the correct class when location is middle of the page", function () {
|
|
|
|
Display.setAlertLocation(1);
|
|
|
|
|
|
|
|
expect(alertBackground.className).toEqual("bg-default middle");
|
2019-03-15 14:46:26 +00:00
|
|
|
});
|
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
it("should set the correct class when location is bottom of the page", function () {
|
|
|
|
Display.setAlertLocation(2);
|
2019-03-15 14:46:26 +00:00
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
expect(alertBackground.className).toEqual("bg-default bottom");
|
2019-03-15 14:46:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-17 19:05:31 +00:00
|
|
|
describe("Display.showAlertText", function () {
|
|
|
|
var alertText, settings;
|
2019-03-15 14:46:26 +00:00
|
|
|
beforeEach(function () {
|
2019-03-17 19:05:31 +00:00
|
|
|
document.body.innerHTML = "";
|
2019-03-15 14:46:26 +00:00
|
|
|
alertText = document.createElement("p");
|
|
|
|
alertText.setAttribute("id","alert");
|
2019-03-17 19:05:31 +00:00
|
|
|
document.body.appendChild(alertText);
|
|
|
|
settings = {
|
2019-03-15 14:46:26 +00:00
|
|
|
"location": 2, "font_face": "Tahoma", "font_size": 40,
|
|
|
|
"font_color": "rgb(255, 255, 255)", "background_color": "rgb(102, 0, 0)",
|
2019-03-17 19:05:31 +00:00
|
|
|
"timeout": 0.01, "repeat": 1, "scroll": true
|
|
|
|
};
|
2019-03-15 14:46:26 +00:00
|
|
|
Display._transitionState = TransitionState.EntranceTransition;
|
2019-03-17 19:05:31 +00:00
|
|
|
});
|
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
it("should set the correct styles on the text", function() {
|
2019-03-17 19:05:31 +00:00
|
|
|
Display.showAlertText(settings);
|
2019-03-15 14:46:26 +00:00
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
expect(alertText.style.opacity).toEqual('1');
|
2019-03-17 19:05:31 +00:00
|
|
|
expect(alertText.style.color).toEqual("rgb(255, 255, 255)");
|
|
|
|
expect(alertText.style.fontFamily).toEqual("Tahoma");
|
|
|
|
expect(alertText.style.fontSize).toEqual("40pt");
|
2019-03-15 14:46:26 +00:00
|
|
|
});
|
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
it("should set the correct animation when text is set to scroll)", function () {
|
2019-03-17 19:05:31 +00:00
|
|
|
Display.showAlertText(settings);
|
2019-03-15 14:46:26 +00:00
|
|
|
|
2019-03-17 19:05:31 +00:00
|
|
|
expect(alertText.style.animation).toEqual("alert-scrolling-text " + settings.timeout + "s linear 0s 1 normal");
|
|
|
|
expect(Display._animationState).toEqual(AnimationState.ScrollingText);
|
|
|
|
});
|
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
it("should set the correct styles when text is not scrolling", function (done) {
|
2019-03-17 19:05:31 +00:00
|
|
|
settings.scroll = false;
|
2019-03-29 12:36:32 +00:00
|
|
|
Display._transitionState = TransitionState.EntranceTransition;
|
|
|
|
spyOn(Display, "hideAlertText");
|
2019-03-17 19:05:31 +00:00
|
|
|
Display.showAlertText(settings);
|
2019-03-15 14:46:26 +00:00
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
expect(alertText.style.opacity).toEqual('1');
|
2019-03-15 14:46:26 +00:00
|
|
|
expect(alertText.style.animation).toEqual("");
|
|
|
|
expect(Display._animationState).toEqual(AnimationState.NonScrollingText);
|
2019-03-17 19:05:31 +00:00
|
|
|
setTimeout (function () {
|
|
|
|
expect(alertText.className).toEqual("no-scroll");
|
2019-03-15 14:46:26 +00:00
|
|
|
expect(Display._animationState).toEqual(AnimationState.NoAnimation);
|
2019-03-29 12:36:32 +00:00
|
|
|
expect(Display.hideAlertText).toHaveBeenCalled();
|
2019-03-15 14:46:26 +00:00
|
|
|
done();
|
|
|
|
}, settings.timeout * 1000);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-29 12:36:32 +00:00
|
|
|
describe("Display.hideAlertText", function() {
|
|
|
|
var alertBackground, alertText, keyframeStyle;
|
|
|
|
beforeEach(function () {
|
2019-03-12 19:37:07 +00:00
|
|
|
document.body.innerHTML = "";
|
2019-03-29 12:36:32 +00:00
|
|
|
// keyframeStyle = document.createElement("style");
|
|
|
|
// keyframeStyle.setAttribute("id", "keyframeStyles");
|
|
|
|
// document.head.appendChild(keyframeStyle);
|
|
|
|
// alertBackground = document.createElement("div");
|
|
|
|
// alertBackground.setAttribute("id", "alert-background");
|
|
|
|
// document.body.appendChild(alertBackground);
|
|
|
|
alertText = document.createElement("p");
|
|
|
|
alertText.setAttribute("id", "alert");
|
|
|
|
alertText.style.opacity = 1;
|
|
|
|
alertText.style.animation = "alert-scrolling-text 5s linear 0s 1 bg-default";
|
|
|
|
document.body.appendChild(alertText);
|
|
|
|
Display._animationState = AnimationState.ScrollingText;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should reset the text styles and animation state after the text has scrolled", function() {
|
|
|
|
spyOn(Display, "resetAlertKeyframes");
|
|
|
|
spyOn(Display, "hideAlertBackground");
|
|
|
|
Display.hideAlertText();
|
|
|
|
|
|
|
|
expect(alertText.style.animation).toEqual("");
|
|
|
|
expect(alertText.style.opacity).toEqual('0');
|
|
|
|
expect(alertText.style.color).toEqual("rgb(255, 255, 255)");
|
|
|
|
expect(alertText.style.fontSize).toEqual("40pt");
|
|
|
|
expect(Display._animationState).toEqual(AnimationState.NoAnimation);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should call the hideAlertBackground and resetAlertKeyframes methods", function() {
|
|
|
|
spyOn(Display, "hideAlertBackground");
|
|
|
|
spyOn(Display, "resetAlertKeyframes");
|
|
|
|
Display.hideAlertText();
|
|
|
|
|
|
|
|
expect(Display.hideAlertBackground).toHaveBeenCalled();
|
|
|
|
expect(Display.resetAlertKeyframes).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.addAlertToQueue", function () {
|
|
|
|
it("should add an alert to the queue if one is displaying already", function() {
|
|
|
|
Display._alerts = [];
|
|
|
|
Display._alertState = AlertState.Displaying;
|
|
|
|
settings = '{ \
|
|
|
|
"location": 1, "font_face": "Segoe UI, Tahoma, Geneva, Verdana, sans-serif", \
|
|
|
|
"font_size": 40, "font_color": "#ffffff", "background_color": "#660000", \
|
|
|
|
"timeout": 5, "repeat": 1, "scrolling_text": true \
|
|
|
|
}';
|
|
|
|
var alertObject = {text: "Testing alert queue", settings: settings};
|
|
|
|
var queuedAlert = JSON.stringify(alertObject);
|
|
|
|
|
|
|
|
Display.addAlertToQueue("Testing alert queue", settings);
|
|
|
|
|
|
|
|
expect(Display._alerts.length).toEqual(1);
|
|
|
|
expect(Display._alerts[0]).toEqual(queuedAlert);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-02 19:08:27 +00:00
|
|
|
describe("Display.showNextAlert", function () {
|
|
|
|
Display.showNextAlert();
|
2019-03-29 12:36:32 +00:00
|
|
|
|
|
|
|
it("should return null if there are no alerts in the queue", function () {
|
|
|
|
Display._alerts = [];
|
2019-04-02 19:08:27 +00:00
|
|
|
Display.showNextAlert();
|
2019-03-29 12:36:32 +00:00
|
|
|
|
2019-04-02 19:08:27 +00:00
|
|
|
expect(Display.showNextAlert()).toBeNull();
|
2019-03-29 12:36:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should call the alert function correctly if there is an alert in the queue", function () {
|
|
|
|
var settings = {
|
|
|
|
"location": 2, "font_face": "Tahoma", "font_size": 40,
|
|
|
|
"font_color": "rgb(255, 255, 255)", "background_color": "rgb(102, 0, 0)",
|
|
|
|
"timeout": 5, "repeat": 1, "scrolling_text": true
|
|
|
|
};
|
|
|
|
var alertObject = {text: "Queued Alert", settings: settings};
|
|
|
|
Display._alerts.push(JSON.stringify(alertObject));
|
|
|
|
spyOn(Display, "alert");
|
2019-04-02 19:08:27 +00:00
|
|
|
Display.showNextAlert();
|
2019-03-29 12:36:32 +00:00
|
|
|
|
|
|
|
expect(Display.alert).toHaveBeenCalled();
|
|
|
|
expect(Display.alert).toHaveBeenCalledWith("Queued Alert",alertObject.settings);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.alertTransitionEndEvent", function() {
|
|
|
|
it("should set the correct state and call showAlertText after the alert entrance transition", function() {
|
|
|
|
var fake_settings = {test: "fake_settings"};
|
|
|
|
Display._alertSettings = fake_settings;
|
2019-03-29 14:18:54 +00:00
|
|
|
spyOn(Display, "showAlertText");
|
|
|
|
Display._transitionState = TransitionState.EntranceTransition;
|
|
|
|
Display.alertTransitionEndEvent();
|
2019-03-29 12:36:32 +00:00
|
|
|
|
|
|
|
expect(Display._transitionState).toEqual(TransitionState.NoTransition);
|
2019-03-29 14:18:54 +00:00
|
|
|
expect(Display.showAlertText).toHaveBeenCalledWith(fake_settings);
|
2019-03-12 19:37:07 +00:00
|
|
|
});
|
2019-03-15 14:46:26 +00:00
|
|
|
|
2019-04-02 19:08:27 +00:00
|
|
|
it("should set the correct state after the alert exit transition", function() {
|
|
|
|
spyOn(Display, "showNextAlert");
|
2019-03-29 14:18:54 +00:00
|
|
|
Display._transitionState = TransitionState.ExitTransition;
|
|
|
|
Display.alertTransitionEndEvent();
|
2019-03-17 19:05:31 +00:00
|
|
|
|
2019-04-02 19:08:27 +00:00
|
|
|
expect(Display._transitionState).toEqual(TransitionState.NoTransition);
|
2019-03-29 12:36:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.alertAnimationEndEvent", function () {
|
|
|
|
it("should call the hideAlertText method", function() {
|
2019-03-29 14:18:54 +00:00
|
|
|
spyOn(Display, "hideAlertText");
|
|
|
|
|
|
|
|
Display.alertAnimationEndEvent();
|
2019-03-29 12:36:32 +00:00
|
|
|
|
|
|
|
expect(Display.hideAlertText).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.setAlertKeyframes", function () {
|
|
|
|
var keyframeStyle;
|
|
|
|
beforeEach( function () {
|
|
|
|
document.head.innerHTML = "";
|
|
|
|
keyframeStyle = document.createElement("style");
|
|
|
|
keyframeStyle.setAttribute("id", "keyframeStyles");
|
|
|
|
document.head.appendChild(keyframeStyle);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should set the correct keyframes", function () {
|
|
|
|
var scrollWidth = 3200;
|
|
|
|
var scrollWidthPercentage = (Math.ceil((((scrollWidth / screen.width) * 100) + 1) / 10) * 10) + 110;
|
|
|
|
var keyframeHtml = "@keyframes alert-scrolling-text {" +
|
|
|
|
"from { transform: translateX(110%); } " +
|
|
|
|
"to { transform: translateX(-" + scrollWidthPercentage +"%);}";
|
|
|
|
|
|
|
|
expect(Display.setAlertKeyframes(scrollWidth)).toEqual(keyframeHtml);
|
|
|
|
expect(keyframeStyle.innerHTML).toEqual(keyframeHtml);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.resetAlertKeyframes", function () {
|
|
|
|
var keyframeStyle;
|
|
|
|
beforeEach( function () {
|
|
|
|
document.head.innerHTML = "";
|
|
|
|
keyframeStyle = document.createElement("style");
|
|
|
|
keyframeStyle.setAttribute("id", "keyframeStyles");
|
|
|
|
document.head.appendChild(keyframeStyle);
|
|
|
|
keyframeStyle.innerHTML = "@keyframes alert-scrolling-text {" +
|
|
|
|
"from { margin-left: 110%; } to { margin-left: -220;}";
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shoud reset the key frames after scrolling the text", function () {
|
|
|
|
Display.resetAlertKeyframes();
|
|
|
|
|
|
|
|
expect(keyframeStyle.innerHTML).toEqual("");
|
2019-03-15 14:46:26 +00:00
|
|
|
});
|
2019-03-12 19:37:07 +00:00
|
|
|
});
|
|
|
|
|
2017-10-04 07:44:08 +00:00
|
|
|
describe("Display.addTextSlide", function () {
|
|
|
|
beforeEach(function() {
|
|
|
|
document.body.innerHTML = "";
|
|
|
|
var slidesDiv = document.createElement("div");
|
|
|
|
slidesDiv.setAttribute("class", "slides");
|
|
|
|
document.body.appendChild(slidesDiv);
|
|
|
|
Display._slides = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should add a new slide", function () {
|
|
|
|
var verse = "v1", text = "Amazing grace,\nhow sweet the sound";
|
|
|
|
spyOn(Display, "reinit");
|
|
|
|
|
|
|
|
Display.addTextSlide(verse, text);
|
|
|
|
|
|
|
|
expect(Display._slides[verse]).toEqual(0);
|
|
|
|
expect($(".slides > section").length).toEqual(1);
|
|
|
|
expect($(".slides > section")[0].innerHTML).toEqual(_prepareText(text));
|
|
|
|
expect(Display.reinit).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should add a new slide without calling reinit()", function () {
|
|
|
|
var verse = "v1", text = "Amazing grace,\nhow sweet the sound";
|
|
|
|
spyOn(Display, "reinit");
|
|
|
|
|
|
|
|
Display.addTextSlide(verse, text, false);
|
|
|
|
|
|
|
|
expect(Display._slides[verse]).toEqual(0);
|
|
|
|
expect($(".slides > section").length).toEqual(1);
|
|
|
|
expect($(".slides > section")[0].innerHTML).toEqual(_prepareText(text));
|
|
|
|
expect(Display.reinit).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should update an existing slide", function () {
|
|
|
|
var verse = "v1", text = "Amazing grace, how sweet the sound\nThat saved a wretch like me";
|
|
|
|
Display.addTextSlide(verse, "Amazing grace,\nhow sweet the sound", false);
|
|
|
|
spyOn(Display, "reinit");
|
|
|
|
|
|
|
|
Display.addTextSlide(verse, text, true);
|
|
|
|
|
|
|
|
expect(Display._slides[verse]).toEqual(0);
|
|
|
|
expect($(".slides > section").length).toEqual(1);
|
|
|
|
expect($(".slides > section")[0].innerHTML).toEqual(_prepareText(text));
|
|
|
|
expect(Display.reinit).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.setTextSlides", function () {
|
|
|
|
beforeEach(function() {
|
|
|
|
document.body.innerHTML = "";
|
|
|
|
var slidesDiv = document.createElement("div");
|
|
|
|
slidesDiv.setAttribute("class", "slides");
|
|
|
|
document.body.appendChild(slidesDiv);
|
2018-01-21 13:08:24 +00:00
|
|
|
|
|
|
|
var background = document.createElement("div");
|
|
|
|
background.setAttribute("id", "global-background");
|
|
|
|
document.body.appendChild(background);
|
|
|
|
|
|
|
|
var footer = document.createElement("div");
|
|
|
|
footer.setAttribute("class", "footer");
|
|
|
|
document.body.appendChild(footer);
|
|
|
|
|
2017-10-04 07:44:08 +00:00
|
|
|
Display._slides = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should add a list of slides", function () {
|
|
|
|
var slides = [
|
|
|
|
{
|
|
|
|
"verse": "v1",
|
|
|
|
"text": "Amazing grace, how sweet the sound\nThat saved a wretch like me\n" +
|
|
|
|
"I once was lost, but now I'm found\nWas blind but now I see"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"verse": "v2",
|
|
|
|
"text": "'twas Grace that taught, my heart to fear\nAnd grace, my fears relieved.\n" +
|
|
|
|
"How precious did that grace appear,\nthe hour I first believed."
|
|
|
|
}
|
|
|
|
];
|
|
|
|
spyOn(Display, "clearSlides");
|
|
|
|
spyOn(Display, "reinit");
|
|
|
|
spyOn(Reveal, "slide");
|
|
|
|
|
|
|
|
Display.setTextSlides(slides);
|
|
|
|
|
|
|
|
expect(Display.clearSlides).toHaveBeenCalledTimes(1);
|
|
|
|
expect(Display._slides["v1"]).toEqual(0);
|
|
|
|
expect(Display._slides["v2"]).toEqual(1);
|
|
|
|
expect($(".slides > section").length).toEqual(2);
|
|
|
|
expect(Display.reinit).toHaveBeenCalledTimes(1);
|
|
|
|
expect(Reveal.slide).toHaveBeenCalledWith(0);
|
|
|
|
});
|
2018-01-21 13:08:24 +00:00
|
|
|
|
|
|
|
it("should correctly set outline width", function () {
|
|
|
|
const slides = [
|
|
|
|
{
|
|
|
|
"verse": "v1",
|
|
|
|
"text": "Amazing grace, how sweet the sound\nThat saved a wretch like me\n" +
|
|
|
|
"I once was lost, but now I'm found\nWas blind but now I see"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const theme = {
|
|
|
|
'font_main_color': 'yellow',
|
|
|
|
'font_main_outline': true,
|
|
|
|
'font_main_outline_size': 42,
|
|
|
|
'font_main_outline_color': 'red'
|
|
|
|
};
|
|
|
|
|
|
|
|
spyOn(Display, "reinit");
|
2019-03-06 10:05:28 +00:00
|
|
|
spyOn(Reveal, "slide");
|
2018-01-21 13:08:24 +00:00
|
|
|
|
|
|
|
Display.setTextSlides(slides);
|
|
|
|
Display.setTheme(theme);
|
|
|
|
|
|
|
|
const slidesDiv = $(".slides")[0];
|
|
|
|
|
|
|
|
expect(slidesDiv.style['-webkit-text-stroke']).toEqual('42pt red');
|
|
|
|
expect(slidesDiv.style['padding-left']).toEqual('84pt');
|
|
|
|
expect(slidesDiv.style['-webkit-text-fill-color']).toEqual('yellow');
|
|
|
|
})
|
2017-10-04 07:44:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.setImageSlides", function () {
|
|
|
|
beforeEach(function() {
|
|
|
|
document.body.innerHTML = "";
|
|
|
|
var slidesDiv = document.createElement("div");
|
|
|
|
slidesDiv.setAttribute("class", "slides");
|
|
|
|
document.body.appendChild(slidesDiv);
|
|
|
|
var backgroundDiv = document.createElement("div");
|
|
|
|
backgroundDiv.setAttribute("id", "global-background");
|
|
|
|
document.body.appendChild(backgroundDiv);
|
|
|
|
Display._slides = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should add a list of images", function () {
|
2019-01-16 06:15:21 +00:00
|
|
|
var slides = [{"path": "file:///openlp1.jpg"}, {"path": "file:///openlp2.jpg"}];
|
2017-10-04 07:44:08 +00:00
|
|
|
spyOn(Display, "clearSlides");
|
|
|
|
spyOn(Display, "reinit");
|
|
|
|
|
|
|
|
Display.setImageSlides(slides);
|
|
|
|
|
|
|
|
expect(Display.clearSlides).toHaveBeenCalledTimes(1);
|
|
|
|
expect(Display._slides["0"]).toEqual(0);
|
|
|
|
expect(Display._slides["1"]).toEqual(1);
|
|
|
|
expect($(".slides > section").length).toEqual(2);
|
|
|
|
expect($(".slides > section > img").length).toEqual(2);
|
2019-01-16 06:15:21 +00:00
|
|
|
expect($(".slides > section > img")[0].getAttribute("src")).toEqual("file:///openlp1.jpg")
|
|
|
|
expect($(".slides > section > img")[1].getAttribute("src")).toEqual("file:///openlp2.jpg")
|
2017-10-04 07:44:08 +00:00
|
|
|
expect(Display.reinit).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.setVideo", function () {
|
|
|
|
beforeEach(function() {
|
|
|
|
document.body.innerHTML = "";
|
|
|
|
var slidesDiv = document.createElement("div");
|
|
|
|
slidesDiv.setAttribute("class", "slides");
|
|
|
|
document.body.appendChild(slidesDiv);
|
|
|
|
var backgroundDiv = document.createElement("div");
|
|
|
|
backgroundDiv.setAttribute("id", "global-background");
|
|
|
|
document.body.appendChild(backgroundDiv);
|
|
|
|
Display._slides = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should add a video to the page", function () {
|
2019-01-16 06:15:21 +00:00
|
|
|
var video = {"path": "file:///video.mp4"};
|
2017-10-04 07:44:08 +00:00
|
|
|
spyOn(Display, "clearSlides");
|
|
|
|
spyOn(Display, "reinit");
|
|
|
|
|
|
|
|
Display.setVideo(video);
|
|
|
|
|
|
|
|
expect(Display.clearSlides).toHaveBeenCalledTimes(1);
|
|
|
|
expect($(".slides > section").length).toEqual(1);
|
|
|
|
expect($(".slides > section > video").length).toEqual(1);
|
2019-01-16 06:15:21 +00:00
|
|
|
expect($(".slides > section > video")[0].src).toEqual("file:///video.mp4")
|
2017-10-04 07:44:08 +00:00
|
|
|
expect(Display.reinit).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.playVideo", function () {
|
|
|
|
var playCalled = false,
|
|
|
|
mockVideo = {
|
|
|
|
play: function () {
|
|
|
|
playCalled = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
spyOn(window, "$").and.returnValue([mockVideo]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should play the video when called", function () {
|
|
|
|
Display.playVideo();
|
|
|
|
expect(playCalled).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.pauseVideo", function () {
|
|
|
|
var pauseCalled = false,
|
|
|
|
mockVideo = {
|
|
|
|
pause: function () {
|
|
|
|
pauseCalled = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
spyOn(window, "$").and.returnValue([mockVideo]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should pause the video when called", function () {
|
|
|
|
Display.pauseVideo();
|
|
|
|
expect(pauseCalled).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.stopVideo", function () {
|
|
|
|
var pauseCalled = false,
|
|
|
|
mockVideo = {
|
|
|
|
pause: function () {
|
|
|
|
pauseCalled = true;
|
|
|
|
},
|
|
|
|
currentTime: 10.0
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
spyOn(window, "$").and.returnValue([mockVideo]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should play the video when called", function () {
|
|
|
|
Display.stopVideo();
|
|
|
|
expect(pauseCalled).toEqual(true);
|
|
|
|
expect(mockVideo.currentTime).toEqual(0.0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.seekVideo", function () {
|
|
|
|
var mockVideo = {
|
|
|
|
currentTime: 1.0
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
spyOn(window, "$").and.returnValue([mockVideo]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should seek to the specified position within the video when called", function () {
|
|
|
|
Display.seekVideo(7.34);
|
|
|
|
expect(mockVideo.currentTime).toEqual(7.34);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.setPlaybackRate", function () {
|
|
|
|
var mockVideo = {
|
|
|
|
playbackRate: 1.0
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
spyOn(window, "$").and.returnValue([mockVideo]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should set the playback rate of the video when called", function () {
|
|
|
|
// Let's sound like chipmunks!
|
|
|
|
Display.setPlaybackRate(1.25);
|
|
|
|
expect(mockVideo.playbackRate).toEqual(1.25);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.setVideoVolume", function () {
|
|
|
|
var mockVideo = {
|
|
|
|
volume: 1.0
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
spyOn(window, "$").and.returnValue([mockVideo]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should set the correct volume of the video when called", function () {
|
|
|
|
// Make it quiet
|
|
|
|
Display.setVideoVolume(30);
|
|
|
|
expect(mockVideo.volume).toEqual(0.3);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Display.toggleVideoMute", function () {
|
|
|
|
var mockVideo = {
|
|
|
|
muted: false
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
spyOn(window, "$").and.returnValue([mockVideo]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should mute the video when called", function () {
|
|
|
|
mockVideo.muted = false;
|
|
|
|
Display.toggleVideoMute();
|
|
|
|
expect(mockVideo.muted).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should unmute the video when called", function () {
|
|
|
|
mockVideo.muted = true;
|
|
|
|
Display.toggleVideoMute();
|
|
|
|
expect(mockVideo.muted).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("AudioPlayer", function () {
|
|
|
|
var audioPlayer, audioElement;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
audioElement = {
|
|
|
|
_eventListeners: {},
|
|
|
|
_playing: false,
|
|
|
|
_paused: false,
|
|
|
|
_stopped: false,
|
|
|
|
src: "",
|
|
|
|
addEventListener: function (eventType, listener) {
|
|
|
|
this._eventListeners[eventType] = this._eventListeners[eventType] || [];
|
|
|
|
this._eventListeners[eventType].push(listener);
|
|
|
|
},
|
|
|
|
play: function () {
|
|
|
|
this._playing = true;
|
|
|
|
this._paused = false;
|
|
|
|
this._stopped = false;
|
|
|
|
},
|
|
|
|
pause: function () {
|
|
|
|
this._playing = false;
|
|
|
|
this._paused = true;
|
|
|
|
this._stopped = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
spyOn(document, "createElement").and.returnValue(audioElement);
|
|
|
|
audioPlayer = new AudioPlayer();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create an object", function () {
|
|
|
|
expect(audioPlayer).toBeDefined();
|
|
|
|
expect(audioPlayer._audioElement).not.toBeNull();
|
|
|
|
expect(audioPlayer._eventListeners).toEqual({});
|
|
|
|
expect(audioPlayer._playlist).toEqual([]);
|
|
|
|
expect(audioPlayer._currentTrack).toEqual(null);
|
|
|
|
expect(audioPlayer._canRepeat).toEqual(false);
|
|
|
|
expect(audioPlayer._state).toEqual(AudioState.Stopped);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should call the correct method when _callListener is called", function () {
|
|
|
|
var testCalled = false;
|
|
|
|
function test(event) {
|
|
|
|
testCalled = true;
|
|
|
|
}
|
|
|
|
audioPlayer._eventListeners["test"] = [test];
|
|
|
|
audioPlayer._callListener({"type": "test"});
|
|
|
|
expect(testCalled).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should log a warning when _callListener is called for an unknown event", function () {
|
|
|
|
spyOn(console, "warn");
|
|
|
|
audioPlayer._callListener({"type": "test"});
|
|
|
|
expect(console.warn).toHaveBeenCalledWith("Received unknown event \"test\", doing nothing.");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should add all the correct event listeners", function () {
|
|
|
|
expectedListeners = {
|
|
|
|
"ended": [audioPlayer.onEnded, audioPlayer._callListener],
|
|
|
|
"timeupdate": [audioPlayer._callListener],
|
|
|
|
"volumechange": [audioPlayer._callListener],
|
|
|
|
"durationchange": [audioPlayer._callListener],
|
|
|
|
"loadeddata": [audioPlayer._callListener]
|
|
|
|
};
|
|
|
|
expect(audioElement._eventListeners).toEqual(expectedListeners);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should add the correct event listener when calling addEventListener", function () {
|
|
|
|
function dummy () {};
|
|
|
|
var expectedListeners = {
|
|
|
|
"test": [dummy]
|
|
|
|
};
|
|
|
|
audioPlayer.addEventListener("test", dummy);
|
|
|
|
expect(audioPlayer._eventListeners).toEqual(expectedListeners);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should set call nextTrack when the onEnded listener is called", function () {
|
|
|
|
spyOn(audioPlayer, "nextTrack");
|
|
|
|
audioPlayer.onEnded({});
|
|
|
|
expect(audioPlayer.nextTrack).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should set the _canRepeat property when calling setCanRepeat", function () {
|
|
|
|
audioPlayer.setCanRepeat(true);
|
|
|
|
expect(audioPlayer._canRepeat).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should clear the playlist when clearTracks is called", function () {
|
|
|
|
audioPlayer._playlist = ["one", "two", "three"];
|
|
|
|
audioPlayer.clearTracks();
|
|
|
|
expect(audioPlayer._playlist).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should add a track to the playlist when addTrack is called", function () {
|
|
|
|
audioPlayer._playlist = [];
|
|
|
|
audioPlayer.addTrack("one");
|
|
|
|
expect(audioPlayer._playlist).toEqual(["one"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should move to the first track when canRepeat is true and nextTrack is called", function () {
|
|
|
|
spyOn(audioPlayer, "play");
|
|
|
|
audioPlayer.addTrack("one");
|
|
|
|
audioPlayer.addTrack("two");
|
|
|
|
audioPlayer.setCanRepeat(true);
|
|
|
|
audioPlayer._currentTrack = "two";
|
|
|
|
|
|
|
|
audioPlayer.nextTrack();
|
|
|
|
|
|
|
|
expect(audioPlayer.play).toHaveBeenCalledWith("one");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should move to the next track when nextTrack is called", function () {
|
|
|
|
spyOn(audioPlayer, "play");
|
|
|
|
audioPlayer.addTrack("one");
|
|
|
|
audioPlayer.addTrack("two");
|
|
|
|
audioPlayer._currentTrack = "one";
|
|
|
|
|
|
|
|
audioPlayer.nextTrack();
|
|
|
|
|
|
|
|
expect(audioPlayer.play).toHaveBeenCalledWith("two");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should stop when canRepeat is false and nextTrack is called on the last track in the list", function () {
|
|
|
|
spyOn(audioPlayer, "play");
|
|
|
|
spyOn(audioPlayer, "stop");
|
|
|
|
audioPlayer.addTrack("one");
|
|
|
|
audioPlayer.addTrack("two");
|
|
|
|
audioPlayer.setCanRepeat(false);
|
|
|
|
audioPlayer._currentTrack = "two";
|
|
|
|
|
|
|
|
audioPlayer.nextTrack();
|
|
|
|
|
|
|
|
expect(audioPlayer.play).not.toHaveBeenCalled();
|
|
|
|
expect(audioPlayer.stop).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should play the first track when nextTrack is called when no songs are playing", function () {
|
|
|
|
spyOn(audioPlayer, "play");
|
|
|
|
audioPlayer.addTrack("one");
|
|
|
|
audioPlayer.nextTrack();
|
|
|
|
expect(audioPlayer.play).toHaveBeenCalledWith("one");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should log a warning when nextTrack is called when no songs are in the playlist", function () {
|
|
|
|
spyOn(console, "warn");
|
|
|
|
audioPlayer.nextTrack();
|
|
|
|
expect(console.warn).toHaveBeenCalledWith("No tracks in playlist, doing nothing.");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should play the track specified when play is called with a filename", function () {
|
|
|
|
audioPlayer.addTrack("one");
|
|
|
|
audioPlayer.play("one");
|
|
|
|
|
|
|
|
expect(audioPlayer._currentTrack).toEqual("one");
|
|
|
|
expect(audioElement._playing).toEqual(true);
|
|
|
|
expect(audioElement.src).toEqual("one");
|
|
|
|
expect(audioPlayer._state).toEqual(AudioState.Playing);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should continue playing when play is called without a filename and the player is paused", function () {
|
|
|
|
audioPlayer._state = AudioState.Paused;
|
|
|
|
audioPlayer.play();
|
|
|
|
|
|
|
|
expect(audioElement._playing).toEqual(true);
|
|
|
|
expect(audioPlayer._state).toEqual(AudioState.Playing);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should do nothing when play is called without a filename and the player is not paused", function () {
|
|
|
|
spyOn(console, "warn");
|
|
|
|
audioPlayer._state = AudioState.Playing;
|
|
|
|
audioPlayer.play();
|
|
|
|
|
|
|
|
expect(console.warn).toHaveBeenCalledWith("No track currently paused and no track specified, doing nothing.");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should pause the current track when pause is called", function () {
|
|
|
|
audioPlayer.pause();
|
|
|
|
expect(audioPlayer._state).toEqual(AudioState.Paused);
|
|
|
|
expect(audioElement._paused).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should stop the current track when stop is called", function () {
|
|
|
|
audioPlayer.stop();
|
|
|
|
expect(audioPlayer._state).toEqual(AudioState.Stopped);
|
|
|
|
expect(audioElement._paused).toEqual(true);
|
|
|
|
expect(audioElement.src).toEqual("");
|
|
|
|
});
|
|
|
|
});
|