@kiva/kv-components 3.64.0 → 3.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.65.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.64.0...@kiva/kv-components@3.65.0) (2024-03-19)
7
+
8
+
9
+ ### Features
10
+
11
+ * logged in feats for commenting components ([#370](https://github.com/kiva/kv-ui-elements/issues/370)) ([bee56c9](https://github.com/kiva/kv-ui-elements/commit/bee56c9fa3451ef91e89b3b64a5f7846840fedcf))
12
+
13
+
14
+
15
+
16
+
6
17
  # [3.64.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.63.1...@kiva/kv-components@3.64.0) (2024-03-18)
7
18
 
8
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiva/kv-components",
3
- "version": "3.64.0",
3
+ "version": "3.65.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -75,5 +75,5 @@
75
75
  "optional": true
76
76
  }
77
77
  },
78
- "gitHead": "45a8ab6c3566690a670f9a836cc8b71b9f7fddc5"
78
+ "gitHead": "fc9dab72dc150db1190d3d1ca6603eab7c24842a"
79
79
  }
@@ -3,18 +3,25 @@ import userEvent from '@testing-library/user-event';
3
3
  import Container, { ADD_REACTION_EVENT } from '../../../../vue/KvCommentsContainer.vue';
4
4
  import { ADD_COMMENT_ID, ADD_COMMENT_EVENT } from '../../../../vue/KvCommentsAdd.vue';
5
5
 
6
+ const LOGGED_IN_USER = 'TEST_USER';
7
+
6
8
  const renderContainer = (props = {}) => {
7
9
  return render(Container, { props });
8
10
  };
9
11
 
