mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
215 lines
6.3 KiB
JavaScript
215 lines
6.3 KiB
JavaScript
import { config, mount, RouterLinkStub } from '@vue/test-utils'
|
|
import Vuex from 'vuex'
|
|
import ReportsTable from './ReportsTable.vue'
|
|
import { reports } from './ReportsTable.story.js'
|
|
import BaseIcon from '~/components/_new/generic/BaseIcon/BaseIcon'
|
|
|
|
const localVue = global.localVue
|
|
|
|
config.stubs['client-only'] = '<span><slot /></span>'
|
|
|
|
describe('ReportsTable', () => {
|
|
let propsData, mocks, stubs, getters, wrapper, reportsTable
|
|
|
|
beforeEach(() => {
|
|
propsData = {}
|
|
mocks = {
|
|
$t: jest.fn(string => string),
|
|
}
|
|
stubs = {
|
|
NuxtLink: RouterLinkStub,
|
|
}
|
|
getters = {
|
|
'auth/user': () => {
|
|
return { slug: 'awesome-user' }
|
|
},
|
|
'auth/isModerator': () => true,
|
|
}
|
|
})
|
|
|
|
describe('mount', () => {
|
|
const Wrapper = () => {
|
|
const store = new Vuex.Store({
|
|
getters,
|
|
})
|
|
return mount(ReportsTable, { propsData, mocks, stubs, localVue, store })
|
|
}
|
|
|
|
describe('given no reports', () => {
|
|
beforeEach(() => {
|
|
propsData = { ...propsData, reports: [] }
|
|
wrapper = Wrapper()
|
|
})
|
|
|
|
it('shows a placeholder', () => {
|
|
expect(wrapper.text()).toContain('moderation.reports.empty')
|
|
})
|
|
})
|
|
|
|
describe('given reports', () => {
|
|
beforeEach(() => {
|
|
propsData = { ...propsData, reports }
|
|
wrapper = Wrapper()
|
|
reportsTable = wrapper.find('.ds-table')
|
|
})
|
|
|
|
it('renders a table', () => {
|
|
expect(reportsTable.exists()).toBe(true)
|
|
})
|
|
|
|
describe('Comment', () => {
|
|
let commentRow
|
|
beforeEach(() => {
|
|
commentRow = wrapper.find('.report-comment')
|
|
})
|
|
|
|
it('renders a comments icon', () => {
|
|
const commentsIcon = commentRow.find(BaseIcon).props().name
|
|
expect(commentsIcon).toEqual('comments')
|
|
})
|
|
|
|
it('renders a link to the post, with the comment contentExcerpt', () => {
|
|
const postLink = commentRow.find('.report-content a')
|
|
expect(postLink.text()).toEqual('@peter-lustig Lorem ipsum dolor sit amet, …')
|
|
})
|
|
|
|
it('renders the author', () => {
|
|
const username = commentRow.find('.report-author b')
|
|
expect(username.text()).toEqual('Louie')
|
|
})
|
|
|
|
describe('given it has been reviewed', () => {
|
|
it('renders the enabled icon', () => {
|
|
expect(
|
|
commentRow
|
|
.find('.status-line')
|
|
.find(BaseIcon)
|
|
.props().name,
|
|
).toEqual('eye')
|
|
})
|
|
|
|
it('renders its current status', () => {
|
|
expect(commentRow.find('.status-line').text()).toEqual('moderation.reports.enabledBy')
|
|
})
|
|
|
|
it('renders the moderator who reviewed the resource', () => {
|
|
const username = commentRow.find('.report-reviewer')
|
|
expect(username.text()).toContain('@moderator')
|
|
})
|
|
})
|
|
|
|
describe('give report has not been closed', () => {
|
|
let confirmButton
|
|
beforeEach(() => {
|
|
confirmButton = commentRow.find('button.confirm')
|
|
})
|
|
it('renders a confirm button', () => {
|
|
expect(confirmButton.exists()).toBe(true)
|
|
})
|
|
|
|
it('emits confirm event', () => {
|
|
confirmButton.trigger('click')
|
|
expect(wrapper.emitted().confirm[0][0]).toEqual(reports[0])
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('Post', () => {
|
|
let postRow
|
|
beforeEach(() => {
|
|
postRow = wrapper.find('.report-post')
|
|
})
|
|
|
|
it('renders a bookmark icon', () => {
|
|
const postIcon = postRow.find(BaseIcon).props().name
|
|
expect(postIcon).toEqual('bookmark')
|
|
})
|
|
|
|
it('renders a link to the post', () => {
|
|
const postLink = postRow.find('.report-content a')
|
|
expect(postLink.text()).toEqual("I'm a bigoted post!")
|
|
})
|
|
|
|
it('renders the author', () => {
|
|
const username = postRow.find('.report-author')
|
|
expect(username.text()).toContain('Dagobert')
|
|
})
|
|
|
|
describe('given it has not been reviewed', () => {
|
|
it('renders the enabled icon', () => {
|
|
expect(
|
|
postRow
|
|
.find('.status-line')
|
|
.find(BaseIcon)
|
|
.props().name,
|
|
).toEqual('eye')
|
|
})
|
|
|
|
it('renders its current status', () => {
|
|
expect(postRow.find('.status-line').text()).toEqual('moderation.reports.enabled')
|
|
})
|
|
})
|
|
|
|
describe('give report has not been closed', () => {
|
|
let confirmButton
|
|
beforeEach(() => {
|
|
confirmButton = postRow.find('button.confirm')
|
|
})
|
|
|
|
it('renders a confirm button', () => {
|
|
expect(confirmButton.exists()).toBe(true)
|
|
})
|
|
|
|
it('emits confirm event', () => {
|
|
confirmButton.trigger('click')
|
|
expect(wrapper.emitted().confirm[0][0]).toEqual(reports[1])
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('User', () => {
|
|
let userRow
|
|
beforeEach(() => {
|
|
userRow = wrapper.find('.report-user')
|
|
})
|
|
|
|
it('renders a bookmark icon', () => {
|
|
const userIcon = userRow.find(BaseIcon).props().name
|
|
expect(userIcon).toEqual('user')
|
|
})
|
|
|
|
it('renders a link to the user profile', () => {
|
|
const userLink = userRow.find('.report-content a')
|
|
expect(userLink.text()).toContain('Abusive user')
|
|
})
|
|
|
|
describe('given it has been reviewed', () => {
|
|
it('renders the disabled icon', () => {
|
|
expect(
|
|
userRow
|
|
.find('.status-line')
|
|
.find(BaseIcon)
|
|
.props().name,
|
|
).toEqual('eye-slash')
|
|
})
|
|
|
|
it('renders its current status', () => {
|
|
expect(userRow.find('.status-line').text()).toEqual('moderation.reports.disabledBy')
|
|
})
|
|
|
|
it('renders the moderator who reviewed the resource', () => {
|
|
const username = userRow.find('.report-reviewer')
|
|
expect(username.text()).toContain('Peter Lustig')
|
|
})
|
|
})
|
|
|
|
describe('give report has been closed', () => {
|
|
it('renders Decided text', () => {
|
|
expect(userRow.find('.report-closed').text()).toEqual('moderation.reports.decided')
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|