Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
718d6c3
Restore
Jul 15, 2023
75bcd60
Merge branch 'add-tests-workshop' into pokemon-index-input
Jul 15, 2023
72c5f86
Merge branch 'add-tests-workshop' into pokemon-index-input
Jul 15, 2023
580f944
fix failing test
Jul 15, 2023
18447f3
Merge branch 'add-tests-workshop' into add-tests-workshop-solution
ShellyDCMS Jul 15, 2023
bc97d37
Merge branch 'add-tests-workshop' into add-tests-workshop-solution
ShellyDCMS Jul 15, 2023
1d6aea1
Merge branch 'add-tests-workshop' into add-tests-workshop-solution
ShellyDCMS Jul 15, 2023
179941e
fix integration tests
Jul 15, 2023
07bbfdc
Merge branch 'add-tests-workshop-solution' of https://github.com/Shel…
Jul 15, 2023
c0b79bd
Merge branch 'add-tests-workshop' into add-tests-workshop-solution
ShellyDCMS Jul 15, 2023
fcc5cee
Merge branch 'add-tests-workshop' into add-tests-workshop-solution
Jul 15, 2023
73a9ddc
Merge branch 'add-tests-workshop-solution' of https://github.com/Shel…
Jul 15, 2023
1184866
Merge branch 'add-tests-workshop' into add-tests-workshop-solution
ShellyDCMS Jul 15, 2023
1809c0f
Merge branch 'add-tests-workshop' into add-tests-workshop-solution
ShellyDCMS Jul 15, 2023
778ebb1
fix image fallback defect
Jul 18, 2023
6d6c7cd
Merge branch 'add-tests-workshop' into add-tests-workshop-solution
Jul 19, 2023
b6b2fdc
restore react fix
Jul 19, 2023
6bfbe7c
Merge branch 'add-tests-workshop' into add-tests-workshop-solution
Jul 19, 2023
f986f76
Merge branch 'add-tests-workshop' into add-tests-workshop-solution
Jul 19, 2023
6c3ea10
add integration test
Jul 19, 2023
91f3553
add tests and fix image error bug
Jul 26, 2023
13e643c
fix failing tests
Jul 26, 2023
4c10e78
fix failing tests
Jul 26, 2023
bb2a5bf
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 2, 2023
499465d
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 2, 2023
e33d64e
max chars -> 120
Aug 2, 2023
da87988
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 2, 2023
8f9bb90
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 2, 2023
c5e7a76
update test name
Aug 5, 2023
42eca6e
remove wait from rendering go component driver
Aug 6, 2023
bcf9b13
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 8, 2023
106ab88
updates due to breaking changes in cypress helper
Aug 8, 2023
c4aa88c
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 8, 2023
dc42215
fix failing tests
Aug 8, 2023
a9724fe
update lock file
Aug 9, 2023
76d1e37
update lockfile
Aug 9, 2023
a7a06ce
fix failing tests
Aug 9, 2023
7cc8705
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 9, 2023
7942976
fix failing test
Aug 9, 2023
eb6e96f
add types
Aug 10, 2023
ad4599f
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 10, 2023
26cfa5e
improve tests readability
Aug 10, 2023
d7ed5de
fix failing tests
Aug 10, 2023
dd79b35
update angular and lit as well
Aug 10, 2023
0d9edd9
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 10, 2023
897e37f
remove all async await from tests
Aug 15, 2023
c4cdcaf
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 15, 2023
6a1cb46
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 26, 2023
3dc1c7b
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 26, 2023
48da690
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 26, 2023
c2e7915
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 26, 2023
221e705
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 27, 2023
3abac49
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 27, 2023
538db0c
add e2e tests fro pokemon go
Aug 28, 2023
70449fe
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 28, 2023
b215557
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 29, 2023
5b6983c
data-cy => data-hook
Aug 29, 2023
8cb7ce7
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 29, 2023
a973ef8
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 29, 2023
3cde235
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 29, 2023
fafcdbf
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 29, 2023
c7aaae9
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Aug 30, 2023
1a0b733
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Sep 5, 2023
41657ab
fix typo in test name
Sep 5, 2023
dd39529
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Sep 6, 2023
87803fd
fix failing integration tests
Sep 8, 2023
1891258
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Oct 2, 2023
3a1f5a3
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Oct 6, 2023
9f320b9
upgrade to new helper
Oct 6, 2023
3bed2ce
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Oct 17, 2023
2acf23d
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Oct 18, 2023
457d302
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Oct 22, 2023
d305345
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Nov 4, 2023
d85a800
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Nov 5, 2023
5b5a74b
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Jan 12, 2024
1ec7f20
use asseratble
Jan 12, 2024
b48b3bd
restore tests
Jan 12, 2024
e85be27
Merge pull request #44 from ShellyDCMS/use-assert
ShellyDCMS Jan 12, 2024
2b6f4b1
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Jan 18, 2024
3ac4a74
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Jan 29, 2024
7d4b06b
update assertable import path
Jan 29, 2024
5c70171
add missing declaration
Feb 15, 2024
9a7614c
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Feb 17, 2024
5fd12c6
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Feb 17, 2024
8d05826
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Feb 17, 2024
1af0129
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Feb 21, 2024
182db41
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Mar 24, 2024
1033bf9
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Mar 29, 2024
28225d8
Merge branch 'add-tests-workshop-starter' into add-tests-workshop-sol…
Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class PokemonPageDriver {
this.helper.beforeAndAfter();
this.pokemonDriver.beforeAndAfter();
};

