Skip to content

Commit

Permalink
feat(forum_upvote): update icon and title for upvotes
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Jul 25, 2023
1 parent d3462cc commit ddec93f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lacommunaute/forum_conversation/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def test_post_has_no_upvote(self):

response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, '<i class="ri-star-line" aria-hidden="true"></i><span class="ml-1">0</span>')
self.assertContains(response, '<i class="ri-bookmark-line" aria-hidden="true"></i><span class="ml-1">0</span>')

def test_post_has_upvote_by_user(self):
PostFactory(topic=self.topic, poster=self.poster)
Expand All @@ -437,7 +437,7 @@ def test_post_has_upvote_by_user(self):

response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, '<i class="ri-star-fill" aria-hidden="true"></i><span class="ml-1">1</span>')
self.assertContains(response, '<i class="ri-bookmark-fill" aria-hidden="true"></i><span class="ml-1">1</span>')

def test_certified_post_is_highlighted(self):
post = PostFactory(topic=self.topic, poster=self.poster)
Expand Down
6 changes: 3 additions & 3 deletions lacommunaute/forum_conversation/tests/tests_views_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ def test_upvote_annotations(self):

response = view.get(request)
self.assertEqual(response.status_code, 200)
self.assertContains(response, '<i class="ri-star-line" aria-hidden="true"></i><span class="ml-1">0</span>')
self.assertContains(response, '<i class="ri-bookmark-line" aria-hidden="true"></i><span class="ml-1">0</span>')

UpVoteFactory(content_object=post, voter=UserFactory())
UpVoteFactory(content_object=post, voter=self.user)

response = view.get(request)
self.assertEqual(response.status_code, 200)
self.assertContains(response, '<i class="ri-star-fill" aria-hidden="true"></i><span class="ml-1">2</span>')
self.assertContains(response, '<i class="ri-bookmark-fill" aria-hidden="true"></i><span class="ml-1">2</span>')

def test_certified_post_highlight(self):
post = PostFactory(topic=self.topic, poster=self.user)
Expand Down Expand Up @@ -430,7 +430,7 @@ def test_create_post_as_authenticated_user(self, *args):
self.assertContains(response, self.content)
self.assertIsInstance(response.context["form"], PostForm)
self.assertEqual(1, ForumReadTrack.objects.count())
self.assertContains(response, '<i class="ri-star-line" aria-hidden="true"></i><span class="ml-1">0</span>')
self.assertContains(response, '<i class="ri-bookmark-line" aria-hidden="true"></i><span class="ml-1">0</span>')
self.topic.refresh_from_db()
self.assertEqual(self.topic.posts.count(), 2)
self.assertEqual(
Expand Down
4 changes: 2 additions & 2 deletions lacommunaute/forum_upvote/tests/test_forumupvoteview.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def test_upvote_downvote_with_permission(client, db):
# upvote
response = client.post(url, data=form_data)
assert response.status_code == 200
assert '<i class="ri-star-fill" aria-hidden="true"></i><span class="ml-1">1</span>' in str(response.content)
assert '<i class="ri-bookmark-fill" aria-hidden="true"></i><span class="ml-1">1</span>' in str(response.content)
assert UpVote.objects.get(
voter_id=user.id, object_id=forum.id, content_type=ContentType.objects.get_for_model(forum)
)

# downvote
response = client.post(url, data=form_data)
assert response.status_code == 200
assert '<i class="ri-star-line" aria-hidden="true"></i><span class="ml-1">0</span>' in str(response.content)
assert '<i class="ri-bookmark-line" aria-hidden="true"></i><span class="ml-1">0</span>' in str(response.content)
assert not UpVote.objects.all()


Expand Down
4 changes: 2 additions & 2 deletions lacommunaute/forum_upvote/tests/test_postupvoteview.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_upvote_with_permission(client, db):
# upvote
response = client.post(url, data=form_data)
assert response.status_code == 200
assert '<i class="ri-star-fill" aria-hidden="true"></i><span class="ml-1">1</span>' in str(response.content)
assert '<i class="ri-bookmark-fill" aria-hidden="true"></i><span class="ml-1">1</span>' in str(response.content)
assert UpVote.objects.get(
voter_id=user.id,
object_id=topic.first_post.id,
Expand All @@ -45,7 +45,7 @@ def test_upvote_with_permission(client, db):
# downvote
response = client.post(url, data=form_data)
assert response.status_code == 200
assert '<i class="ri-star-line" aria-hidden="true"></i><span class="ml-1">0</span>' in str(response.content)
assert '<i class="ri-bookmark-line" aria-hidden="true"></i><span class="ml-1">0</span>' in str(response.content)
assert not UpVote.objects.all()


Expand Down
11 changes: 5 additions & 6 deletions lacommunaute/templates/partials/upvotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@
<input type='hidden' name='pk' value="{{obj.pk}}"/>

<button type="submit"
class="btn btn-ico btn-link px-0 text-nowrap matomo-event"
title="{% trans "UpVotes" %}"
class="btn btn-sm btn-ico-only btn-secondary matomo-event"
data-matomo-category="engagement"
data-matomo-action="upvote"
data-matomo-option="post"
>
<span class="mr-1">{% trans "UpVotes" %}</span>
<i class="{% if obj.has_upvoted %}ri-star-fill{% else %}ri-star-line{% endif %}" aria-hidden="true"></i><span class="ml-1">{{counter}}</span>
<i class="{% if obj.has_upvoted %}ri-bookmark-fill{% else %}ri-bookmark-line{% endif %}" aria-hidden="true"></i><span class="ml-1">{{counter}}</span>
</button>
</form>
{% else %}
<a href="{% inclusion_connect_url next_url obj.id %}" class="btn btn-ico btn-link pr-0 text-nowrap" data-toggle="tooltip" data-placement="top" title="Connectez-vous pour contribuer">
<span class="mr-1">{% trans "UpVotes" %}</span>
<i class="{% if obj.has_upvoted %}ri-star-fill{% else %}ri-star-line{% endif %}" aria-hidden="true"></i><span class="ml-1">{{counter}}</span>
<a href="{% inclusion_connect_url next_url obj.id %}" class="btn btn-sm btn-ico-only btn-link btn-secondary" data-toggle="tooltip" data-placement="top" title="Connectez-vous pour sauvegarder">
<i class="{% if obj.has_upvoted %}ri-bookmark-fill{% else %}ri-bookmark-line{% endif %}" aria-hidden="true"></i><span class="ml-1">{{counter}}</span>
</a>
{% endif %}
{% endwith %}
Expand Down

0 comments on commit ddec93f

Please sign in to comment.