10
12
  describe('KvCommentsContainer', () => {
11
- it('should render comments add component', async () => {
13
+ it('should not render comments add component for guest user', async () => {
12
14
  const { container } = renderContainer();
15
+ expect(container.querySelectorAll(`#${ADD_COMMENT_ID}`).length).toBe(0);
16
+ });
17
+
18
+ it('should render comments add component for logged in user', async () => {
19
+ const { container } = renderContainer({ userPublicId: LOGGED_IN_USER });
13
20
  expect(container.querySelectorAll(`#${ADD_COMMENT_ID}`).length).toBe(1);
14
21
  });
15
22
 
16
- it('should emit comment', async () => {
17
- const { getByPlaceholderText, getByRole, emitted } = renderContainer();
23
+ it('should emit comment for logged in user', async () => {
24
+ const { getByPlaceholderText, getByRole, emitted } = renderContainer({ userPublicId: LOGGED_IN_USER });
18
25
  const textInput = getByPlaceholderText('Add a comment...');
19
26
  const commentButton = getByRole('button', { name: 'Comment' });
20
27
  const TEST_INPUT = 'test test';
@@ -5,6 +5,8 @@ import activityFeed from '../../../fixtures/mockFeedActivityData';
5
5
  import { LIKE_COMMENT_EVENT, REPLY_COMMENT_EVENT } from '../../../../vue/KvCommentsListItem.vue';
6
6
  import { ADD_REACTION_EVENT } from '../../../../vue/KvCommentsContainer.vue';
7
7
 
8
+ const LOGGED_IN_USER = 'TEST_USER';
9
+
8
10
  const renderList = (props = {}) => {
9
11
  return render(ListComponent,
10
12
  {
@@ -32,9 +34,17 @@ describe('KvCommentsList', () => {
32
34
  expect(container.querySelectorAll(`#${id}`).length).toBe(1);
33
35
  });
34
36
 
35
- it('should emit like reaction events', async () => {
37
+ it('should not emit like reaction events for guest user', async () => {
36
38
  const { getAllByRole, emitted } = renderList({ comments });
37
39
  const likeButton = getAllByRole('button', { name: 'Like' })[0];
40
+
41
+ await userEvent.click(likeButton);
42
+ expect(emitted()[ADD_REACTION_EVENT]).toEqual(undefined);
43
+ });
44
+
45
+ it('should emit like reaction events for logged in user', async () => {
46
+ const { getAllByRole, emitted } = renderList({ comments, userPublicId: LOGGED_IN_USER });
47
+ const likeButton = getAllByRole('button', { name: 'Like' })[0];
38
48
  const firstComment = comments.comment[0];
39
49
 
40
50
  const TEST_OBJ = {
@@ -46,13 +56,13 @@ describe('KvCommentsList', () => {
46
56
  expect(emitted()[ADD_REACTION_EVENT]).toEqual([[{ ...TEST_OBJ, reaction: LIKE_COMMENT_EVENT, value: true }]]);
47
57
  });
48
58
 
49
- it('should emit reply reaction events', async () => {
59
+ it('should emit reply reaction events for logged in user', async () => {
50
60
  const {
51
61
  getAllByRole,
52
62
  getByRole,
53
63
  getByPlaceholderText,
54
64
  emitted,
55
- } = renderList({ comments });
65
+ } = renderList({ comments, userPublicId: LOGGED_IN_USER });
56
66
  const replyButton = getAllByRole('button', { name: 'Reply' })[0];
57
67
  const firstComment = comments.comment[0];
58
68
 
@@ -5,6 +5,7 @@ import activityFeed from '../../../fixtures/mockFeedActivityData';
5
5
  import { ADD_REACTION_EVENT } from '../../../../vue/KvCommentsContainer.vue';
6
6
 
7
7
  const comment = activityFeed.results[0].latest_reactions.comment[0];
8
+ const LOGGED_IN_USER = 'TEST_USER';
8
9
 
9
10
  const renderComment = (props = {}) => {
10
11
  return render(KvCommentsListItem,
@@ -24,8 +25,15 @@ const renderComment = (props = {}) => {
24
25
  };
25
26
 
26
27
  describe('KvCommentsListItem', () => {
27
- it('should render defaults', () => {
28
+ it('should render defaults for guest user', () => {
28
29
  const { getAllByRole } = renderComment({ comment });
30
+ const likeButton = getAllByRole('button', { name: 'Like' })[0];
31
+
32
+ expect(likeButton).toBeDefined();
33
+ });
34
+
35
+ it('should render defaults for logged in user', () => {
36
+ const { getAllByRole } = renderComment({ comment, userPublicId: LOGGED_IN_USER });
29
37
  const replyButton = getAllByRole('button', { name: 'Reply' })[0];
30
38
  const likeButton = getAllByRole('button', { name: 'Like' })[0];
31
39
 
@@ -38,13 +46,24 @@ describe('KvCommentsListItem', () => {
38
46
  getByText(comment.data.text);
39
47
  });
40
48
 
41
- it('should handle like button click', async () => {
49
+ it('should not handle like button click for guest user', async () => {
42
50
  const { getAllByRole, emitted, getByTestId } = renderComment({ comment });
43
51
  const likeButton = getAllByRole('button', { name: 'Like' })[0];
44
52
  const likeCount = getByTestId('like-count');
45
53
 
46
54
  await userEvent.click(likeButton);
47
55
 
56
+ expect(likeCount).toHaveTextContent(1);
57
+ expect(emitted()[ADD_REACTION_EVENT]).toEqual(undefined);
58
+ });
59
+
60
+ it('should handle like button click for logged in user', async () => {
61
+ const { getAllByRole, emitted, getByTestId } = renderComment({ comment, userPublicId: LOGGED_IN_USER });
62
+ const likeButton = getAllByRole('button', { name: 'Like' })[0];
63
+ const likeCount = getByTestId('like-count');
64
+
65
+ await userEvent.click(likeButton);
66
+
48
67
  expect(likeCount).toHaveTextContent(1);
49
68
  expect(emitted()[ADD_REACTION_EVENT]).toEqual([[{
50
69
  id: comment.id,
@@ -54,21 +73,21 @@ describe('KvCommentsListItem', () => {
54
73
  }]]);
55
74
  });
56
75
 
57
- it('should handle reply button click', async () => {
58
- const { getAllByRole, getByRole } = renderComment({ comment });
76
+ it('should handle reply button click for logged in user', async () => {
77
+ const { getAllByRole, getByRole } = renderComment({ comment, userPublicId: LOGGED_IN_USER });
59
78
  const replyButton = getAllByRole('button', { name: 'Reply' })[0];
60
79
 
61
80
  await userEvent.click(replyButton);
62
81
  getByRole('button', { name: 'Comment' });
63
82
  });
64
83
 
65
- it('should emit reply reaction events', async () => {
84
+ it('should emit reply reaction events for logged in user', async () => {
66
85
  const {
67
86
  getAllByRole,
68
87
  getByRole,
69
88
  getByPlaceholderText,
70
89
  emitted,
71
- } = renderComment({ comment });
90
+ } = renderComment({ comment, userPublicId: LOGGED_IN_USER });
72
91
  const replyButton = getAllByRole('button', { name: 'Reply' })[0];
73
92
 
74
93
  const TEST_OBJ = {
@@ -1,6 +1,7 @@
1
1
  <template>
2
2
  <div>
3
3
  <kv-comments-add
4
+ v-if="userPublicId"
4
5
  :user-image-url="userImageUrl"
5
6
  :user-display-name="userDisplayName"
6
7
  @add-comment="handleReaction"
@@ -26,6 +26,7 @@
26
26
  <kv-comments-heart-button
27
27
  :is-small="true"
28
28
  :is-liked="isLiked"
29
+ :disabled="!userPublicId"
29
30
  @click="addReaction(LIKE_COMMENT_EVENT, $event)"
30
31
  />
31
32
  <p
@@ -37,6 +38,7 @@
37
38
  </p>
38
39
  </div>
39
40
  <kv-comments-reply-button
41
+ v-if="userPublicId"
40
42
  :number-of-replies="numberOfReplies"
41
43
  @click="replyClick"
42
44
  />