Skip to content

Commit

Permalink
feat(preact): renaming the branch override parameter to `searchspring…
Browse files Browse the repository at this point in the history
…-preview`
  • Loading branch information
korgon committed Dec 19, 2024
1 parent 2c9561e commit eee80a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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');
Expand Down
5 changes: 3 additions & 2 deletions packages/snap-preact/src/Snap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/snap-preact/src/integration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit eee80a0

Please sign in to comment.