|
1 | | -"use strict"; |
2 | | -var nsAppium = require("nativescript-dev-appium"); |
| 1 | +import { AppiumDriver, createDriver } from "nativescript-dev-appium"; |
| 2 | +import { assert } from "chai"; |
| 3 | +import { initialDisplayName } from "./const"; |
3 | 4 |
|
4 | | -describe("lazy load routing", function () { |
5 | | - this.timeout(360000); |
6 | | - var driver; |
| 5 | +describe("lazy load routing", async function () { |
| 6 | + let driver: AppiumDriver; |
| 7 | + const imagesResults = new Map<string, boolean>(); |
| 8 | + const lazyLoadedDisplay = "lazyLoadedDisplay"; |
7 | 9 |
|
8 | | - before(function () { |
9 | | - driver = nsAppium.createDriver(); |
| 10 | + before(async () => { |
| 11 | + driver = await createDriver(); |
| 12 | + await driver.resetApp(); |
10 | 13 | }); |
11 | 14 |
|
12 | | - after(function () { |
13 | | - return driver |
14 | | - .quit() |
15 | | - .finally(function () { |
16 | | - console.log("Driver quit successfully"); |
17 | | - }); |
| 15 | + afterEach("clear image results", () => { |
| 16 | + imagesResults.clear(); |
18 | 17 | }); |
19 | 18 |
|
20 | | - it("loads default path", function () { |
21 | | - return driver |
22 | | - .waitForElementByAccessibilityId("first-lazy-load", 300000) |
23 | | - .elementByAccessibilityId("first-lazy-load") |
24 | | - .should.eventually.exist |
25 | | - .text().should.eventually.equal("First: lazy-load") |
| 19 | + const loadFirstLazyLoadPage = async () => { |
| 20 | + await (await driver.findElementByAccessibilityId("first-navigate-lazy-load")).tap(); |
| 21 | + } |
| 22 | + |
| 23 | + it("loads default path", async () => { |
| 24 | + const initDisplay = await driver.compareScreen(initialDisplayName, 1, 0.01); |
| 25 | + assert.isTrue(initDisplay); |
26 | 26 | }); |
27 | 27 |
|
28 | | - it("navigates and returns", function () { |
29 | | - var expectedHookLog = [ |
30 | | - "first.init", // <-- load |
31 | | - "second.init", // <-- forward (first component is not destroyed) |
32 | | - "second.destroy"] // <-- back (first component is reused) |
33 | | - .join(","); |
34 | | - return driver |
35 | | - .waitForElementByAccessibilityId("first-navigate-lazy-load", 300000) |
36 | | - .elementByAccessibilityId("first-navigate-lazy-load") |
37 | | - .should.eventually.exist |
38 | | - .tap() |
39 | | - .elementByAccessibilityId("second-lazy-load") |
40 | | - .should.eventually.exist |
41 | | - .text().should.eventually.equal("Second: lazy-load") |
42 | | - .elementByAccessibilityId("router-location-strategy-states-lazy-load") |
43 | | - .text().should.eventually.equal("/first/lazy-load,/second/lazy-load") |
44 | | - .elementByAccessibilityId("second-navigate-back-lazy-load") |
45 | | - .should.eventually.exist |
46 | | - .tap() |
47 | | - .elementByAccessibilityId("first-lazy-load") |
48 | | - .should.eventually.exist |
49 | | - .text().should.eventually.equal("First: lazy-load") |
50 | | - .elementByAccessibilityId("hooks-log-lazy-load") |
51 | | - .text().should.eventually.equal(expectedHookLog) |
| 28 | + it("navigates and returns", async () => { |
| 29 | + await loadFirstLazyLoadPage(); |
| 30 | + compareScreen(lazyLoadedDisplay); |
| 31 | + |
| 32 | + const btn = await driver.findElementByAccessibilityId("second-navigate-back-lazy-load"); |
| 33 | + btn.tap(); |
| 34 | + compareScreen(initialDisplayName); |
| 35 | + |
| 36 | + assertImages(); |
52 | 37 | }); |
53 | 38 |
|
54 | | - it("navigates and clear history", function() { |
55 | | - return driver |
56 | | - .waitForElementByAccessibilityId("first-navigate-lazy-load", 300000) |
57 | | - .elementByAccessibilityId("first-navigate-clear-history-lazy-load") |
58 | | - .should.eventually.exist |
59 | | - .tap() |
60 | | - .elementByAccessibilityId("second-lazy-load") |
61 | | - .should.eventually.exist |
62 | | - .text().should.eventually.equal("Second: lazy-load") |
63 | | - .elementByAccessibilityId("router-location-strategy-states-lazy-load") |
64 | | - .text().should.eventually.equal("/second/lazy-load") |
| 39 | + it("navigates and clear history", async () => { |
| 40 | + await loadFirstLazyLoadPage(); |
| 41 | + compareScreen(lazyLoadedDisplay); |
| 42 | + |
| 43 | + await driver.navBack(); |
| 44 | + compareScreen(initialDisplayName); |
| 45 | + |
| 46 | + assertImages(); |
65 | 47 | }); |
| 48 | + |
| 49 | + async function compareScreen(imageName){ |
| 50 | + imagesResults.set(lazyLoadedDisplay, await driver.compareScreen("lazyLoaded", 1, 0.01)); |
| 51 | + } |
| 52 | + |
| 53 | + function assertImages(){ |
| 54 | + for (let key in imagesResults) { |
| 55 | + assert.isTrue(imagesResults.get(key), `Image is not correct ${key}`); |
| 56 | + } |
| 57 | + } |
66 | 58 | }); |
0 commit comments