Add comment count to room entry widget, with test

Resolves MS-344
This commit is contained in:
Ramon Wenger 2022-06-28 13:45:26 +02:00
parent 866e6f718c
commit a3bcd6f314
4 changed files with 68 additions and 68 deletions

View File

@ -163,7 +163,7 @@ describe('The Room Page (Teacher)', () => {
cy.getByDataCy('room-widget').first().click(); cy.getByDataCy('room-widget').first().click();
cy.getByDataCy('toggle-more-actions-menu').click(); cy.getByDataCy('toggle-more-actions-menu').click();
cy.getByDataCy('delete-room').within(() => { cy.getByDataCy('delete-room').within(() => {
cy.get('a').click(); cy.get('a').click();
}); });
cy.url().should('include', 'rooms'); cy.url().should('include', 'rooms');
cy.getByDataCy('room-widget').should('have.length', 1); cy.getByDataCy('room-widget').should('have.length', 1);
@ -228,40 +228,42 @@ describe('The Room Page (student)', () => {
const authorId = btoa(`PublicUserNode:${id}`); const authorId = btoa(`PublicUserNode:${id}`);
const entrySlug = 'entry-slug'; const entrySlug = 'entry-slug';
const {selectedClass} = me; const {selectedClass} = me;
const room = {
id,
slug,
schoolClass: selectedClass,
restricted: false,
roomEntries: {
edges: [],
},
};
const RoomEntriesQuery = {
room,
};
const roomEntry = { const roomEntry = {
id: 'entry-id', id: 'entry-id',
slug: entrySlug, slug: entrySlug,
title: 'My Entry', title: 'My Entry',
contents: [ contents: [
{ {
type: 'text_block', type: 'text_block',
value: { value: {
text: 'some text' text: 'some text',
} },
} },
], ],
comments: [], comments: [{}, {}],
author: { author: {
...me, ...me,
id: authorId, id: authorId,
firstName: 'Hans', firstName: 'Hans',
lastName: 'Was Heiri', lastName: 'Was Heiri',
avatarUrl: '' avatarUrl: '',
}, },
}; };
const room = {
id,
slug,
schoolClass: selectedClass,
restricted: false,
roomEntries: {
edges: [{
node: roomEntry,
}],
},
};
const RoomEntriesQuery = {
room,
};
beforeEach(() => { beforeEach(() => {
cy.setup(); cy.setup();
@ -326,7 +328,7 @@ describe('The Room Page (student)', () => {
room, room,
}, },
RoomEntryQuery: { RoomEntryQuery: {
roomEntry roomEntry,
}, },
}; };
cy.mockGraphqlOps({ cy.mockGraphqlOps({
@ -339,55 +341,18 @@ describe('The Room Page (student)', () => {
}); });
it('Deletes room entry', () => { it('Deletes room entry', () => {
const MeQuery = getMinimalMe({isTeacher: false});
const {me} = MeQuery;
const authorId = btoa(`PublicUserNode:${id}`);
const entrySlug = 'entry-slug';
const roomEntry = {
id: 'entry-id',
slug: entrySlug,
title: 'My Entry',
contents: [
{
type: 'text_block',
value: {
text: 'some text'
}
}
],
comments: [],
author: {
...me,
id: authorId,
firstName: 'Hans',
lastName: 'Was Heiri',
avatarUrl: ''
},
};
const room = {
id: 'some-room',
slug,
roomEntries: {
edges: [{
node: roomEntry
}],
},
};
const DeleteRoomEntry = { const DeleteRoomEntry = {
deleteRoomEntry: { deleteRoomEntry: {
success: true, success: true,
errors: null, errors: null,
roomSlug: slug roomSlug: slug,
} },
}; };
const operations = { const operations = {
MeQuery, MeQuery,
RoomEntriesQuery: { RoomEntriesQuery,
room, DeleteRoomEntry,
},
DeleteRoomEntry
}; };
cy.mockGraphqlOps({ cy.mockGraphqlOps({
@ -401,4 +366,20 @@ describe('The Room Page (student)', () => {
cy.getByDataCy('room-entry').should('have.length', 0); cy.getByDataCy('room-entry').should('have.length', 0);
}); });
it('Shows room entries with comment count', () => {
const operations = {
MeQuery,
RoomEntriesQuery,
};
cy.mockGraphqlOps({
operations,
});
cy.visit(`/room/${slug}`);
cy.getByDataCy('room-entry').should('have.length', 1).within(() => {
cy.getByDataCy('entry-count').should('contain.text', '2');
});
});
}); });

View File

@ -27,10 +27,16 @@
class="room-entry__teaser" class="room-entry__teaser"
v-html="teaser" v-html="teaser"
/> />
<user-meta-widget <div class="room-entry__footer">
v-bind="author" <user-meta-widget
class="room-entry__author" v-bind="author"
/> class="room-entry__author"
/>
<entry-count-widget
:entry-count="comments"
:verbose="false"
/>
</div>
</div> </div>
</router-link> </router-link>
@ -49,11 +55,13 @@
import UserMetaWidget from '@/components/UserMetaWidget'; import UserMetaWidget from '@/components/UserMetaWidget';
import teaser from '@/helpers/teaser'; import teaser from '@/helpers/teaser';
import RoomEntryActions from '@/components/rooms/RoomEntryActions'; import RoomEntryActions from '@/components/rooms/RoomEntryActions';
import EntryCountWidget from '@/components/rooms/EntryCountWidget';
export default { export default {
props: ['title', 'author', 'contents', 'slug', 'id'], props: ['title', 'author', 'contents', 'slug', 'id', 'comments'],
components: { components: {
EntryCountWidget,
RoomEntryActions, RoomEntryActions,
UserMetaWidget, UserMetaWidget,
}, },
@ -125,5 +133,12 @@
right: 10px; right: 10px;
} }
&__footer {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
} }
</style> </style>

View File

@ -3,6 +3,9 @@ fragment RoomEntryParts on RoomEntryNode {
slug slug
title title
contents contents
comments {
id
}
author { author {
id id
firstName firstName

View File

@ -44,8 +44,9 @@
--> -->
</add-room-entry-button> </add-room-entry-button>
<room-entry <room-entry
v-for="entry in room.roomEntries"
v-bind="entry" v-bind="entry"
:comments="entry.comments.length"
v-for="entry in room.roomEntries"
:key="entry.id" :key="entry.id"
/> />
</div> </div>