Exemplo n.º 1
0
        public async Task RendersGATrackingCodeBasedOnUsersPreferences(
            bool?allowAnalyticsCookies,
            bool expectGATagsToBeRendered)
        {
            // Arrange
            Cookies.CookieSettings settings = null;
            if (allowAnalyticsCookies != null)
            {
                settings = new Cookies.CookieSettings()
                {
                    AllowAnalyticsCookies = allowAnalyticsCookies.Value
                };
            }

            CookieSettingsProvider.SetPreferencesForCurrentUser(settings);

            // Act
            var response = await HttpClient.GetAsync($"/tests/empty-provider-context");

            // Assert
            var doc = await response.GetDocument();

            var gotGATags = doc.QuerySelectorAll("script")
                            .Where(s => s.GetAttribute("src")?.StartsWith("https://www.googletagmanager.com") == true)
                            .Any();

            gotGATags.Should().Be(expectGATagsToBeRendered);
        }
Exemplo n.º 2
0
        public async Task AllCookiesAccepted_RendersConfirmation()
        {
            // Arrange
            CookieSettingsProvider.SetPreferencesForCurrentUser(null);

            // Act
            var response = await HttpClient.PostAsync("cookies/accept-all?returnUrl=/foo", null);

            // Assert
            var doc = await response.GetDocument();

            doc.GetAllElementsByTestId("cookie-banner-confirmation").Should().NotBeNull();
        }
Exemplo n.º 3
0
        public async Task NoCookiePreferencesSet_RendersCookieBanner()
        {
            // Arrange
            CookieSettingsProvider.SetPreferencesForCurrentUser(null);

            // Act
            var response = await HttpClient.GetAsync($"/tests/empty-provider-context");

            // Assert
            var doc = await response.GetDocument();

            doc.GetAllElementsByTestId("cookie-banner").Should().NotBeNull();
        }
Exemplo n.º 4
0
        public async Task CookiePreferencesSet_DoesNotRenderCookieBanner(bool allowAnalyticsCookies)
        {
            // Arrange
            CookieSettingsProvider.SetPreferencesForCurrentUser(new Cookies.CookieSettings()
            {
                AllowAnalyticsCookies = allowAnalyticsCookies
            });

            // Act
            var response = await HttpClient.GetAsync($"/tests/empty-provider-context");

            // Assert
            var doc = await response.GetDocument();

            doc.GetElementByTestId("cookie-banner").Should().BeNull();
        }