Skip to content

Commit

Permalink
fix(address-finder): Update to version 4.5.3
Browse files Browse the repository at this point in the history
* migrate cypress to version 13
* remove outdated code parts
* adjust test files
  • Loading branch information
mfilip committed Apr 9, 2024
1 parent 7b24c7a commit 02c803c
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 228 deletions.
16 changes: 16 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: "http://localhost:8000",
video: false,
testIsolation: false,
specPattern: "cypress/integration/**/**.ts",
},
viewportWidth: 1920,
viewportHeight: 1024,
env: {
"WC_VERSION": "80",
"API_KEY": "ak_marcin"
}
});
5 changes: 0 additions & 5 deletions cypress.json

This file was deleted.

1 change: 1 addition & 0 deletions cypress/integration/001_test_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Cypress.on("uncaught:exception", (err, runnable) => {

describe("IdealPostcodes Admin Setup", () => {
before(() => {
console.log(Cypress.env("WC_VERSION"));
if (Cypress.env("WC_VERSION")) {
// @ts-ignore
return cy[`installwc${Cypress.env("WC_VERSION")}`]();
Expand Down
21 changes: 12 additions & 9 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,22 @@ declare namespace Cypress {
installwc59(): void;
installwc60(): void;
installwc70(): void;
installwc80(): void
}
}

Cypress.Commands.add("login", () => {
cy.visit("/wp-login.php");
cy.wait(100);
cy.get("#user_login").clear();
cy.wait(10);
cy.get("#user_login").focus().type("admin");
cy.get("#user_pass").clear();
cy.wait(100);
cy.get("#user_pass").focus().type("password");
cy.get("#wp-submit").click();
cy.wait(1000);
cy.wait(500);
cy.get("#user_login").clear().then(() => {
cy.wait(10);
cy.get("#user_login").focus().type("admin");
cy.get("#user_pass").clear();
cy.wait(100);
cy.get("#user_pass").focus().type("password");
cy.get("#wp-submit").click();
cy.wait(1000);
});
});

const install42 = () => {
Expand Down Expand Up @@ -381,6 +383,7 @@ Cypress.Commands.add("installwc80", () => {
cy.wait(1000);
cy.get(".components-button.woocommerce-profiler-navigation-skip-link.is-link").click();
cy.url({ timeout: 300000 }).should('contain', '/wp-admin/admin.php?page=wc-admin');
cy.wait(20000);
cy.contains("Add shipping costs").click();
cy.url({ timeout: 300000 }).should('contain', '/wp-admin/admin.php?page=wc-admin&task=shipping');
cy.get("#woocommerce-shipping-rate__toggle-0").click();
Expand Down
File renamed without changes.
8 changes: 2 additions & 6 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
{
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"target": "es2015",
"lib": ["es5", "dom"],
"types": ["cypress"]
},
"include": [
"**/*.ts"
]
"include": ["**/*.ts"]
}
29 changes: 1 addition & 28 deletions lib/admin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AddressFinder } from "@ideal-postcodes/address-finder";
import { toIso, change, hasValue, isSelect, AnyAddress } from "@ideal-postcodes/jsutil";

const { watch } = AddressFinder;

Expand Down Expand Up @@ -60,20 +59,7 @@ orderSelectors.forEach((selectors) => {
outputFields: selectors,
listStyle: {
minWidth: "25em"
},
onAddressRetrieved: function (address: AnyAddress) {
const select = document.querySelector(
selectors.country
) as HTMLSelectElement;
const code = toIso(address);
if (
select !== null &&
code !== null &&
isSelect(select) &&
hasValue(select, code)
)
change({ e: select, value: code });
},
}
},
{
pageTest: (): boolean => /\/wp-admin/i.test(window.location.href),
Expand All @@ -88,19 +74,6 @@ userSelectors.forEach((selectors) => {
...config,
...(config.autocompleteOverride || {}),
outputFields: selectors,
onAddressRetrieved: function (address: AnyAddress) {
const select = document.querySelector(
selectors.country
) as HTMLSelectElement;
const code = toIso(address);
if (
select !== null &&
code !== null &&
isSelect(select) &&
hasValue(select, code)
)
change({ e: select, value: code });
},
},
{
pageTest: (): boolean => /\/wp-admin/i.test(window.location.href),
Expand Down
23 changes: 7 additions & 16 deletions lib/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import {
Selectors,
Config,
idGen,
isString,
//isString,
OutputFields,
toIso,
//toIso,
hide,
show,
toHtmlElem,
isInput,
update,
//toHtmlElem,
//isInput,
//update,
setupBind,
insertBefore,
Targets,
getParent,
AnyAddress
//AnyAddress
} from "@ideal-postcodes/jsutil";

if (!window.IdealPostcodes) window.IdealPostcodes = {};
Expand Down Expand Up @@ -178,8 +178,6 @@ export const toOutputFields = (
selectors: Selectors
): OutputFields => {
const outputFields: OutputFields = { ...selectors };
if (config.populateOrganisation === false)
delete outputFields.organisation_name;
if (config.populateCounty === false) delete outputFields.county;
return outputFields;
};
Expand Down Expand Up @@ -213,14 +211,7 @@ export const newBind = (selectors: Selectors) => (config: WooConfig) => {
apiKey: config.apiKey,
tags,
outputFields,
onAddressPopulated: (address: AnyAddress) => {
if (isString(outputFields.country)) {
const countryField = toHtmlElem(parent, outputFields.country);
if (isInput(countryField)) {
const iso = toIso(address);
if (iso) update(countryField, iso);
}
}
onAddressPopulated: () => {
updateCheckout();
},
};
Expand Down
Loading

0 comments on commit 02c803c

Please sign in to comment.