given = {
fetchPokemonResponse: (response: PokemonList) =>
this.helper.given.interceptAndMockResponse({
Expand All @@ -27,14 +28,12 @@ export class PokemonPageDriver {
};

when = {
...this.pokemonDriver.when
...this.pokemonDriver.when,
waitForPokemonLastCall: () => this.helper.when.waitForLastCall("pokemon")
};

get = {
...this.pokemonDriver.get,
fetchPokemonOffset: () => {
this.helper.when.waitForLastCall("pokemon");
return this.helper.get.requestQueryParam("pokemon", "offset");
}
fetchPokemonQueryParams: () => this.helper.get.requestQueryParams("pokemon")
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,40 @@ describe("Pokemon e2e", () => {
});
});
});

describe("when typing pokemon index and clicking Go", () => {
beforeEach(() => {
when.pokemon.pokemonGo.typePokemonIndex("25");
when.pokemon.pokemonGo.clickGo();
when.waitUntil(() => get.elementByText("pikachu"));
});

it("should update index", () => {
then(get.pokemon.countText()).shouldStartWith("25 of");
});

it("should update pokemon image", () => {
then(get.pokemon.image.pictureSrc()).shouldEndWith("/25.gif");
});

it("prev button should be enabled", () => {
then(get.pokemon.prevButton()).shouldBeEnabled();
});

it("should render pokemon name", () => {
then(get.elementByText("pikachu")).shouldExist();
});
});

