Skip to content

Commit

Permalink
Merge pull request #1960 from usablica/improvetests
Browse files Browse the repository at this point in the history
Improving unit test coverage
  • Loading branch information
binrysearch authored Aug 13, 2023
2 parents 9b31d69 + 1b1461a commit a4b6a12
Show file tree
Hide file tree
Showing 37 changed files with 930 additions and 372 deletions.
4 changes: 4 additions & 0 deletions src/core/DOMEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class DOMEvent {
obj.attachEvent(`on${type}`, handler);
}

// @ts-ignore
obj[this.events_key] = obj[this.events_key] || {};
// @ts-ignore
obj[this.events_key][id] = handler;
}

Expand All @@ -61,6 +63,7 @@ class DOMEvent {
useCapture: boolean
) {
const id = this._id(type, listener, context);
// @ts-ignore
const handler = obj[this.events_key] && obj[this.events_key][id];

if (!handler) {
Expand All @@ -74,6 +77,7 @@ class DOMEvent {
obj.detachEvent(`on${type}`, handler);
}

// @ts-ignore
obj[this.events_key][id] = null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/dontShowAgain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export function setDontShowAgain(intro: IntroJs, dontShowAgain: boolean) {
*/
export function getDontShowAgain(intro: IntroJs): boolean {
const dontShowCookie = getCookie(intro._options.dontShowAgainCookie);
return dontShowCookie && dontShowCookie === dontShowAgainCookieValue;
return dontShowCookie !== "" && dontShowCookie === dontShowAgainCookieValue;
}
14 changes: 9 additions & 5 deletions src/core/exitIntro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import onResize from "./onResize";
import removeShowElement from "./removeShowElement";
import removeChild from "../util/removeChild";
import { IntroJs } from "src/intro";
import isFunction from "../util/isFunction";

/**
* Exit from intro
Expand All @@ -22,7 +23,10 @@ export default async function exitIntro(
//
// If this callback return `false`, it would halt the process
if (intro._introBeforeExitCallback !== undefined) {
continueExit = await intro._introBeforeExitCallback(targetElement);
continueExit = await intro._introBeforeExitCallback.call(
intro,
targetElement
);
}

// skip this check if `force` parameter is `true`
Expand Down Expand Up @@ -70,10 +74,10 @@ export default async function exitIntro(
DOMEvent.off(window, "resize", onResize, intro, true);

//check if any callback is defined
if (intro._introExitCallback !== undefined) {
await intro._introExitCallback();
if (isFunction(intro._introExitCallback)) {
await intro._introExitCallback.call(intro);
}

//set the step to zero
intro._currentStep = undefined;
// set the step to default
intro._currentStep = -1;
}
38 changes: 20 additions & 18 deletions src/core/fetchIntroSteps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IntroJs } from "src/intro";
import cloneObject from "../util/cloneObject";
import createElement from "../util/createElement";
import { ScrollTo, Step, TooltipPosition } from "./steps";
import { IntroStep, ScrollTo, TooltipPosition } from "./steps";

/**
* Finds all Intro steps from the data-* attributes and the options.steps array
Expand All @@ -15,12 +15,12 @@ export default function fetchIntroSteps(
const allIntroSteps: HTMLElement[] = Array.from(
targetElm.querySelectorAll("*[data-intro]")
);
let introItems: Step[] = [];
let introItems: IntroStep[] = [];

if (intro._options.steps) {
if (intro._options.steps && intro._options.steps.length) {
//use steps passed programmatically
for (const step of intro._options.steps) {
const currentItem: Step = cloneObject(step);
const currentItem = cloneObject(step);

//set the step
currentItem.step = introItems.length + 1;
Expand All @@ -30,9 +30,8 @@ export default function fetchIntroSteps(
//use querySelector function only when developer used CSS selector
if (typeof currentItem.element === "string") {
//grab the element with given selector from the page
currentItem.element = document.querySelector<HTMLElement>(
currentItem.element
);
currentItem.element =
document.querySelector<HTMLElement>(currentItem.element) || undefined;
}

//intro without element
Expand Down Expand Up @@ -66,7 +65,7 @@ export default function fetchIntroSteps(
}

if (currentItem.element !== null) {
introItems.push(currentItem);
introItems.push(currentItem as IntroStep);
}
}
} else {
Expand All @@ -93,24 +92,25 @@ export default function fetchIntroSteps(
continue;
}

const step = parseInt(currentElement.getAttribute("data-step"), 10);
const step = parseInt(currentElement.getAttribute("data-step") || "", 10);

disableInteraction = intro._options.disableInteraction;
if (currentElement.hasAttribute("data-disable-interaction")) {
disableInteraction = !!currentElement.getAttribute(
"data-disable-interaction"
);
} else {
disableInteraction = intro._options.disableInteraction;
}

if (step > 0) {
introItems[step - 1] = {
step: step,
element: currentElement,
title: currentElement.getAttribute("data-title") || "",
intro: currentElement.getAttribute("data-intro"),
step: parseInt(currentElement.getAttribute("data-step"), 10),
tooltipClass: currentElement.getAttribute("data-tooltip-class"),
highlightClass: currentElement.getAttribute("data-highlight-class"),
intro: currentElement.getAttribute("data-intro") || "",
tooltipClass:
currentElement.getAttribute("data-tooltip-class") || undefined,
highlightClass:
currentElement.getAttribute("data-highlight-class") || undefined,
position: (currentElement.getAttribute("data-position") ||
intro._options.tooltipPosition) as TooltipPosition,
scrollTo:
Expand Down Expand Up @@ -154,10 +154,12 @@ export default function fetchIntroSteps(
introItems[nextStep] = {
element: currentElement,
title: currentElement.getAttribute("data-title") || "",
intro: currentElement.getAttribute("data-intro"),
intro: currentElement.getAttribute("data-intro") || "",
step: nextStep + 1,
tooltipClass: currentElement.getAttribute("data-tooltip-class"),
highlightClass: currentElement.getAttribute("data-highlight-class"),
tooltipClass:
currentElement.getAttribute("data-tooltip-class") || undefined,
highlightClass:
currentElement.getAttribute("data-highlight-class") || undefined,
position: (currentElement.getAttribute("data-position") ||
intro._options.tooltipPosition) as TooltipPosition,
scrollTo:
Expand Down
Loading

1 comment on commit a4b6a12

@vercel
Copy link

@vercel vercel bot commented on a4b6a12 Aug 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

intro-js – ./

intro-js-tinyapp.vercel.app
intro-js-git-master-tinyapp.vercel.app
intro-js-alpha.vercel.app

Please sign in to comment.