Fix frontend tests

This commit is contained in:
Wolfgang Huß 2020-03-13 14:45:27 +01:00
parent 32d5482597
commit 06be781078
7 changed files with 76 additions and 88 deletions

View File

@ -205,20 +205,16 @@ describe('Notification', () => {
propsData.notification = {
reason: 'filed_report_on_resource',
from: {
__typename: 'Report',
id: 'reportOnUser',
filed: [
{
reasonCategory: 'discrimination_etc',
reasonDescription: 'This user is harassing me with bigoted remarks!',
reportedResource: {
__typename: 'User',
id: 'badWomen',
slug: 'mrs.-badwomen',
name: 'Mrs. Badwomen',
},
},
],
__typename: 'FiledReport',
reportId: 'reportOnUser',
reasonCategory: 'discrimination_etc',
reasonDescription: 'This user is harassing me with bigoted remarks!',
resource: {
__typename: 'User',
id: 'badWomen',
slug: 'mrs.-badwomen',
name: 'Mrs. Badwomen',
},
},
}
})

View File

@ -73,7 +73,7 @@
<client-only>
<user-teaser :user="notificationData.triggerer" :date-time="notificationData.createdAt" />
</client-only>
<p class="description">
<p class="description" data-test="reason-text">
<base-icon
:name="notificationData.iconName"
v-tooltip="{ content: $t(notificationData.iconTooltip), placement: 'right' }"

View File

@ -71,12 +71,12 @@ describe('NotificationList.vue', () => {
wrapper = Wrapper()
})
describe('click on a notification', () => {
describe("emit 'read', like as clicked on a notification", () => {
beforeEach(() => {
wrapper.find('.notification .notifications-card').trigger('click')
wrapper.find(Notification).vm.$emit('read')
})
it("emits 'markAsRead' with the id of the notification source", () => {
it("emits 'markAsRead' with the id of the notification source, if 'read' was emited", () => {
expect(wrapper.emitted('markAsRead')[0]).toEqual(['post-1'])
})
})

View File

@ -4,7 +4,7 @@
v-for="notification in notifications"
:key="notification.id"
:notification="notification"
@read="markAsRead(notification.from.id)"
@read="markAsRead(notification.from.id || notification.from.reportId)"
/>
</div>
</template>

View File

@ -167,7 +167,7 @@ describe('NotificationsTable.vue', () => {
it('renders a link to the user', () => {
const userLink = thirdRowNotification.find('[data-test="notification-title-link"]')
expect(userLink.text()).toEqual(reportNotification.from.filed[0].reportedResource.name)
expect(userLink.text()).toEqual(reportNotification.from.resource.name)
})
it('renders the reported users slug', () => {
@ -183,7 +183,7 @@ describe('NotificationsTable.vue', () => {
it('renders the reported category', () => {
wrapper = Wrapper()
expect(wrapper.text()).toContain(
'report.reason.category.options.' + reportNotification.from.filed[0].reasonCategory,
'report.reason.category.options.' + reportNotification.from.reasonCategory,
)
})
@ -194,7 +194,7 @@ describe('NotificationsTable.vue', () => {
it('renders the reported description', () => {
wrapper = Wrapper()
expect(wrapper.text()).toContain(reportNotification.from.filed[0].reasonDescription)
expect(wrapper.text()).toContain(reportNotification.from.reasonDescription)
})
})

View File

@ -44,26 +44,23 @@ export const testNotifications = [
read: false,
reason: 'filed_report_on_resource',
from: {
__typename: 'Report',
id: 'reportOnUser',
filed: [
{
reasonCategory: 'discrimination_etc',
reasonDescription: 'This user is harassing me with bigoted remarks!',
reportedResource: {
__typename: 'User',
id: 'badWomen',
slug: 'mrs.-badwomen',
name: 'Mrs. Badwomen',
},
},
],
__typename: 'FiledReport',
reportId: 'reportOnUser',
reasonCategory: 'discrimination_etc',
reasonDescription: 'This user is harassing me with bigoted remarks!',
resource: {
__typename: 'User',
id: 'badWomen',
slug: 'mrs.-badwomen',
name: 'Mrs. Badwomen',
},
},
},
]
export const extractNotificationDataOfCurrentUser = (notification, currentUser) => {
const from = notification.from // for readability
// Wolle console.log('from: ', from)
let user = null
let post = null
let comment = null
@ -78,7 +75,7 @@ export const extractNotificationDataOfCurrentUser = (notification, currentUser)
// extract data out of the deep structure of db response
// leave undefined data as default, see above, so later by priority user, comment, post we get easely a clou what it is
// leave undefined data as default, see above. so later by priority user, comment, post we get easely a clou what it is
switch (from.__typename) {
case 'Comment':
comment = from
@ -95,35 +92,32 @@ export const extractNotificationDataOfCurrentUser = (notification, currentUser)
iconTooltip = 'notifications.post'
triggerer = post.author
break
case 'Report':
{
const filed = from.filed[0] // for readability
report = {
reasonCategory: filed.reasonCategory,
reasonDescription: filed.reasonDescription,
}
isReport = true
iconName = 'balance-scale'
iconTooltip = 'notifications.report.name'
triggerer = currentUser
switch (filed.reportedResource.__typename) {
case 'User':
user = filed.reportedResource
isUser = true
reasonTranslationExtention = '.user'
break
case 'Comment':
comment = filed.reportedResource
post = filed.reportedResource.post
isComment = true
reasonTranslationExtention = '.comment'
break
case 'Post':
post = filed.reportedResource
isPost = true
reasonTranslationExtention = '.post'
break
}
case 'FiledReport':
report = {
reasonCategory: from.reasonCategory,
reasonDescription: from.reasonDescription,
}
isReport = true
iconName = 'balance-scale'
iconTooltip = 'notifications.report.name'
triggerer = currentUser
switch (from.resource.__typename) {
case 'User':
user = from.resource
isUser = true
reasonTranslationExtention = '.user'
break
case 'Comment':
comment = from.resource
post = from.resource.post
isComment = true
reasonTranslationExtention = '.comment'
break
case 'Post':
post = from.resource
isPost = true
reasonTranslationExtention = '.post'
break
}
break
}

View File

@ -93,35 +93,33 @@ export const notificationQuery = i18n => {
}
}
}
... on Report {
id
filed {
reasonCategory
reasonDescription
reportedResource {
__typename
... on User {
... on FiledReport {
reportId
reasonCategory
reasonDescription
resource {
__typename
... on User {
...user
...userCounts
}
... on Post {
...post
author {
...user
...userCounts
}
... on Post {
}
... on Comment {
...comment
author {
...user
}
post {
...post
author {
...user
}
}
... on Comment {
...comment
author {
...user
}
post {
...post
author {
...user
}
}
}
}
}
}