-
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
6bc1c77
commit 06680d3
Showing
15 changed files
with
147 additions
and
355 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
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,92 @@ | ||
import { getMockTour } from "./tests/mock"; | ||
|
||
describe("exitIntro", () => { | ||
test("should reset the _currentStep", async () => { | ||
const mockTour = getMockTour(); | ||
mockTour.addStep({ element: document.querySelector("h1") }); | ||
await mockTour.render(); | ||
|
||
await mockTour.exit(false); | ||
|
||
expect(mockTour.getCurrentStep()).toBe(-1); | ||
}); | ||
|
||
test("should call the onexit and onbeforeexit callbacks", async () => { | ||
const fnOnExit = jest.fn(); | ||
const fnOnBeforeExit = jest.fn(); | ||
fnOnBeforeExit.mockReturnValue(true); | ||
|
||
const mockTour = getMockTour(); | ||
mockTour.addStep({ element: document.querySelector("h1") }); | ||
mockTour.onExit(fnOnExit) | ||
mockTour.onBeforeExit(fnOnBeforeExit); | ||
|
||
await mockTour.render(); | ||
await mockTour.exit(false); | ||
|
||
expect(fnOnExit).toBeCalledTimes(1); | ||
|
||
expect(fnOnBeforeExit).toBeCalledTimes(1); | ||
expect(fnOnBeforeExit).toHaveBeenCalledWith(document.body); | ||
expect(fnOnBeforeExit).toHaveBeenCalledBefore(fnOnExit); | ||
}); | ||
|
||
test("should not continue when onbeforeexit returns false", async () => { | ||
const fnOnExit = jest.fn(); | ||
const fnOnBeforeExit = jest.fn(); | ||
fnOnBeforeExit.mockReturnValue(false); | ||
|
||
const mockTour = getMockTour(); | ||
mockTour.addStep({ element: document.querySelector("h1") }); | ||
mockTour.onExit(fnOnExit) | ||
mockTour.onBeforeExit(fnOnBeforeExit); | ||
|
||
await mockTour.render(); | ||
await mockTour.exit(false); | ||
|
||
expect(fnOnExit).toBeCalledTimes(0); | ||
|
||
expect(fnOnBeforeExit).toBeCalledTimes(1); | ||
expect(fnOnBeforeExit).toHaveBeenCalledWith(document.body); | ||
|
||
// test cleanup | ||
document.body.innerHTML = ''; | ||
}); | ||
|
||
test("should not continue when exit force is true", async () => { | ||
const fnOnExit = jest.fn(); | ||
const fnOnBeforeExit = jest.fn(); | ||
fnOnBeforeExit.mockReturnValue(false); | ||
|
||
const mockTour = getMockTour(); | ||
mockTour.addStep({ element: document.querySelector("h1") }); | ||
mockTour.onExit(fnOnExit) | ||
mockTour.onBeforeExit(fnOnBeforeExit); | ||
|
||
await mockTour.render(); | ||
await mockTour.exit(false); | ||
|
||
expect(fnOnExit).toBeCalledTimes(0); | ||
expect(fnOnBeforeExit).toBeCalledTimes(1); | ||
|
||
// test cleanup | ||
document.body.innerHTML = ''; | ||
}); | ||
|
||
test("should continue when exit force is true and beforeExit callback returns false", async () => { | ||
const fnOnExit = jest.fn(); | ||
const fnOnBeforeExit = jest.fn(); | ||
fnOnBeforeExit.mockReturnValue(false); | ||
|
||
const mockTour = getMockTour(); | ||
mockTour.addStep({ element: document.querySelector("h1") }); | ||
mockTour.onExit(fnOnExit) | ||
mockTour.onBeforeExit(fnOnBeforeExit); | ||
|
||
await mockTour.render(); | ||
await mockTour.exit(true); | ||
|
||
expect(fnOnExit).toBeCalledTimes(1); | ||
expect(fnOnBeforeExit).toBeCalledTimes(1); | ||
}); | ||
}); |
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.