Skip to content

Check to see if cookies are enabled for banner message #2359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions e2e/tests/cookies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, expect } from "@playwright/test";
import { clientUrl } from "../utils.ts";

const COOKIE_CONSENT_MESSAGE = 'We use cookies to ensure you get the best experience on DANDI.';
// const COOKIE_DISABLED_MESSAGE = 'We noticed you\'re blocking cookies - note that certain aspects of the site may not work.';
const COOKIE_DISABLED_MESSAGE = 'We noticed you\'re blocking cookies - note that certain aspects of the site may not work.';

test.describe("Cookie banner behavior", async () => {
test("cookie banner when cookies are enabled", async ({ page }) => {
Expand All @@ -11,19 +11,15 @@ test.describe("Cookie banner behavior", async () => {
await page.getByText("Got it!").click();
await expect(page.getByText(COOKIE_CONSENT_MESSAGE)).toHaveCount(0);
});
// See: https://github.com/dandi/dandi-archive/issues/2271
//
// test("cookie banner when cookies are disabled", async ({ page }) => {
// Patch navigator.cookieEnabled. This is the condition used to determine which
// cookie banner message to show the end user.
test("cookie banner when cookies are disabled", async ({ page }) => {
// https://github.com/microsoft/playwright/issues/30115#issuecomment-2020821987
// await page.addInitScript(() => {
// Object.defineProperty(navigator.__proto__, "cookieEnabled", { get: () => false });
// });
// await page.goto(clientUrl);
await page.addInitScript(() => {
Object.defineProperty(navigator.__proto__, "cookieEnabled", { get: () => false });
});
await page.goto(clientUrl);

// await expect(page.getByText(COOKIE_DISABLED_MESSAGE)).toHaveCount(1);
// await page.getByText("Got it!").click();
// await expect(page.getByText(COOKIE_CONSENT_MESSAGE)).toHaveCount(0);
// });
await expect(page.getByText(COOKIE_DISABLED_MESSAGE)).toHaveCount(1);
await page.getByText("Got it!").click();
await expect(page.getByText(COOKIE_CONSENT_MESSAGE)).toHaveCount(0);
});
});
8 changes: 7 additions & 1 deletion web/src/components/CookieBanner.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import {
cookiesEnabled as cookiesEnabledFunc
} from '@/rest';
const COOKIE_NAME = 'dandi-cookie-consent';
Expand All @@ -18,6 +21,8 @@ const dandiCookie = computed({
const open = ref(dandiCookie.value !== 'true');
const cookiesEnabled = computed(cookiesEnabledFunc);
function setCookie() {
dandiCookie.value = 'true';
open.value = false;
Expand All @@ -43,7 +48,8 @@ function setCookie() {
max-width="60%"
style="left: 50%; transform: translateX(-50%); z-index: 1;"
>
<span>We use cookies to ensure you get the best experience on DANDI.</span>
<span v-if="cookiesEnabled">We use cookies to ensure you get the best experience on DANDI.</span>
<span v-else>We noticed you're blocking cookies - note that certain aspects of the site may not work.</span>
<v-btn
class="bg-error"
elevation="0"
Expand Down