Skip to content

Commit

Permalink
feat(forum/tests): ajout des tests snapshots pour ForumDetail et Foru…
Browse files Browse the repository at this point in the history
…mDocumentationCategory
  • Loading branch information
calummackervoy committed Jul 2, 2024
1 parent 78400c1 commit dd3a862
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lacommunaute/forum/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Meta:

class Params:
with_image = factory.Trait(image=factory.django.ImageField(filename="banner.jpg"))
for_snapshot = factory.Trait(name="Test Forum", description="Test description")
for_snapshot = factory.Trait(
name="Test Forum", description="Test description", short_description="Test description"
)

@factory.post_generation
def with_public_perms(self, create, extracted, **kwargs):
Expand Down
94 changes: 94 additions & 0 deletions lacommunaute/forum/tests/__snapshots__/tests_views.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,45 @@
</nav>
'''
# ---
# name: TestDocumentationCategoryForumContent.test_documentation_category_foot_content[documentation_category_add_file_control]
'''
<section class="s-section" id="add-documentation-to-category-control">
<div class="s-section__container container">
<div class="s-section__row row">
<div class="s-section__col col-12">
<a aria-label="Ajouter une fiche pratique" class="btn btn-outline-primary" href="/documentation/category/9999/create/" role="button">Ajouter une fiche pratique</a>
</div>
</div>
</div>
</section>
'''
# ---
# name: TestDocumentationCategoryForumContent.test_documentation_category_subforum_list[documentation_category_subforum_list]
'''
<div class="row mt-4" id="documentation-category-subforums">

<div class="col-12 col-md-4 mb-3 mb-md-5">
<div class="card c-card has-one-link-inside h-100">

<div class="card-header card-header-thumbnail rounded">
<img alt="Test Forum" class="img-fitcover img-fluid" loading="lazy" src="[img src]"/>
</div>

<div class="card-body pb-0">
<p class="h3 lh-base">Test Forum</p>
<div class="mt-3">Test description</div>
</div>
<div class="card-footer text-end">
<a class="btn btn-sm btn-ico btn-link stretched-link matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="fiches_techniques" href="/forum/test-forum-10000/">
<i class="ri-arrow-right-line ri-lg"></i>
</a>
</div>
</div>
</div>

