Fakultas Ilmu Komputer UI

Commit 0a815a6d authored by Ahmad Fauzan Amirul Isnain's avatar Ahmad Fauzan Amirul Isnain
Browse files

Merge branch '1706979152-38' into 'master'

[#38] Materia: Like/Favorite (Contributor View)

Closes #38

See merge request !25
parents 329f1294 5098d09e
Pipeline #58069 passed with stages
in 14 minutes and 34 seconds
......@@ -41,6 +41,10 @@
<span style="font-size: 0.75rem; padding-left: 0.3rem;">{{ post.data.date_created }}</span>
</div>
</div>
<div class="posts-vertically-centered ml-auto pr-4">
<span id="post-like-count-{{post.data.id}}">{{ post.data.like_count }}</span>
<span>Like</span>
</div>
<div class="posts-vertically-centered">
<span>{{ post.comments|length }}</span>
<span>Komentar</span>
......
......@@ -274,6 +274,7 @@ class PostsViewTest(TestCase):
def generate_posts_data(cls, user):
POST_COUNT = 3
COMMENTS_COUNT_PER_POST = [1, 0, 3]
LIKES_COUNT_PER_POST = [5, 4, 2]
assert POST_COUNT == len(COMMENTS_COUNT_PER_POST)
......@@ -281,7 +282,7 @@ class PostsViewTest(TestCase):
sample_category = Category.objects.create(name="Test Category")
post_comment_group_dict = {}
for _ in range(POST_COUNT):
for i in range(POST_COUNT):
post = Materi.objects.create(
uploader=user,
cover=sample_file,
......@@ -294,6 +295,13 @@ class PostsViewTest(TestCase):
"comments": [],
}
for j in range (LIKES_COUNT_PER_POST[i]):
Like.objects.create(
timestamp=datetime.now(),
materi=post,
session_id=("dummysession-" + str(i) + '-' + str(j))
)
for i, post_id in enumerate(post_comment_group_dict):
post = post_comment_group_dict[post_id]["data"]
......@@ -372,6 +380,16 @@ class PostsViewTest(TestCase):
rf'.*(<div id="post-{posts[0]}-comment-{comments[0][0]}">)'
)
def test_like_count_written_correctly_on_template(self):
response = self._request_as_user()
for _, post_id in enumerate(self.data):
post = self.data[post_id]["data"]
self.assertContains(
response,
'<span id="post-like-count-' + str(post.id) + '">' + str(post.like_count) + '</span>',
)
class TemplateLoaderTest(TestCase):
def test_template_loader_url_exist(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment