-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add CKEditor integration tests and update dependencies (#32)
Co-authored-by: sourcery-ai[bot] <sourcery-ai[bot]@users.noreply.github.com> Co-authored-by: Fabian Braun <[email protected]>
- Loading branch information
1 parent
1fd3132
commit aa0417e
Showing
7 changed files
with
142 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import os | ||
import pytest | ||
from pytest_django.live_server_helper import LiveServer | ||
from playwright.sync_api import sync_playwright | ||
|
||
from tests.fixtures import 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): | ||
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="<p>Test content</p>") | ||
|
||
|
||
def pytest_configure(): | ||
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from unittest import skipIf | ||
|
||
import pytest | ||
from cms.utils.urlutils import admin_reverse | ||
from playwright.sync_api import expect | ||
|
||
from tests.fixtures import DJANGO_CMS4 | ||
|
||
|
||
def login(page, live_server): | ||
page.goto(f"{live_server.url}/en/admin/") | ||
page.fill("input[name='username']", "admin") | ||
page.fill("input[name='password']", "admin") | ||
page.click("input[type='submit']") | ||
# Ensure success | ||
expect(page.locator("h1", has_text="Site administration")).to_be_visible() | ||
|
||
|
||
def get_pagecontent(cms_page): | ||
return cms_page.pagecontent_set(manager="admin_manager").current_content(language="en").first() | ||
|
||
|
||
@pytest.mark.django_db | ||
@skipIf(not DJANGO_CMS4, reason="Integration tests only work on Django CMS 4") | ||
def test_editor_loads(live_server, page, text_plugin): | ||
"""Test that tiptap editor loads and initializes properly""" | ||
# Navigate to the text plugin add view | ||
login(page, live_server) | ||
|
||
page.goto(f"{live_server.url}{admin_reverse('cms_placeholder_edit_plugin', args=(text_plugin.pk,))}") | ||
|
||
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 tiptap.inner_text() == "Test content" | ||
|
||
|
||
@pytest.mark.django_db | ||
@skipIf(not DJANGO_CMS4, reason="Integration tests only work on Django CMS 4") | ||
def _test_text_plugin_saves(live_server, page): | ||
"""Test that text plugin content saves correctly""" | ||
# Navigate and login (reusing steps from above) | ||
page.goto(f"{live_server.url}/admin/cms/page/add/") | ||
page.fill("input[name='username']", "admin") | ||
page.fill("input[name='password']", "admin") | ||
page.click("input[type='submit']") | ||
|
||
# Add and fill text plugin | ||
page.click("text=Add plugin") | ||
page.click("text=Text") | ||
|
||
iframe_locator = page.frame_locator(".cke_wysiwyg_frame") | ||
iframe_locator.locator("body").fill("Content to save") | ||
|
||
# Save the plugin | ||
page.click("text=Save") | ||
|
||
# Verify saved content | ||
page.reload() | ||
saved_content = iframe_locator.locator("body").inner_text() | ||
assert saved_content == "Content to save" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters