fix: preserve safe motion and consent failures
This commit is contained in:
1 parent
a4e5e5c048
commit
bea235d6fd
4 files changed
+61
-14
No files matched your search
@@ -240,7 +240,7 @@ describe("GoogleAnalytics consent", () => {
|
||||
|
||||
expect(
|
||||
screen.getByRole("alert", {
|
||||
name: "Falha ao salvar a revogação",
|
||||
name: "Falha ao salvar o consentimento",
|
||||
}),
|
||||
).toHaveTextContent(
|
||||
"Não foi possível salvar a revogação. Tente novamente para concluir.",
|
||||
@@ -250,4 +250,30 @@ describe("GoogleAnalytics consent", () => {
|
||||
screen.getByRole("button", { name: "Revogar analytics" }),
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
it("reports when refusal cannot be persisted", async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.spyOn(Storage.prototype, "setItem").mockImplementation(() => {
|
||||
throw new Error("storage blocked");
|
||||
});
|
||||
render(<GoogleAnalytics />);
|
||||
|
||||
await user.click(
|
||||
await screen.findByRole("button", { name: "Recusar analytics" }),
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByRole("alert", {
|
||||
name: "Falha ao salvar o consentimento",
|
||||
}),
|
||||
).toHaveTextContent(
|
||||
"Não foi possível salvar sua recusa. Tente novamente para concluir.",
|
||||
);
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Recusar analytics" }),
|
||||
).toBeVisible();
|
||||
expect(
|
||||
screen.queryByRole("button", { name: "Preferências de analytics" }),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -98,7 +98,7 @@ const buttonClassName =
|
||||
function GoogleAnalyticsConsent() {
|
||||
const [consent, setConsent] = useState<AnalyticsConsent | null>();
|
||||
const [preferencesOpen, setPreferencesOpen] = useState(false);
|
||||
const [revokeError, setRevokeError] = useState<string | null>(null);
|
||||
const [consentError, setConsentError] = useState<string | null>(null);
|
||||
const configuredRef = useRef(false);
|
||||
const preferencesButtonRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
@@ -138,26 +138,38 @@ function GoogleAnalyticsConsent() {
|
||||
}
|
||||
|
||||
function acceptAnalytics() {
|
||||
if (!persistConsent("granted")) return;
|
||||
if (!persistConsent("granted")) {
|
||||
setConsentError(
|
||||
"Não foi possível salvar sua aceitação. Tente novamente para concluir.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
setConsentError(null);
|
||||
enableAnalytics();
|
||||
setConsent("granted");
|
||||
closePreferences();
|
||||
}
|
||||
|
||||
function denyAnalytics() {
|
||||
persistConsent("denied");
|
||||
if (!persistConsent("denied")) {
|
||||
setConsentError(
|
||||
"Não foi possível salvar sua recusa. Tente novamente para concluir.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
setConsentError(null);
|
||||
setConsent("denied");
|
||||
closePreferences();
|
||||
}
|
||||
|
||||
function revokeAnalytics() {
|
||||
if (!persistConsent("denied")) {
|
||||
setRevokeError(
|
||||
setConsentError(
|
||||
"Não foi possível salvar a revogação. Tente novamente para concluir.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
setRevokeError(null);
|
||||
setConsentError(null);
|
||||
window[GA_DISABLE_KEY] = true;
|
||||
window.gtag?.("consent", "update", deniedConsent);
|
||||
expireAnalyticsCookies();
|
||||
@@ -189,6 +201,15 @@ function GoogleAnalyticsConsent() {
|
||||
Você decide se permite métricas anônimas para melhorar este site.
|
||||
Publicidade e personalização continuam desativadas.
|
||||
</p>
|
||||
{consentError && (
|
||||
<p
|
||||
role="alert"
|
||||
aria-label="Falha ao salvar o consentimento"
|
||||
className="mt-sp-3 text-[13px] leading-6 text-[var(--slash)]"
|
||||
>
|
||||
{consentError}
|
||||
</p>
|
||||
)}
|
||||
<div className="mt-sp-4 flex flex-wrap gap-sp-2">
|
||||
<button
|
||||
type="button"
|
||||
@@ -257,13 +278,13 @@ function GoogleAnalyticsConsent() {
|
||||
Analytics está {consent === "granted" ? "ativo" : "desativado"}.
|
||||
Dados de publicidade permanecem negados.
|
||||
</p>
|
||||
{revokeError && (
|
||||
{consentError && (
|
||||
<p
|
||||
role="alert"
|
||||
aria-label="Falha ao salvar a revogação"
|
||||
aria-label="Falha ao salvar o consentimento"
|
||||
className="mt-sp-3 text-[13px] leading-6 text-[var(--slash)]"
|
||||
>
|
||||
{revokeError}
|
||||
{consentError}
|
||||
</p>
|
||||
)}
|
||||
<div className="mt-sp-4 flex flex-wrap gap-sp-2">
|
||||
|
||||
@@ -133,7 +133,7 @@ describe("ControlRoomGlobe lifecycle", () => {
|
||||
expect(state.height).toBe(1040);
|
||||
});
|
||||
|
||||
it("keeps the reduced-motion globe static", async () => {
|
||||
it("keeps the reduced-motion globe static while tracking dimensions", async () => {
|
||||
render(<ControlRoomGlobe autoRotate={false} />);
|
||||
await waitFor(() => expect(createGlobe).toHaveBeenCalled());
|
||||
setGlobeIntersects(true);
|
||||
@@ -141,6 +141,6 @@ describe("ControlRoomGlobe lifecycle", () => {
|
||||
|
||||
renderCallback()(state);
|
||||
|
||||
expect(state).toEqual({ phi: 0, theta: 0, width: 0, height: 0 });
|
||||
expect(state).toEqual({ phi: 0, theta: 0, width: 800, height: 800 });
|
||||
});
|
||||
});
|
||||
@@ -123,6 +123,9 @@ export function ControlRoomGlobe({
|
||||
width: initialRenderWidth,
|
||||
height: initialRenderWidth,
|
||||
onRender: (state) => {
|
||||
const renderWidth = widthRef.current * dpr;
|
||||
state.width = renderWidth;
|
||||
state.height = renderWidth;
|
||||
if (!autoRotate || !intersectsRef.current || document.hidden)
|
||||
return;
|
||||
if (!pointerInteracting.current) {
|
||||
@@ -135,9 +138,6 @@ export function ControlRoomGlobe({
|
||||
(config.theta ?? TROPIC_OF_CAPRICORN_RAD) +
|
||||
Math.sin(thetaPhaseRef.current) * 0.35 +
|
||||
thetaDragRef.current;
|
||||
const renderWidth = widthRef.current * dpr;
|
||||
state.width = renderWidth;
|
||||
state.height = renderWidth;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user