From eee80a02608cf4947a562134cf7f5633b07b8624 Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 19 Dec 2024 11:48:02 -0700 Subject: [PATCH] feat(preact): renaming the branch override parameter to `searchspring-preview` --- .../tests/cypress/e2e/core/branchOverride.cy.js | 4 ++-- packages/snap-preact/src/Snap.tsx | 5 +++-- packages/snap-preact/src/integration.test.tsx | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/snap-preact-demo/tests/cypress/e2e/core/branchOverride.cy.js b/packages/snap-preact-demo/tests/cypress/e2e/core/branchOverride.cy.js index b51c92f66..4362ef00f 100644 --- a/packages/snap-preact-demo/tests/cypress/e2e/core/branchOverride.cy.js +++ b/packages/snap-preact-demo/tests/cypress/e2e/core/branchOverride.cy.js @@ -1,6 +1,6 @@ describe('Branch Override Functionality', () => { it('adds snap bundle to search page', () => { - cy.visit('https://localhost:2222/?branch=override'); + cy.visit('https://localhost:2222/?searchspring-preview=override'); cy.on('uncaught:exception', (err, runnable) => { // expected error due to branch override throwing @@ -42,7 +42,7 @@ describe('Branch Override Functionality', () => { }); // cy.on('uncaught:exception', (err, runnable) => false); - cy.visit('https://localhost:2222/?branch=nope'); + cy.visit('https://localhost:2222/?searchspring-preview=nope'); // expect injected div from 'override' branch to not be on the page cy.get('#override').should('not.exist'); diff --git a/packages/snap-preact/src/Snap.tsx b/packages/snap-preact/src/Snap.tsx index f03ce77c7..62955d7b7 100644 --- a/packages/snap-preact/src/Snap.tsx +++ b/packages/snap-preact/src/Snap.tsx @@ -39,6 +39,7 @@ import { setupEvents } from './setupEvents'; configureMobx({ useProxies: 'never', isolateGlobalState: true, enforceActions: 'never' }); export const BRANCH_COOKIE = 'ssBranch'; +export const BRANCH_PARAM = 'searchspring-preview'; export const DEV_COOKIE = 'ssDev'; export const STYLESHEET_CLASSNAME = 'ss-snap-bundle-styles'; @@ -353,7 +354,7 @@ export class Snap { try { const urlParams = url(window.location.href); - const branchOverride = urlParams?.params?.query?.branch || cookies.get(BRANCH_COOKIE); + const branchOverride = urlParams?.params?.query[BRANCH_PARAM] || cookies.get(BRANCH_COOKIE); const cookieDomain = (typeof window !== 'undefined' && window.location.hostname && '.' + window.location.hostname.replace(/^www\./, '')) || undefined; /* app mode priority: @@ -494,7 +495,7 @@ export class Snap { onRemoveClick={() => { cookies.unset(BRANCH_COOKIE, cookieDomain); const urlState = url(window.location.href); - delete urlState?.params.query['branch']; + delete urlState?.params.query[BRANCH_PARAM]; const newUrl = urlState?.url(); if (newUrl && newUrl != window.location.href) { diff --git a/packages/snap-preact/src/integration.test.tsx b/packages/snap-preact/src/integration.test.tsx index 8ebed4db4..730fb6ac2 100644 --- a/packages/snap-preact/src/integration.test.tsx +++ b/packages/snap-preact/src/integration.test.tsx @@ -5,7 +5,7 @@ import { cleanup, waitFor } from '@testing-library/preact'; import { cookies } from '@searchspring/snap-toolbox'; -import { Snap, SnapConfig, DEV_COOKIE, BRANCH_COOKIE } from './Snap'; +import { Snap, SnapConfig, DEV_COOKIE, BRANCH_PARAM, BRANCH_COOKIE } from './Snap'; import { SHOPIFY_WEBPIXEL_STORAGE_KEY } from './configureSnapFeatures'; const baseConfig: SnapConfig = { @@ -223,7 +223,7 @@ describe('Snap Preact Integration', () => { // @ts-ignore window.location = { - href: `https://www.merch.com?branch=${branchName}`, + href: `https://www.merch.com?${BRANCH_PARAM}=${branchName}`, }; expect(() => {