describe("when changing from pokemon without gif to pokemon with gif, should show gif", () => {
it("should render pokemon gif", () => {
when.pokemon.pokemonGo.typePokemonIndex("888");
when.pokemon.pokemonGo.clickGo();
when.waitUntil(() => get.elementByText("zacian"));
when.pokemon.pokemonGo.typePokemonIndex("33");
when.pokemon.pokemonGo.clickGo();
when.waitUntil(() => get.elementByText("nidorino"));
then(get.pokemon.image.pictureSrc()).shouldEndWith("/33.gif");
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("Pokemon Page integration Tests", () => {
given.pokemon.fetchPokemonResponse(pokemonList);
given.pokemon.fetchImageResponse("default.png");
when.visit("/");
when.pokemon.waitForPokemonLastCall();
});

it("should disable next button once showing last pokemon", () => {
Expand All @@ -28,5 +29,15 @@ describe("Pokemon Page integration Tests", () => {
it("should disable prev button once showing first pokemon", () => {
then(get.pokemon.prevButton()).shouldBeDisabled();
});

it("should render correct image", () => {
then(get.pokemon.image.pictureSrc()).shouldEndWith("/1.gif");
});

it("should fetch pokemon by index", () => {
when.pokemon.pokemonGo.typePokemonIndex("78");
when.pokemon.pokemonGo.clickGo();
then(get.pokemon.fetchPokemonQueryParams()).shouldInclude({ offset: "77" });
});
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PokemonGoComponent } from "@components/pokemon-go/pokemon-go.component";
import { PokemonList, PokemonService } from "@services/pokemon.service";
import { then } from "@shellygo/cypress-test-utils";
import { Builder } from "builder-pattern";
Expand All @@ -11,7 +12,7 @@ describe("PokemonCatalogComponent Tests", () => {
const { when, given, get, beforeAndAfter } = new PokemonCatalogComponentDriver();

const testConfig = {
declarations: [PokemonCatalog, PokemonImageComponent],
declarations: [PokemonCatalog, PokemonImageComponent, PokemonGoComponent],
providers: [
{
provide: PokemonService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import type { Type } from "@angular/core";
import { CypressHelper } from "@shellygo/cypress-test-utils";
import { CypressAngularComponentHelper } from "@shellygo/cypress-test-utils/angular";
import { MountConfig } from "cypress/angular";
import { PokemonGoComponent } from "./pokemon-go.component";

export class PokemonGoComponentDriver {
beforeAndAfter = () => {};
private helper = new CypressHelper({ defaultDataAttribute: "data-hook" });
private angularComponentHelper = new CypressAngularComponentHelper<PokemonGoComponent>();

private componentProperties: Partial<PokemonGoComponent> = {};

beforeAndAfter = () => {
this.helper.beforeAndAfter();
};

given = {};

when = {};
when = {
render: (type: Type<PokemonGoComponent>, config: MountConfig<PokemonGoComponent>) => {
this.angularComponentHelper.when.mount(type, config, {
...this.componentProperties
});
},
typePokemonIndex: (value: string) => this.helper.when.type("pokemon-index", value),
clickGo: () => this.helper.when.click("go")
};

get = {};
get = {
pokemonIndexInputValue: () => this.helper.get.inputValue("pokemon-index"),
selectedPokemonSpy: () => this.helper.get.spy("selectedPokemon"),
goButton: () => this.helper.get.elementByTestId("go")
};
}
Original file line number Diff line number Diff line change
@@ -1 +1,48 @@
describe("PokemonGo Component Tests", () => {});
import { FormsModule } from "@angular/forms";
import { then } from "@shellygo/cypress-test-utils";
import { PokemonGoComponent } from "./pokemon-go.component";
import { PokemonGoComponentDriver } from "./pokemon-go.component.driver";

describe("PokemonGo Component Tests", () => {
const testConfig = {
declarations: [PokemonGoComponent],
imports: [FormsModule]
};

const { when, get, given, beforeAndAfter } = new PokemonGoComponentDriver();
beforeAndAfter();

beforeEach(() => {
when.render(PokemonGoComponent, testConfig);
});
it("Go button should be disabled", () => {
then(get.goButton()).shouldBeDisabled();
});

it("when typing index Go button should be enabled", () => {
when.typePokemonIndex("33");
then(get.goButton()).shouldBeEnabled();
});

it("When input filled should have input value", () => {
when.typePokemonIndex("42");
then(get.pokemonIndexInputValue()).shouldEqual("42");
});

it("When input and clicked go should fetch pokemon by index", () => {
when.typePokemonIndex("12");
when.clickGo();
then(get.selectedPokemonSpy()).shouldHaveBeenCalledWith("12");
});

it("should clear input when clicking submit", () => {
when.typePokemonIndex("33");
when.clickGo();
then(get.pokemonIndexInputValue()).shouldEqual("");
});

it("should not update input value when typing non digits", () => {
when.typePokemonIndex("abcd-");
then(get.pokemonIndexInputValue()).shouldEqual("");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class PokemonImageComponent {
this.showFallbackImage = true;
}

ngOnChanges() {
this.showFallbackImage = false;
}
getPokemonImage = () => {
return `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/versions/generation-v/black-white/animated/${this.pokemonIndex}.gif`;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PokemonCatalogComponentDriver } from "@components/pokemon-catalog/pokemon-catalog.component.driver";
import { PokemonList } from "@services/pokemon.service";
import { CypressHelper } from "@shellygo/cypress-test-utils";
import { Interception } from "cypress/types/net-stubbing";

export class PokemonPageDriver {
private helper: CypressHelper = new CypressHelper({ defaultDataAttribute: "data-hook" });
Expand All @@ -10,7 +11,9 @@ export class PokemonPageDriver {
this.helper.beforeAndAfter();
this.pokemonDriver.beforeAndAfter();
};

given = {
...this.pokemonDriver.given,
fetchPokemonResponse: (response: PokemonList) =>
this.helper.given.interceptAndMockResponse({
url: "https://pokeapi.co/api/v2/pokemon**",
Expand All @@ -27,10 +30,12 @@ export class PokemonPageDriver {
};

when = {
...this.pokemonDriver.when
...this.pokemonDriver.when,
waitForPokemonLastCall: (): Cypress.Chainable<Interception> => this.helper.when.waitForLastCall("pokemon")
};

get = {
...this.pokemonDriver.get
...this.pokemonDriver.get,
fetchPokemonQueryParams: () => this.helper.get.requestQueryParams("pokemon")
};
}
36 changes: 36 additions & 0 deletions examples/lit/pokemon-catalog/cypress/e2e/pokemon-page.spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,40 @@ describe("Pokemon e2e", () => {
});
});
});

describe("when typing pokemon index and clicking Go", () => {
beforeEach(() => {
when.pokemon.pokemonGo.typePokemonIndex("25");
when.pokemon.pokemonGo.clickGo();
when.waitUntil(() => get.elementByText("pikachu"));
});

it("should update index", () => {
then(get.pokemon.countText()).shouldStartWith("25 of");
});

it("should update pokemon image", () => {
then(get.pokemon.image.pictureSrc()).shouldEndWith("/25.gif");
});

it("prev button should be enabled", () => {
then(get.pokemon.prevButton()).shouldBeEnabled();
});

it("should render pokemon name", () => {
then(get.elementByText("pikachu")).shouldExist();
});
});

describe("when changing from pokemon without gif to pokemon with gif, should show gif", () => {
it("should render pokemon gif", () => {
when.pokemon.pokemonGo.typePokemonIndex("888");
when.pokemon.pokemonGo.clickGo();
when.waitUntil(() => get.elementByText("zacian"));
when.pokemon.pokemonGo.typePokemonIndex("33");
when.pokemon.pokemonGo.clickGo();
when.waitUntil(() => get.elementByText("nidorino"));
then(get.pokemon.image.pictureSrc()).shouldEndWith("/33.gif");
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("Pokemon Page integration Tests", () => {
given.pokemon.fetchPokemonResponse(pokemonList);
given.pokemon.fetchImageResponse("default.png");
when.visit("/");
when.pokemon.waitForPokemonLastCall();
});

it("should disable next button once showing last pokemon", () => {
Expand All @@ -28,5 +29,15 @@ describe("Pokemon Page integration Tests", () => {
it("should disable prev button once showing first pokemon", () => {
then(get.pokemon.prevButton()).shouldBeDisabled();
});

it("should render correct image", () => {
then(get.pokemon.image.pictureSrc()).shouldEndWith("/1.gif");
});

it("should fetch pokemon by index", () => {
when.pokemon.pokemonGo.typePokemonIndex("78");
when.pokemon.pokemonGo.clickGo();
then(get.pokemon.fetchPokemonQueryParams()).shouldInclude({ offset: "77" });
});
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
import { CypressHelper } from "@shellygo/cypress-test-utils";
import { CypressLitComponentHelper } from "@shellygo/cypress-test-utils/lit";
import { html } from "lit";
import { PokemonGoComponent } from "./pokemon-go.component";

export class PokemonGoComponentDriver {
beforeAndAfter = () => {};
private helper = new CypressHelper({ defaultDataAttribute: "data-hook" });
private litComponentHelper = new CypressLitComponentHelper();
private props = {
onSubmit: (pokemonIndex: string) => {}
};
beforeAndAfter = () => {
this.helper.beforeAndAfter();
};

given = {};
given = {
onSubmitSpy: () => {
this.props.onSubmit = this.helper.given.spyOnObject(this.props, "onSubmit");
}
};

when = {};
when = {
render: (element: PokemonGoComponent) => {
this.litComponentHelper.when.unmount(element);
this.litComponentHelper.when.mount(element, html`<pokemon-go .onSubmit="${this.props.onSubmit}"></pokemon-go>`);
},
typePokemonIndex: (input: string) => this.helper.when.type("pokemon-index", input),
clickGo: () => this.helper.when.click("go")
};

get = {};
get = {
onSubmitSpy: () => this.helper.get.spy("onSubmit"),
pokemonIndexInputValue: () => this.helper.get.inputValue("pokemon-index"),
goButton: () => this.helper.get.elementByTestId("go")
};
}
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
describe("PokemonGo Component Tests", () => {});
import { then } from "@shellygo/cypress-test-utils";
import { PokemonGoComponent } from "./pokemon-go.component";
import { PokemonGoComponentDriver } from "./pokemon-go.component.driver";

describe("PokemonGo Component Tests", () => {
const { when, given, get, beforeAndAfter } = new PokemonGoComponentDriver();
beforeAndAfter();

beforeEach(() => {
given.onSubmitSpy();
when.render(new PokemonGoComponent());
});

it("Go button should be disabled", () => {
then(get.goButton()).shouldBeDisabled();
});

it("when typing index Go button should be enabled", () => {
when.typePokemonIndex("33");
then(get.goButton()).shouldBeEnabled();
});

it("When input filled should have input value", () => {
when.typePokemonIndex("42");
then(get.pokemonIndexInputValue()).shouldEqual("42");
});

it("when typing index and submitting should call onSubmit", () => {
when.typePokemonIndex("33");
when.clickGo();
then(get.onSubmitSpy()).shouldHaveBeenCalledWith("33");
});

it("should clear input when clicking submit", () => {
when.typePokemonIndex("33");
when.clickGo();
then(get.pokemonIndexInputValue()).shouldEqual("");
});

it("should not update input value when typing non digits", () => {
when.typePokemonIndex("abcd-");
then(get.pokemonIndexInputValue()).shouldEqual("");
});
});
Loading