-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6f5871
commit 56436f4
Showing
21 changed files
with
342 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { setOption, setOptions } from "./option"; | ||
|
||
describe("option", () => { | ||
describe("setOption", () => { | ||
it("should set option", () => { | ||
// Arrange | ||
const mockOption = { | ||
key1: "value1", | ||
}; | ||
|
||
// Act | ||
setOption(mockOption, "key1", "newValue1"); | ||
|
||
// Assert | ||
expect(mockOption.key1).toBe("newValue1"); | ||
}); | ||
}); | ||
|
||
describe("setOptions", () => { | ||
it("should set options", () => { | ||
// Arrange | ||
const mockOption = { | ||
key1: "value1", | ||
key2: "value2", | ||
}; | ||
|
||
// Act | ||
setOptions(mockOption, { key2: "newValue2", key1: "newValue1" }); | ||
|
||
// Assert | ||
expect(mockOption.key1).toBe("newValue1"); | ||
expect(mockOption.key2).toBe("newValue2"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { TooltipPosition } from "./tooltipPosition"; | ||
export { placeTooltip } from "./placeTooltip"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
import * as getOffset from "../../util/getOffset"; | ||
import * as getWindowSize from "../../util/getWindowSize"; | ||
import { placeTooltip } from "./placeTooltip"; | ||
|
||
describe("placeTooltip", () => { | ||
test("should automatically place the tooltip position when there is enough space", () => { | ||
// Arrange | ||
jest.spyOn(getOffset, "default").mockReturnValue({ | ||
height: 100, | ||
width: 100, | ||
top: 0, | ||
left: 0, | ||
}); | ||
|
||
jest.spyOn(getWindowSize, "default").mockReturnValue({ | ||
height: 1000, | ||
width: 1000, | ||
}); | ||
|
||
jest.spyOn(Element.prototype, "getBoundingClientRect").mockReturnValue({ | ||
x: 0, | ||
y: 0, | ||
toJSON: jest.fn, | ||
width: 100, | ||
height: 100, | ||
top: 200, | ||
left: 200, | ||
bottom: 300, | ||
right: 300, | ||
}); | ||
|
||
const stepElement = document.createElement("div"); | ||
const tooltipLayer = document.createElement("div"); | ||
const arrowLayer = document.createElement("div"); | ||
|
||
// Act | ||
placeTooltip( | ||
tooltipLayer, | ||
arrowLayer, | ||
stepElement, | ||
"top", | ||
["top", "bottom", "left", "right"], | ||
false, | ||
true | ||
); | ||
|
||
// Assert | ||
expect(tooltipLayer.className).toBe( | ||
"introjs-tooltip introjs-top-right-aligned" | ||
); | ||
}); | ||
|
||
test("should skip auto positioning when autoPosition is false", () => { | ||
// Arrange | ||
const stepElement = document.createElement("div"); | ||
const tooltipLayer = document.createElement("div"); | ||
const arrowLayer = document.createElement("div"); | ||
|
||
// Act | ||
placeTooltip( | ||
tooltipLayer, | ||
arrowLayer, | ||
stepElement, | ||
"top", | ||
["top", "bottom"], | ||
false, | ||
false | ||
); | ||
|
||
// Assert | ||
expect(tooltipLayer.className).toBe("introjs-tooltip introjs-top"); | ||
}); | ||
|
||
test("should use floating tooltips when height/width is limited", () => { | ||
// Arrange | ||
jest.spyOn(getOffset, "default").mockReturnValue({ | ||
height: 100, | ||
width: 100, | ||
top: 0, | ||
left: 0, | ||
}); | ||
|
||
jest.spyOn(getWindowSize, "default").mockReturnValue({ | ||
height: 100, | ||
width: 100, | ||
}); | ||
|
||
jest.spyOn(Element.prototype, "getBoundingClientRect").mockReturnValue({ | ||
x: 0, | ||
y: 0, | ||
toJSON: jest.fn, | ||
width: 100, | ||
height: 100, | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
}); | ||
|
||
const stepElement = document.createElement("div"); | ||
const tooltipLayer = document.createElement("div"); | ||
const arrowLayer = document.createElement("div"); | ||
|
||
// Act | ||
placeTooltip( | ||
tooltipLayer, | ||
arrowLayer, | ||
stepElement, | ||
"left", | ||
["top", "bottom", "left", "right"], | ||
false, | ||
true | ||
); | ||
|
||
// Assert | ||
expect(tooltipLayer.className).toBe("introjs-tooltip introjs-floating"); | ||
}); | ||
|
||
test("should use bottom middle aligned when there is enough vertical space", () => { | ||
// Arrange | ||
jest.spyOn(getOffset, "default").mockReturnValue({ | ||
height: 100, | ||
width: 100, | ||
top: 0, | ||
left: 0, | ||
}); | ||
|
||
jest.spyOn(getWindowSize, "default").mockReturnValue({ | ||
height: 500, | ||
width: 100, | ||
}); | ||
|
||
jest.spyOn(Element.prototype, "getBoundingClientRect").mockReturnValue({ | ||
x: 0, | ||
y: 0, | ||
toJSON: jest.fn, | ||
width: 100, | ||
height: 100, | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
}); | ||
|
||
const stepElement = document.createElement("div"); | ||
const tooltipLayer = document.createElement("div"); | ||
const arrowLayer = document.createElement("div"); | ||
|
||
// Act | ||
placeTooltip( | ||
tooltipLayer, | ||
arrowLayer, | ||
stepElement, | ||
"left", | ||
["top", "bottom", "left", "right"], | ||
false, | ||
true | ||
); | ||
|
||
// Assert | ||
expect(tooltipLayer.className).toBe( | ||
"introjs-tooltip introjs-bottom-middle-aligned" | ||
); | ||
}); | ||
|
||
test("should attach the global custom tooltip css class", () => { | ||
// Arrange | ||
const stepElement = document.createElement("div"); | ||
const tooltipLayer = document.createElement("div"); | ||
const arrowLayer = document.createElement("div"); | ||
|
||
// Act | ||
placeTooltip( | ||
tooltipLayer, | ||
arrowLayer, | ||
stepElement, | ||
"left", | ||
["top", "bottom", "left", "right"], | ||
false, | ||
true, | ||
"newClass" | ||
); | ||
|
||
// Assert | ||
expect(tooltipLayer.className).toBe( | ||
"introjs-tooltip newClass introjs-bottom-middle-aligned" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type TooltipPosition = | ||
| "floating" | ||
| "top" | ||
| "bottom" | ||
| "left" | ||
| "right" | ||
| "top-right-aligned" | ||
| "top-left-aligned" | ||
| "top-middle-aligned" | ||
| "bottom-right-aligned" | ||
| "bottom-left-aligned" | ||
| "bottom-middle-aligned"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.