Skip to content
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
run: |
python -m pip install --upgrade pip setuptools
python -m pip install -r requirements/tests.txt
- name: Install playwright browsers
run: |
python -m playwright install --with-deps
- name: Set up databases
run: |
PGPASSWORD="postgres" createuser -U postgres -d djangoproject --superuser -h localhost
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ COPY ./requirements ./requirements
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends ${BUILD_DEPENDENCIES} \
&& python3 -m pip install --no-cache-dir -r ${REQ_FILE} \
&& if [ "${REQ_FILE}" = "requirements/tests.txt" ]; then \
echo "Installing Playwright browsers..."; \
playwright install --with-deps; \
fi \
&& apt-get purge --assume-yes --auto-remove ${BUILD_DEPENDENCIES} \
&& apt-get distclean

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ APP_LIST ?= accounts aggregator blog contact dashboard djangoproject docs founda
SCSS = djangoproject/scss
STATIC = djangoproject/static

ci: compilemessages test
ci: compilemessages collectstatics test
@python -m coverage report

compilemessages:
Expand Down
52 changes: 52 additions & 0 deletions djangoproject/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import os
from http import HTTPStatus
from io import StringIO

from django.conf import settings
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.core.management import call_command
from django.test import TestCase
from django.urls import NoReverseMatch, get_resolver
from django.utils.translation import activate, gettext as _
from django_hosts.resolvers import reverse
from playwright.sync_api import expect, sync_playwright

from docs.models import DocumentRelease, Release

Expand Down Expand Up @@ -211,3 +214,52 @@ def test_single_h1_per_page(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "<h1", count=1)


class EndToEndTests(ReleaseMixin, StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
super().setUpClass()
cls.playwright = sync_playwright().start()
cls.browser = cls.playwright.chromium.launch()

@classmethod
def tearDownClass(cls):
super().tearDownClass()
cls.browser.close()
cls.playwright.stop()

def setUp(self):
self.setUpTestData()
self.mac_user_agent = "Mozilla/5.0 (Macintosh) AppleWebKit"
self.windows_user_agent = "Mozilla/5.0 (Windows NT 10.0)"
self.mobile_linux_user_agent = "Mozilla/5.0 (Linux; Android 10; Mobile)"

def test_search_ctrl_k_hotkey(self):
page1 = self.browser.new_page(user_agent=self.windows_user_agent)
page2 = self.browser.new_page(
user_agent=self.mobile_linux_user_agent,
viewport={"width": 375, "height": 812},
)
for page in [page1, page2]:
with self.subTest(page=page):
page.goto(self.live_server_url)
search_bar = page.locator("#id_q")
expect(search_bar).to_have_attribute("placeholder", "Search (Ctrl+K)")
is_focused = page.evaluate("document.activeElement.id === 'id_q'")
self.assertFalse(is_focused)

page.keyboard.press("Control+KeyK")
is_focused = page.evaluate("document.activeElement.id === 'id_q'")
self.assertTrue(is_focused)
page.close()

def test_search_placeholder_mac_mode(self):
page = self.browser.new_page(user_agent=self.mac_user_agent)
page.goto(self.live_server_url)

desktop_search_bar = page.locator("#id_q")
expect(desktop_search_bar).to_have_attribute("placeholder", "Search (⌘\u200aK)")

page.close()
1 change: 1 addition & 0 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-r dev.txt
coverage==7.13.1
playwright==1.57.0
requests-mock==1.12.1
tblib>=3.0.0
Loading