Skip to content

Commit

Permalink
debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed May 9, 2024
1 parent b24a095 commit 91cf8e3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cookie_consent/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class CookieStatusView(View):
"""

def get(self, request: HttpRequest) -> JsonResponse:
print("GET cookie status")
accepted = get_accepted_cookie_groups(request)
declined = get_declined_cookie_groups(request)
not_accepted_or_declined = get_not_accepted_or_declined_cookie_groups(request)
Expand All @@ -114,4 +115,6 @@ def get(self, request: HttpRequest) -> JsonResponse:
group.varname for group in not_accepted_or_declined
],
}
print("RESPONSE cookie status")
print(data)
return JsonResponse(data)
8 changes: 7 additions & 1 deletion js/src/cookiebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export const showCookieBar = async (options: Partial<Options> = {}): Promise<voi

const client = new FetchClient(statusUrl, csrfHeaderName);
const cookieStatus = await client.getCookieStatus();
console.log('Retrieved cookie status', cookieStatus);

// calculate the cookie groups to invoke the callbacks. We deliberately fire those
// without awaiting so that our cookie bar is shown/hidden as soon as possible.
Expand All @@ -296,7 +297,12 @@ export const showCookieBar = async (options: Partial<Options> = {}): Promise<voi
} = cookieStatus;

const acceptedGroups = filterCookieGroups(cookieGroups, acceptedCookieGroups);
if (acceptedGroups.length) onAccept?.(acceptedGroups);
if (acceptedGroups.length) {
console.log('Accepted groups: ', acceptedGroups);
console.log('Calling onAccept');
onAccept?.(acceptedGroups);
console.log('Called onAccept');
}
const declinedGroups = filterCookieGroups(cookieGroups, declinedCookieGroups);
if (declinedGroups.length) onDecline?.(declinedGroups);

Expand Down
7 changes: 7 additions & 0 deletions tests/test_javascript_cookiebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@pytest.fixture(scope="function", autouse=True)
def before_each_after_each(live_server, page: Page, load_testapp_fixture):
page.on("console", lambda msg: print(f"CONSOLE OUTPUT: {msg.text}"))
test_page_url = f"{live_server.url}{reverse('test_page')}"
page.goto(test_page_url)
marker = page.get_by_text("page-done-loading")
Expand Down Expand Up @@ -71,11 +72,17 @@ def test_cookiebar_not_shown_anymore_after_accept_or_decline(btn_text: str, page
def test_on_accept_handler_runs_on_load(page: Page, live_server):
accept_button = page.get_by_role("button", name="Accept")
accept_button.click()
# wait for fetch calls to complete & avoid test race conditions...
share_button = page.get_by_role("button", name="SHARE")
expect(share_button).to_be_visible()

test_page_url = f"{live_server.url}{reverse('test_page')}"
page.goto(test_page_url)
print("GOTO PAGE")
marker = page.get_by_text("page-done-loading")
expect(marker).to_be_visible()
print("PAGE DONE LOADING")

share_button = page.get_by_role("button", name="SHARE")
print("CHECKING SHARE BUTTON")
expect(share_button).to_be_visible()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extras =
deps =
Django~=4.2.0
commands =
pytest tests \
pytest --verbose -s tests \
--cov --cov-report xml:reports/coverage-{envname}.xml \
{posargs}

Expand Down

0 comments on commit 91cf8e3

Please sign in to comment.