Skip to content

Commit

Permalink
refactor and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tihuan committed Apr 16, 2020
1 parent 0f68a7b commit 6ef74f1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 25 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
2 changes: 1 addition & 1 deletion test/integration/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const WAIT_BETWEEN_SCREENSHOTS_MS = 100;

export async function waitUntilScreenSteady() {
export async function waitUntilScreenStable() {
const RETRY_TIMES = 5;
let attempt = 0;

Expand Down
76 changes: 52 additions & 24 deletions test/integration/zika.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { waitUntilScreenSteady } from "./helpers";
import { waitUntilScreenStable } from "./helpers";

describe("Zika", () => {
it("displays the title on the page", async () => {
Expand All @@ -15,41 +15,69 @@ describe("Zika", () => {
});

describe("Color by", () => {
describe("author", () => {
it("matches the screenshot", async () => {
await toMatchImageSnapshot("author", async () => {
await page.keyboard.press("ArrowUp");
await page.keyboard.press("Enter");
});
});
});

describe("country", () => {
it("matches the screenshot", async () => {
await toMatchImageSnapshot("country", () => {});
});
});

describe("date", () => {
it("matches the screenshot", async () => {
await goToZikaPage();
await toMatchImageSnapshot("date", async () => {
await page.keyboard.press("ArrowUp");
await page.keyboard.press("ArrowUp");
await page.keyboard.press("Enter");
});
});
});

const colorBySelector = await expect(page).toMatchElement("#selectColorBy");
describe("region", () => {
it("matches the screenshot", async () => {
await toMatchImageSnapshot("region", async () => {
await page.keyboard.press("ArrowDown");
await page.keyboard.press("Enter");
});
});
});
});
});

await colorBySelector.click();
async function toMatchImageSnapshot(option, selectOptionTest) {
await goToZikaPage();

await page.keyboard.press("ArrowUp");
await page.keyboard.press("ArrowUp");
await page.keyboard.press("Enter");
const colorBySelector = await expect(page).toMatchElement("#selectColorBy");

const EXPECTED_OPTION = "date";
await colorBySelector.click();

await expect(colorBySelector).toMatch(EXPECTED_OPTION);
await selectOptionTest();

const treeTitle = await expect(page).toMatchElement("#Title");
await expect(colorBySelector).toMatch(option);

await expect(treeTitle).toMatch(EXPECTED_OPTION);
const treeTitle = await expect(page).toMatchElement("#Title");

await waitUntilScreenSteady();
await expect(treeTitle).toMatch(option);

const image = await page.screenshot();
await waitUntilScreenStable();

/**
* (tihuan): Apply `blur` to ignore minor noises.
* Also `customSnapshotIdentifier` is needed, since we use `jest.retryTimes()`
* https://github.com/americanexpress/jest-image-snapshot#%EF%B8%8F-api
* https://github.com/americanexpress/jest-image-snapshot/pull/122/files
*/
expect(image).toMatchImageSnapshot({ blur: 2, customSnapshotIdentifier: "Color by: date" });
});
});
});
});
const image = await page.screenshot();

/**
* (tihuan): Apply `blur` to ignore minor noises.
* Also `` is needed, since we use `jest.retryTimes()`
* https://github.com/americanexpress/jest-image-snapshot/pull/122/files
* https://github.com/americanexpress/jest-image-snapshot#%EF%B8%8F-api
*/
expect(image).toMatchImageSnapshot({ blur: 2, customSnapshotIdentifier: `Color by: ${option}` });
}

async function goToZikaPage() {
await page.goto(`${BASE_URL}/zika?p=grid`, { waitUntil: "networkidle2" });
Expand Down

0 comments on commit 6ef74f1

Please sign in to comment.