From 9d6c5bd0969cfb4a0994f59522484827015ef52a Mon Sep 17 00:00:00 2001 From: Zain Fathoni Date: Tue, 14 Sep 2021 22:29:43 +0800 Subject: [PATCH 1/9] test(e2e): upgrade Cypress version --- package.json | 2 +- yarn.lock | 31 +++++++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 948e7083..2c2ffaf6 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "cloudinary-build-url": "^0.2.1", "critters": "^0.0.10", "cross-env": "^7.0.3", - "cypress": "8.2.0", + "cypress": "8.4.0", "eslint": "7.30.0", "eslint-config-kentcdodds": "^19.1.0", "eslint-config-next": "11.0.1", diff --git a/yarn.lock b/yarn.lock index 6fedba89..a895b9e5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1541,10 +1541,10 @@ resolved "https://registry.yarnpkg.com/@corex/deepmerge/-/deepmerge-2.6.20.tgz#a72d1cb5a101fd11160815b96f499a588362ba5b" integrity sha512-oZZxwDtV0bf8VPcSIhZPvdBFUkVIC8zRblUjrrVAsbGRiqUuZJfoXw2M6NDiIXWcUCfOqbkFND6Yf3b9ej9AjA== -"@cypress/request@^2.88.5": - version "2.88.5" - resolved "https://registry.yarnpkg.com/@cypress/request/-/request-2.88.5.tgz#8d7ecd17b53a849cfd5ab06d5abe7d84976375d7" - integrity sha512-TzEC1XMi1hJkywWpRfD2clreTa/Z+lOrXDCxxBTBPEcY5azdPi56A6Xw+O4tWJnaJH3iIE7G5aDXZC6JgRZLcA== +"@cypress/request@^2.88.6": + version "2.88.6" + resolved "https://registry.yarnpkg.com/@cypress/request/-/request-2.88.6.tgz#a970dd675befc6bdf8a8921576c01f51cc5798e9" + integrity sha512-z0UxBE/+qaESAHY9p9sM2h8Y4XqtsbDCt0/DPOrqA/RZgKi4PkxdpXyK4wCCnSk1xHqWHZZAE+gV6aDAR6+caQ== dependencies: aws-sign2 "~0.7.0" aws4 "^1.8.0" @@ -1559,13 +1559,12 @@ isstream "~0.1.2" json-stringify-safe "~5.0.1" mime-types "~2.1.19" - oauth-sign "~0.9.0" performance-now "^2.1.0" qs "~6.5.2" safe-buffer "^5.1.2" tough-cookie "~2.5.0" tunnel-agent "^0.6.0" - uuid "^3.3.2" + uuid "^8.3.2" "@cypress/xvfb@^1.2.4": version "1.2.4" @@ -4689,12 +4688,12 @@ currently-unhandled@^0.4.1: dependencies: array-find-index "^1.0.1" -cypress@8.2.0: - version "8.2.0" - resolved "https://registry.yarnpkg.com/cypress/-/cypress-8.2.0.tgz#1e4e9f6218324e82a95c1b9cad7f3965ba663d7f" - integrity sha512-jg7S5VxxslwsgEyAkCE9ZCkFADxOUY1bSWScp1cWnga88K0TZgFQ0zdxyG9Mw/4spLGuvkriIZ62am+TR6C04w== +cypress@8.4.0: + version "8.4.0" + resolved "https://registry.yarnpkg.com/cypress/-/cypress-8.4.0.tgz#09ec06a73f1cb10121c103cba15076e659e24876" + integrity sha512-RtVgGFR06ikyMaq/VqapeqOjGaIA42PpK7F0qe1MCiFArfUuJECsLmeYaOA+1TlmNUgJNMSF5fWKkZIJr5Uc7w== dependencies: - "@cypress/request" "^2.88.5" + "@cypress/request" "^2.88.6" "@cypress/xvfb" "^1.2.4" "@types/node" "^14.14.31" "@types/sinonjs__fake-timers" "^6.0.2" @@ -9847,11 +9846,6 @@ nwsapi@^2.2.0: resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.0.tgz#204879a9e3d068ff2a55139c2c772780681a38b7" integrity sha512-h2AatdwYH+JHiZpv7pt/gSX1XoRGb7L/qSIeuqA6GwYoF9w1vP1cw42TO0aI2pNyshRK5893hNSl+1//vHK7hQ== -oauth-sign@~0.9.0: - version "0.9.0" - resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455" - integrity sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ== - object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" @@ -13245,6 +13239,11 @@ uuid@^3.0.1, uuid@^3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== +uuid@^8.3.2: + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== + v8-compile-cache@^2.0.3, v8-compile-cache@^2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee" From ed1e543acbd514b2cb6518e3a638ca9e38210924 Mon Sep 17 00:00:00 2001 From: Zain Fathoni Date: Tue, 14 Sep 2021 23:23:26 +0800 Subject: [PATCH 2/9] test(e2e): search by phone number --- components/contact-list.tsx | 5 ++++- cypress/e2e/contacts/search.js | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 cypress/e2e/contacts/search.js diff --git a/components/contact-list.tsx b/components/contact-list.tsx index f6b1acc8..933a9e6e 100644 --- a/components/contact-list.tsx +++ b/components/contact-list.tsx @@ -16,7 +16,10 @@ type ContactListProps = { export function ContactList(props: ContactListProps) { const contactList = useMemo( () => ( -
+
    {props.data.map((contact, index) => ( { + beforeEach(() => { + cy.visit("/provinces/dki-jakarta"); + }); + + it("search by phone number", () => { + cy.findByRole("textbox", { + name: /cari kontak:/i, + }).type("08111617101"); + + cy.findByRole("button", { + name: /cari/i, + }).click(); + + cy.findByTestId("contact-list").within(() => + cy + .get("li") + .each((contact) => + cy + .wrap(contact) + .within(() => cy.findByText("08111617101").should("be.visible")), + ), + ); + }); +}); From 73f8882da6e742a1bad19a0e6a9752b1507b939c Mon Sep 17 00:00:00 2001 From: Zain Fathoni Date: Tue, 14 Sep 2021 23:30:27 +0800 Subject: [PATCH 3/9] test(e2e): search by address --- cypress/e2e/contacts/search.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cypress/e2e/contacts/search.js b/cypress/e2e/contacts/search.js index b37460fe..5fc84ec6 100644 --- a/cypress/e2e/contacts/search.js +++ b/cypress/e2e/contacts/search.js @@ -22,4 +22,24 @@ describe("contacts page typed search", () => { ), ); }); + + it.only("search by address", () => { + cy.findByRole("textbox", { + name: /cari kontak:/i, + }).type("Sudirman"); + + cy.findByRole("button", { + name: /cari/i, + }).click(); + + cy.findByTestId("contact-list").within(() => + cy + .get("li") + .each((contact) => + cy + .wrap(contact) + .within(() => cy.findAllByText(/sudirman/i).should("be.visible")), + ), + ); + }); }); From 97368676599c867e48f297f0832e141b51829360 Mon Sep 17 00:00:00 2001 From: Zain Fathoni Date: Tue, 14 Sep 2021 23:36:53 +0800 Subject: [PATCH 4/9] test(e2e): search by penyedia --- cypress/e2e/contacts/search.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/contacts/search.js b/cypress/e2e/contacts/search.js index 5fc84ec6..5ca4c5ee 100644 --- a/cypress/e2e/contacts/search.js +++ b/cypress/e2e/contacts/search.js @@ -23,7 +23,7 @@ describe("contacts page typed search", () => { ); }); - it.only("search by address", () => { + it("search by address", () => { cy.findByRole("textbox", { name: /cari kontak:/i, }).type("Sudirman"); @@ -42,4 +42,26 @@ describe("contacts page typed search", () => { ), ); }); + + it("search by penyedia", () => { + cy.findByRole("textbox", { + name: /cari kontak:/i, + }).type("dompet dhuafa"); + + cy.findByRole("button", { + name: /cari/i, + }).click(); + + cy.findByTestId("contact-list").within(() => + cy + .get("li") + .each((contact) => + cy + .wrap(contact) + .within(() => + cy.findAllByText(/dompet dhuafa/i).should("be.visible"), + ), + ), + ); + }); }); From be5ea44e5245c7097d8be6d8c039ab3a2bd5e116 Mon Sep 17 00:00:00 2001 From: Zain Fathoni Date: Tue, 14 Sep 2021 23:41:03 +0800 Subject: [PATCH 5/9] test(e2e): trigger the search by pressing the {enter} button instead --- cypress/e2e/contacts/search.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/cypress/e2e/contacts/search.js b/cypress/e2e/contacts/search.js index 5ca4c5ee..dcc43597 100644 --- a/cypress/e2e/contacts/search.js +++ b/cypress/e2e/contacts/search.js @@ -26,11 +26,7 @@ describe("contacts page typed search", () => { it("search by address", () => { cy.findByRole("textbox", { name: /cari kontak:/i, - }).type("Sudirman"); - - cy.findByRole("button", { - name: /cari/i, - }).click(); + }).type("Sudirman{enter}"); cy.findByTestId("contact-list").within(() => cy @@ -46,11 +42,7 @@ describe("contacts page typed search", () => { it("search by penyedia", () => { cy.findByRole("textbox", { name: /cari kontak:/i, - }).type("dompet dhuafa"); - - cy.findByRole("button", { - name: /cari/i, - }).click(); + }).type("dompet dhuafa{enter}"); cy.findByTestId("contact-list").within(() => cy From 590abc2ca42817e3db05fd8212fda95fd11ec8fb Mon Sep 17 00:00:00 2001 From: Zain Fathoni Date: Tue, 14 Sep 2021 23:47:35 +0800 Subject: [PATCH 6/9] refactor(e2e): extract forEachContactItem custom command --- cypress/e2e/contacts/search.js | 32 ++++++-------------------------- cypress/support/commands.js | 6 ++++++ 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/cypress/e2e/contacts/search.js b/cypress/e2e/contacts/search.js index dcc43597..722593e5 100644 --- a/cypress/e2e/contacts/search.js +++ b/cypress/e2e/contacts/search.js @@ -12,14 +12,8 @@ describe("contacts page typed search", () => { name: /cari/i, }).click(); - cy.findByTestId("contact-list").within(() => - cy - .get("li") - .each((contact) => - cy - .wrap(contact) - .within(() => cy.findByText("08111617101").should("be.visible")), - ), + cy.forEachContactItem(() => + cy.findByText("08111617101").should("be.visible"), ); }); @@ -28,14 +22,8 @@ describe("contacts page typed search", () => { name: /cari kontak:/i, }).type("Sudirman{enter}"); - cy.findByTestId("contact-list").within(() => - cy - .get("li") - .each((contact) => - cy - .wrap(contact) - .within(() => cy.findAllByText(/sudirman/i).should("be.visible")), - ), + cy.forEachContactItem(() => + cy.findAllByText(/sudirman/i).should("be.visible"), ); }); @@ -44,16 +32,8 @@ describe("contacts page typed search", () => { name: /cari kontak:/i, }).type("dompet dhuafa{enter}"); - cy.findByTestId("contact-list").within(() => - cy - .get("li") - .each((contact) => - cy - .wrap(contact) - .within(() => - cy.findAllByText(/dompet dhuafa/i).should("be.visible"), - ), - ), + cy.forEachContactItem(() => + cy.findAllByText(/dompet dhuafa/i).should("be.visible"), ); }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 119ab03f..083162bf 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -23,3 +23,9 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) + +Cypress.Commands.add("forEachContactItem", (assertionFn) => { + cy.findByTestId("contact-list").within(() => + cy.get("li").each((contact) => cy.wrap(contact).within(assertionFn)), + ); +}); From ce0edb1851d3966d9dff6e25ea2f276e9a327b0c Mon Sep 17 00:00:00 2001 From: Zain Fathoni Date: Tue, 14 Sep 2021 23:48:36 +0800 Subject: [PATCH 7/9] refactor(e2e): update test name --- cypress/e2e/contacts/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/e2e/contacts/search.js b/cypress/e2e/contacts/search.js index 722593e5..2aaed12d 100644 --- a/cypress/e2e/contacts/search.js +++ b/cypress/e2e/contacts/search.js @@ -27,7 +27,7 @@ describe("contacts page typed search", () => { ); }); - it("search by penyedia", () => { + it("search by provider", () => { cy.findByRole("textbox", { name: /cari kontak:/i, }).type("dompet dhuafa{enter}"); From a8a733286f1e36eed6fe2eff036e9e94c4af3ff1 Mon Sep 17 00:00:00 2001 From: Zain Fathoni Date: Tue, 14 Sep 2021 23:53:03 +0800 Subject: [PATCH 8/9] test(e2e): displays the empty state when there's no matching item --- cypress/e2e/contacts/search.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cypress/e2e/contacts/search.js b/cypress/e2e/contacts/search.js index 2aaed12d..aa1ad677 100644 --- a/cypress/e2e/contacts/search.js +++ b/cypress/e2e/contacts/search.js @@ -36,4 +36,14 @@ describe("contacts page typed search", () => { cy.findAllByText(/dompet dhuafa/i).should("be.visible"), ); }); + + it("displays the empty state when the search keyword matches nothing", () => { + cy.findByRole("textbox", { + name: /cari kontak:/i, + }).type("aoeu{enter}"); + + cy.findByRole("heading", { + name: /fasilitas tidak ditemukan/i, + }).should("be.visible"); + }); }); From 4bd5c35b0796bd6dadae12ee5f8a9e9f862d6dd4 Mon Sep 17 00:00:00 2001 From: Zain Fathoni Date: Sun, 26 Sep 2021 06:40:17 +0800 Subject: [PATCH 9/9] build(dependencies): update yarn.lock file --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index a895b9e5..d4e756c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13234,7 +13234,7 @@ uuid@3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA== -uuid@^3.0.1, uuid@^3.3.2: +uuid@^3.0.1: version "3.4.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==