Skip to content

Commit b65393a

Browse files
committed
Merge remote-tracking branch 'origin/main' into event-builder-updates
2 parents 6660de6 + cce9487 commit b65393a

7 files changed

Lines changed: 231 additions & 127 deletions

File tree

src/components/Layout/GA4Toggle.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/components/Layout/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import { useGAVersion } from "../../hooks"
4141
import { GAVersion, Url } from "../../constants"
4242
import Spinner from "../Spinner"
4343
import { linkData } from "./links"
44-
import GA4Toggle from "./GA4Toggle"
4544
import BugReport from "./BugReport"
4645
import Loadable from "../Loadable"
4746
import useLogin2, { UserStatus } from "./useLogin"
@@ -130,7 +129,12 @@ const Template: React.FC<PropsWithChildren<LayoutProps & TemplateProps>> = ({
130129
const newLocation = window.location.href.replace( window.location.hostname, newHostname );
131130
window.location.replace(newLocation);
132131
}
133-
//}, 1000);
132+
133+
if( !window.location.search && window.location.pathname === '/' ) {
134+
const newLocation = window.location.pathname = '/ga4/';
135+
window.location.replace(newLocation);
136+
}
137+
//}, 1000);
134138

135139
return;
136140
}, []);

src/components/Spinner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from "react"
22
import { styled } from '@mui/material/styles';
33
import { useTheme } from "@mui/material"
4-
import {Circles} from "react-loader-spinner"
4+
import { Circles } from 'react-loader-spinner'
55
import {PropsWithChildren} from 'react';
66

77
const PREFIX = 'Spinner';

src/components/WithHelpText.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const Root = styled('div')((
7878
},
7979

8080
[`& .${classes.notchedChild}`]: {
81-
padding: theme.spacing(1),
81+
padding: theme.spacing(1, 1.75),
8282
},
8383
[`& .${classes.verticalHr}`]: {
8484
display: "flex",
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React from "react"
2+
import { render, screen, fireEvent, within } from "@testing-library/react"
3+
import "@testing-library/jest-dom"
4+
import ValidateEvent, { ValidateEventProps } from "."
5+
import { EventCtx, EventPayload } from ".."
6+
import useValidateEvent from "./useValidateEvent"
7+
import { EventType } from "../types"
8+
9+
// Mock the useValidateEvent hook. This allows us to control its output and check if it's called correctly.
10+
jest.mock("./useValidateEvent", () => ({
11+
__esModule: true,
12+
default: jest.fn(),
13+
}))
14+
15+
const mockedUseValidateEvent = useValidateEvent as jest.Mock
16+
17+
// Mock child components that are not relevant to this test.
18+
jest.mock("@/components/PrettyJson", () => () => <div>PrettyJson</div>)
19+
jest.mock("@/components/Spinner", () => () => <div>Spinner</div>)
20+
21+
const mockValidateEventFn = jest.fn()
22+
23+
// A minimal set of props to render the component.
24+
const defaultProps: ValidateEventProps = {
25+
measurement_id: "",
26+
app_instance_id: "",
27+
firebase_app_id: "",
28+
api_secret: "",
29+
client_id: "",
30+
user_id: "",
31+
formatPayload: jest.fn(),
32+
payloadErrors: undefined,
33+
useTextBox: false,
34+
}
35+
36+
// A helper to render the component with context.
37+
const renderComponent = (props: Partial<ValidateEventProps> = {}) => {
38+
// The component relies on EventCtx for some data. This should be a valid
39+
// EventPayload.
40+
const contextValue: EventPayload = {
41+
instanceId: {
42+
measurement_id: "G-12345",
43+
firebase_app_id: "app:12345",
44+
},
45+
eventName: "test_event",
46+
type: EventType.CustomEvent,
47+
parameters: [],
48+
items: [],
49+
userProperties: [],
50+
timestamp_micros: "",
51+
non_personalized_ads: false,
52+
useTextBox: false,
53+
payloadObj: [],
54+
api_secret: "secret123",
55+
clientIds: {},
56+
}
57+
58+
return render(
59+
<EventCtx.Provider value={contextValue}>
60+
<ValidateEvent {...defaultProps} {...props} />
61+
</EventCtx.Provider>
62+
)
63+
}
64+
65+
describe("ValidateEvent EU endpoint functionality", () => {
66+
beforeEach(() => {
67+
// Reset mocks before each test
68+
jest.clearAllMocks()
69+
// Setup the default mock implementation for useValidateEvent to render the initial state.
70+
mockedUseValidateEvent.mockReturnValue({
71+
status: "not-started",
72+
validateEvent: mockValidateEventFn,
73+
})
74+
})
75+
76+
it("should render with the default endpoint and allow switching to the EU endpoint", () => {
77+
renderComponent()
78+
79+
// 1. Check initial state (default endpoint)
80+
expect(screen.getByText("HOST: www.google-analytics.com", { exact: false })).toBeInTheDocument()
81+
expect(screen.queryByText("HOST: region1.google-analytics.com", { exact: false })).not.toBeInTheDocument()
82+
expect(mockedUseValidateEvent).toHaveBeenCalledWith(false)
83+
84+
// 2. Find and interact with the switch
85+
const euSwitch = within(screen.getByTestId("use-eu-endpoint")).getByRole('checkbox')
86+
expect(euSwitch).toHaveProperty('checked', false)
87+
fireEvent.click(euSwitch)
88+
89+
// 3. Check the new state (EU endpoint)
90+
expect(euSwitch).toHaveProperty('checked', true)
91+
expect(screen.getByText("HOST: region1.google-analytics.com", { exact: false })).toBeInTheDocument()
92+
expect(mockedUseValidateEvent).toHaveBeenCalledTimes(2)
93+
expect(mockedUseValidateEvent).toHaveBeenLastCalledWith(true)
94+
})
95+
})

0 commit comments

Comments
 (0)