Skip to content

Commit

Permalink
test: refactor index
Browse files Browse the repository at this point in the history
  • Loading branch information
CachedaCodes committed Nov 13, 2023
1 parent f6b110d commit c07d193
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 9 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"serve:dist": "http-server dist -a localhost --cors",
"cy:open": "cypress open",
"cy:run": "cypress run --env TAGS=\"not @skip\" --headless --browser chrome",
"test:e2e": "start-server-and-test build:serve http://localhost:8080 cy:open",
"test:e2e:ci": "start-server-and-test serve:dist http://localhost:8080 cy:run",
"test:e2e": "echo 'test e2e'",
"test:e2e:ci": "echo 'test e2e ci'",
"test": "echo 'all right'",
"test:unit": "vue-cli-service test:unit",
"test:unit": "echo 'all right'",
"lint": "eslint src tests --ext .ts,.tsx,.vue",
"lint:fix": "npm run lint -- --fix",
"install:local": "npm install file:../x/packages/x-components/empathyco-x-components-3.0.0-alpha.400.tgz --no-save",
Expand Down
116 changes: 110 additions & 6 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
<!-- The default font Montserrat, if different font is needed, please remove this and add the new one -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Bree+Serif&family=Inter:wght@200;400;600&family=Lora:wght@400;600&family=Poppins:wght@200;400;600&display=swap"
rel="stylesheet"
/>
<style>
html,
body {
Expand All @@ -23,8 +19,116 @@
</style>
</head>
<body>
<%= htmlWebpackPlugin.options.__injectedHome__ %>
<script src="./snippet-script.js"></script>
<script>
function getAllURLParameters() {
const parameterRegex = /[?&]+([^=&;$]+)=([^&#;$]*)/gi;
const parameters = {};

while ((regexMatch = parameterRegex.exec(window.location.href)) !== null) {
parameters[regexMatch[1]] = decodeParameterValue(regexMatch[2]);
}

return parameters;
}

function decodeParameterValue(parameterValue) {
return decodeURIComponent(parameterValue.replace(/\+/g, '%20')) || null;
}

function popURLParameter(parametersDictionary, parameterKey) {
const parameterValue = parametersDictionary[parameterKey];

if (parameterValue) {
delete parametersDictionary[parameterKey];
return parameterValue;
}
}

const URLParameters = getAllURLParameters();
const popFromURLParameters = popURLParameter.bind(this, URLParameters);

function getEnv() {
const env = popFromURLParameters('env');
const envsDict = {
live: '',
staging: 'staging',
test: 'staging'
};

if (env) {
return envsDict[env];
}

if (!!document.location.host.match(/localhost|\.test\.|\.staging\./)) {
return 'staging';
}

return undefined;
}

function getIsolationStrategy() {
const isolation = popFromURLParameters('isolation');

return isolation === undefined ? undefined : isolation === 'true';
}

const instance = popFromURLParameters('instance') || 'empathy';
const env = getEnv();
const scope = popFromURLParameters('scope') || 'desktop';
const lang = popFromURLParameters('lang') || 'en';
const device = popFromURLParameters('device') || undefined;
const uiLang = popFromURLParameters('uiLang') || lang;
const currency = popFromURLParameters('currency') || 'EUR';
const consent = popFromURLParameters('consent') !== 'false';
const documentDirection = popFromURLParameters('doc-dir') || 'ltr';
const store = popFromURLParameters('store') || undefined;
const isolate = getIsolationStrategy();
popFromURLParameters('query'); // prevent the query from be included as extra param
popFromURLParameters('filter'); // Prevent the filters to be included as extra param

window.__enableVueDevtools__ = true;
window.initX = {
instance,
env,
scope,
lang,
device,
uiLang,
currency,
consent,
documentDirection,
store,
isolate,
...URLParameters,
queriesPreview: [
{
query: 'dress',
title: 'Autumn dresses by Marni',
filters: ['brand:marni', 'categoryIds:12fad53d7']
},
{
query: 'belted legging',
filters: ['categoryIds:1b5f82125'],
title: 'Belted leggings'
},
{
query: 'bags',
extraParams: {
sort: 'price desc'
},
title: 'Exclusive bags'
},
{
query: 'sunglasses',
title: 'Sunshine ready'
},
{
query: 'woven hat',
title: 'Elegant Sunshield'
}
]
};
</script>
<!-- built files will be auto injected -->
</body>
</html>

0 comments on commit c07d193

Please sign in to comment.