Skip to content
Merged
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
7 changes: 4 additions & 3 deletions rdmo/management/assets/js/actions/elementActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { get, isNil } from 'lodash'

import { addToPending, removeFromPending } from 'rdmo/core/assets/js/actions/pendingActions'
import { updateConfig } from 'rdmo/core/assets/js/actions/configActions'
import { siteId } from 'rdmo/core/assets/js/utils/meta'

import ConditionsApi from '../api/ConditionsApi'
import DomainApi from '../api/DomainApi'
Expand Down Expand Up @@ -347,14 +348,14 @@ export function fetchElement(elementType, elementId, elementAction=null) {
return dispatch(action)
.then(elements => {
if (elementAction == 'copy') {
const { settings, currentSite } = getState().config
const { settings } = getState().config

elements.element.id = null
elements.element.read_only = false

if (settings.multisite) {
elements.element.sites = [currentSite.id]
elements.element.editors = [currentSite.id]
elements.element.sites = [siteId]
elements.element.editors = [siteId]
}
}
return dispatch(fetchElementSuccess({ ...elements }))
Expand Down
15 changes: 14 additions & 1 deletion rdmo/management/tests/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from _pytest.fixtures import SubRequest
from playwright.sync_api import Page

from rdmo.core.tests.e2e.conftest import ( # noqa: F401
Expand All @@ -21,7 +22,7 @@ def e2e_username(scope="session") -> str:


@pytest.fixture
def page(django_db_setup, live_server, browser, authenticated_page: Page) -> Page: # noqa: F811
def page_single(django_db_setup, live_server, browser, authenticated_page: Page) -> Page: # noqa: F811
"""Navigates the authenticated page to /management."""
authenticated_page.goto("/management") # Navigate to the projects section
authenticated_page.wait_for_load_state() # maybe not needed
Expand All @@ -35,3 +36,15 @@ def page_multisite(django_db_setup, live_server, browser, authenticated_page: Pa
authenticated_page.goto("/management") # Navigate to the projects section
authenticated_page.wait_for_load_state() # maybe not needed
return authenticated_page


@pytest.fixture
def page(request, django_db_setup, authenticated_page) -> Page: # noqa: F811
"""Allows for the specific page fixtures to be parameters and returns a default fixture for page"""
try:
return request.getfixturevalue(request.param)
except AttributeError as e:
if isinstance(request, SubRequest) and request.fixturename == "page":
# set a default return fixture for "page"
return request.getfixturevalue("page_multisite")
raise e from e
39 changes: 39 additions & 0 deletions rdmo/management/tests/e2e/test_frontend_management_catalog_copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ruff: noqa: F811
import pytest

from playwright.sync_api import Page, expect

from rdmo.questions.models import Catalog

pytestmark = pytest.mark.e2e


@pytest.mark.parametrize("page", ["page_single", "page_multisite"], indirect=True)
def test_management_catalog_copy(page: Page) -> None:
"""Test that each content type is available through the navigation."""

expect(page.get_by_role("heading", name="Management")).to_be_visible()
expect(page.locator("strong").filter(has_text="Catalogs")).to_be_visible()

# open the copy form: click on the "Copy catalog" button
# page.goto(f"/management/catalogs/1/copy") # goto does not work with auto return after copy
# page.locator('a[title="Copy catalog"]').first.click()
page.get_by_title("Copy catalog").first.click()

# expect the form is there with a URI Prefix field
expect(page.get_by_role("textbox", name="URI Prefix")).to_be_visible()

# create a copy of the catalog
page.get_by_role("textbox", name="URI Path").click()
page.get_by_role("textbox", name="URI Path").fill("catalog-copy")
page.get_by_role("textbox", name="Title (English)").click()
page.get_by_role("textbox", name="Title (English)").fill("Catalog copy")
page.get_by_role("button", name="Copy").nth(1).click()
# page.get_by_role("button", name="Copy").nth(1).click()

# assert copy was successful
# page.wait_for_url("/management/catalogs/")
expect(page.locator("strong").filter(has_text="Catalogs")).to_be_visible()
expect(page.get_by_role("link", name="http://example.com/terms/questions/catalog-copy")).to_be_visible()

assert Catalog.objects.filter(uri="http://example.com/terms/questions/catalog-copy").exists()
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
pytestmark = pytest.mark.e2e


@pytest.mark.parametrize("page", ["page_single", "page_multisite"], indirect=True)
@pytest.mark.parametrize("helper", model_helpers)
def test_management_navigation(page: Page, helper: ModelHelper) -> None:
"""Test that each content type is available through the navigation."""
Expand All @@ -35,6 +36,7 @@ def test_management_navigation(page: Page, helper: ModelHelper) -> None:
page.screenshot(path="screenshots/management/navigation-catalog.png", full_page=True)


@pytest.mark.parametrize("page", ["page_single", "page_multisite"], indirect=True)
@pytest.mark.parametrize("helper", model_helpers)
def test_management_has_items(page: Page, helper: ModelHelper) -> None:
"""Test all items in database are visible in management UI."""
Expand All @@ -44,6 +46,7 @@ def test_management_has_items(page: Page, helper: ModelHelper) -> None:
expect(items_in_ui).to_have_count(num_items_in_database)


@pytest.mark.parametrize("page", ["page_single", "page_multisite"], indirect=True)
@pytest.mark.parametrize("helper", model_helpers)
def test_management_nested_view(page: Page, helper: ModelHelper) -> None:
"""For each element type, that has a nested view, click the first example."""
Expand All @@ -55,6 +58,7 @@ def test_management_nested_view(page: Page, helper: ModelHelper) -> None:
expect(page.locator(".panel-default > .panel-body").first).to_be_visible()


@pytest.mark.parametrize("page", ["page_single", "page_multisite"], indirect=True)
@pytest.mark.parametrize("helper", model_helpers)
def test_management_create_model(page: Page, helper: ModelHelper) -> None:
"""Test management UI can create objects in the database."""
Expand Down Expand Up @@ -83,7 +87,7 @@ def test_management_create_model(page: Page, helper: ModelHelper) -> None:
query = {helper.db_field: value}
assert helper.model.objects.get(**query)


@pytest.mark.parametrize("page", ["page_single", "page_multisite"], indirect=True)
@pytest.mark.parametrize("helper", model_helpers)
def test_management_edit_model(page: Page, helper: ModelHelper) -> None:
page.goto(f"/management/{helper.url}")
Expand Down