From d9a5c4e9ceca47126a919ee360b1938bc15a61fe Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Wed, 27 Nov 2024 07:39:16 +0100 Subject: [PATCH] Build assets before integration test --- .github/workflows/test.yml | 2 + tests/integration/conftest.py | 93 ++++++++++++++------------- tests/integration/test_text_editor.py | 8 ++- 3 files changed, 58 insertions(+), 45 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4759f02..37a639c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,6 +29,8 @@ jobs: python -m pip install --upgrade pip pip install -r tests/requirements/${{ matrix.requirements-file }} python setup.py install + npm install + npx webpack playwright install --with-deps - name: Run coverage diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 848997d..9a66934 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -5,49 +5,56 @@ from tests.fixtures import DJANGO_CMS4 -if DJANGO_CMS4: - - @pytest.fixture(scope="session") - def live_server(): - server = LiveServer("127.0.0.1:9090") - yield server - server.stop() - - @pytest.fixture(scope="session") - def browser_context(): - with sync_playwright() as p: - browser = p.chromium.launch() - context = browser.new_context() - yield context - context.close() - browser.close() - - @pytest.fixture(scope="session") - def page(browser_context): - page = browser_context.new_page() - yield page - page.close() - - @pytest.fixture - def user(db): - from django.contrib.auth import get_user_model - - User = get_user_model() - return User.objects.create_user(username="admin", password="admin", is_staff=True, is_superuser=True) - - @pytest.fixture - def cms_page(db, user): - from cms.api import create_page - - return create_page("Test Page", "page.html", "en", created_by=user) - - @pytest.fixture - def text_plugin(db, cms_page): - from cms.api import add_plugin - - page_content = cms_page.pagecontent_set(manager="admin_manager").current_content(language="en").first() - placeholder = page_content.get_placeholders().first() - return add_plugin(placeholder, "TextPlugin", "en", body="

Test content

") + +@pytest.fixture(scope="session") +def live_server(): + server = LiveServer("127.0.0.1:9090") + yield server + server.stop() + + +@pytest.fixture(scope="session") +def browser_context(): + with sync_playwright() as p: + browser = p.chromium.launch() + context = browser.new_context() + yield context + context.close() + browser.close() + + +@pytest.fixture(scope="session") +def page(browser_context): + page = browser_context.new_page() + yield page + page.close() + + +@pytest.fixture +def user(db): + from django.contrib.auth import get_user_model + + User = get_user_model() + return User.objects.create_user(username="admin", password="admin", is_staff=True, is_superuser=True) + + +@pytest.fixture +def cms_page(db, user): + from cms.api import create_page + + return create_page("Test Page", "page.html", "en", created_by=user) + + +@pytest.fixture +def text_plugin(db, cms_page): + if not DJANGO_CMS4: + return None + + from cms.api import add_plugin + + page_content = cms_page.pagecontent_set(manager="admin_manager").current_content(language="en").first() + placeholder = page_content.get_placeholders().first() + return add_plugin(placeholder, "TextPlugin", "en", body="

Test content

") def pytest_configure(): diff --git a/tests/integration/test_text_editor.py b/tests/integration/test_text_editor.py index 657895c..e30eb4e 100644 --- a/tests/integration/test_text_editor.py +++ b/tests/integration/test_text_editor.py @@ -28,13 +28,17 @@ def test_editor_loads(live_server, page, text_plugin): login(page, live_server) page.goto(f"{live_server.url}{admin_reverse('cms_placeholder_edit_plugin', args=(text_plugin.pk,))}") - editor = page.locator(".ProseMirror.tiptap") + editor = page.locator(".cms-editor-inline-wrapper.fixed") expect(editor).to_be_visible() # Editor + + tiptap = page.locator(".ProseMirror.tiptap") + expect(tiptap).to_be_visible() # Editor + expect(page.locator('div[role="menubar"]')).to_be_visible() # its menu bar expect(page.locator('button[title="Bold"]')).to_be_visible() # a button in the menu bar - assert editor.inner_text() == "Test content" + assert tiptap.inner_text() == "Test content" @pytest.mark.django_db