</div>
'''
# ---
# name: TestDocumentationForumContent.test_documentation_forum_header_content[template_documentation_link_to_parent]
'<a class="matomo-event h3 text-decoration-none d-inline-block" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="forum" href="/forum/parent-forum-9999/">Les autres fiches du thème Parent-Forum</a>'
# ---
Expand All @@ -160,6 +199,61 @@
</div>
'''
# ---
# name: TestForumDetailContent.test_forum_detail_foot_content[forum_detail_forum_actions_block]
'''
<div class="col-12 col-sm-auto forum-actions-block">

<a class="btn btn-primary btn-ico matomo-event" data-matomo-action="contribute" data-matomo-category="engagement" data-matomo-option="new_topic" href="/forum/test-forum-10000/topic/create/" rel="nofollow">
<i class="ri-chat-new-line ri-lg"></i>
<span>

Poser une question

</span>
</a>


</div>
'''
# ---
# name: TestForumDetailContent.test_forum_detail_header_content[forum_detail_heading]
'''
<section class="s-title-01 mt-lg-5">
<div class="s-title-01__container container">
<div class="s-title-01__row row">
<div class="s-title-01__col col-12">
<h1>Test Forum</h1>

<h2 class="mt-3">Test description</h2>
</div>
</div>
</div>
</section>
'''
# ---
# name: TestForumDetailContent.test_forum_detail_subforum_content_rendered[forum_detail_subforums]
'''
<ul class="list-group mb-3 mb-md-5">

<li class="list-group-item list-group-item-action d-flex flex-column flex-md-row justify-content-md-between">
<div class="flex-grow-1">
<a class="matomo-event h4 d-block mb-0" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="forum" href="/forum/test-child-10001/">Test-Child</a>
<small class="text-muted">


0 Sujet

-

0 Message

</small>
</div>
</li>

</ul>
'''
# ---
# name: TestForumViewContent.test_not_rated_forum[not_rated_forum]
'''
<div class="mb-5 rating" id="rating-area1">
Expand Down
88 changes: 88 additions & 0 deletions lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,16 @@ def test_rated_forum(self, client, db, snapshot):
reset_forum_sequence = pytest.fixture(reset_model_sequence_fixture(Forum))


@pytest.fixture(name="forum_for_snapshot")
def forum_for_snapshot_fixture():
return ForumFactory(
parent=ForumFactory(with_public_perms=True, name="Parent-Forum"),
with_public_perms=True,
with_image=True,
for_snapshot=True,
)


@pytest.fixture(name="documentation_forum")
def documentation_forum_fixture():
return ForumFactory(
Expand All @@ -559,6 +569,55 @@ def documentation_forum_fixture():
)


class TestForumDetailContent:
def test_template_forum_detail_share_actions(self, client, db, snapshot):
forum = ForumFactory(with_public_perms=True)
response = client.get(forum.get_absolute_url())
content = parse_response_to_soup(response, replace_in_href=[forum])

assert len(content.select(f"#upvotesarea{str(forum.pk)}")) == 0
assert len(content.select(f"#dropdownMenuSocialShare{str(forum.pk)}")) == 0

def test_forum_detail_header_content(self, client, db, snapshot, reset_forum_sequence, forum_for_snapshot):
response = client.get(forum_for_snapshot.get_absolute_url())
content = parse_response_to_soup(response)

assert str(content.select("section.s-title-01")[0]) == snapshot(name="forum_detail_heading")
assert (
len(
content.select(
"div.textarea_cms_md", string=(lambda x: x.startswith(str(forum_for_snapshot.description)[:10]))
)
)
== 1
)

# NOTE: tests no subforum content rendered
assert len(content.select("ul.list-group")) == 0

def test_forum_detail_subforum_content_rendered(
self, client, db, snapshot, reset_forum_sequence, forum_for_snapshot
):
# subforum
ForumFactory(parent=forum_for_snapshot, with_public_perms=True, name="Test-Child", for_snapshot=True)

response = client.get(forum_for_snapshot.get_absolute_url())
content = parse_response_to_soup(response)

subforum_content = content.select("ul.list-group")
assert len(subforum_content) == 1
assert str(subforum_content[0]) == snapshot(name="forum_detail_subforums")

def test_forum_detail_foot_content(self, client, db, snapshot, reset_forum_sequence, forum_for_snapshot):
response = client.get(forum_for_snapshot.get_absolute_url())
content = parse_response_to_soup(response)

assert forum_for_snapshot.is_forum
forum_actions_block = content.select("div.forum-actions-block")
assert len(forum_actions_block) == 1
assert str(forum_actions_block[0]) == snapshot(name="forum_detail_forum_actions_block")


class TestDocumentationForumContent:
def test_documentation_forum_share_actions(self, client, db, snapshot, reset_forum_sequence, documentation_forum):
response = client.get(documentation_forum.get_absolute_url())
Expand Down Expand Up @@ -600,6 +659,35 @@ def test_documentation_forum_header_content(self, client, db, snapshot, reset_fo
assert len(content.find_all("a", href=sibling_forum.get_absolute_url())) == 1


class TestDocumentationCategoryForumContent:
def test_documentation_category_subforum_list(
self, client, db, snapshot, reset_forum_sequence, documentation_forum
):
response = client.get(documentation_forum.parent.get_absolute_url())
content = parse_response_to_soup(response, replace_img_src=True)

subforum_content = content.select("#documentation-category-subforums")
assert len(subforum_content) == 1
assert str(subforum_content[0]) == snapshot(name="documentation_category_subforum_list")

def test_documentation_category_foot_content(
self, client, db, snapshot, reset_forum_sequence, documentation_forum
):
response = client.get(documentation_forum.parent.get_absolute_url())
content = parse_response_to_soup(response)

# require superuser permission
assert len(content.select("#add-documentation-to-category-control")) == 0

client.force_login(UserFactory(is_superuser=True))
response = client.get(documentation_forum.parent.get_absolute_url())
content = parse_response_to_soup(response)

add_documentation_control = content.select("#add-documentation-to-category-control")
assert len(add_documentation_control) == 1
assert str(add_documentation_control[0]) == snapshot(name="documentation_category_add_file_control")


@pytest.fixture(name="discussion_area_forum")
def discussion_area_forum_fixture():
return ForumFactory(with_public_perms=True, name="A Forum")
Expand Down

0 comments on commit dd3a862

Please sign in to comment.