Skip to content

Commit 37c7075

Browse files
authored
Merge pull request #2359 from dandi/2271-cookies-disabled-banner
Check to see if cookies are enabled for banner message
2 parents 426d879 + 75271ea commit 37c7075

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

e2e/tests/cookies.spec.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { test, expect } from "@playwright/test";
22
import { clientUrl } from "../utils.ts";
33

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

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

25-
// await expect(page.getByText(COOKIE_DISABLED_MESSAGE)).toHaveCount(1);
26-
// await page.getByText("Got it!").click();
27-
// await expect(page.getByText(COOKIE_CONSENT_MESSAGE)).toHaveCount(0);
28-
// });
21+
await expect(page.getByText(COOKIE_DISABLED_MESSAGE)).toHaveCount(1);
22+
await page.getByText("Got it!").click();
23+
await expect(page.getByText(COOKIE_CONSENT_MESSAGE)).toHaveCount(0);
24+
});
2925
});

web/src/components/CookieBanner.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<script setup lang="ts">
22
import { computed, ref } from 'vue';
3+
import {
4+
cookiesEnabled as cookiesEnabledFunc
5+
} from '@/rest';
36
47
const COOKIE_NAME = 'dandi-cookie-consent';
58
@@ -18,6 +21,8 @@ const dandiCookie = computed({
1821
1922
const open = ref(dandiCookie.value !== 'true');
2023
24+
const cookiesEnabled = computed(cookiesEnabledFunc);
25+
2126
function setCookie() {
2227
dandiCookie.value = 'true';
2328
open.value = false;
@@ -43,7 +48,8 @@ function setCookie() {
4348
max-width="60%"
4449
style="left: 50%; transform: translateX(-50%); z-index: 1;"
4550
>
46-
<span>We use cookies to ensure you get the best experience on DANDI.</span>
51+
<span v-if="cookiesEnabled">We use cookies to ensure you get the best experience on DANDI.</span>
52+
<span v-else>We noticed you're blocking cookies - note that certain aspects of the site may not work.</span>
4753
<v-btn
4854
class="bg-error"
4955
elevation="0"

0 commit comments

Comments
 (0)