mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
* feat(backend): resize images with imagor Open questions: * Do we have external URLs for images? E.g. we have them for seeds. But in production? * Do we want to apply image transformations on these as well? My current implementation does not apply image transformations as of now. If we want to do that, we will also expose internal URLs in the kubernetes Cluster to the S3 endpoint to the client. TODOs: * The chat component is using a fixed size for all avatars at the moment. Maybe we can pair-program on this how to implement responsive images in this component library. Commits: * do not replace upload domain url in the database * fix all webapp specs * refactor: remove behaviour we won't need We don't want to apply image transformations on files, right? * refactor: replace the domain on read not on write * wip: webapp fixes * refactor(backend): add another url to config I've given up. There seems to be no nice way to tell the minio to return a location which differs from it's host name. * refactor: add test for s3Service * refactor(backend): proxy minio via backend in local development Commits: * provide tests for message attachments * remove S3_PUBLIC_URL config value * refactor: follow @ulfgebhardt's review * add missing environment variable --------- Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>
266 lines
6.9 KiB
JavaScript
266 lines
6.9 KiB
JavaScript
import { render, screen, fireEvent } from '@testing-library/vue'
|
|
import { RouterLinkStub } from '@vue/test-utils'
|
|
import UserTeaser from './UserTeaser.vue'
|
|
import Vuex from 'vuex'
|
|
|
|
const localVue = global.localVue
|
|
|
|
// Mock Math.random, used in Dropdown
|
|
Object.assign(Math, {
|
|
random: () => 0,
|
|
})
|
|
|
|
const waitForPopover = async () => await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
|
|
let mockIsTouchDevice
|
|
jest.mock('../utils/isTouchDevice', () => ({
|
|
isTouchDevice: jest.fn(() => mockIsTouchDevice),
|
|
}))
|
|
|
|
const userTilda = {
|
|
name: 'Tilda Swinton',
|
|
slug: 'tilda-swinton',
|
|
id: 'user1',
|
|
avatar: {
|
|
url: '/avatars/tilda-swinton',
|
|
w320: '/avatars/tilda-swinton-w320',
|
|
w640: '/avatars/tilda-swinton-w640',
|
|
w1024: '/avatars/tilda-swinton-w1024',
|
|
},
|
|
badgeVerification: {
|
|
id: 'bv1',
|
|
icon: '/icons/verified',
|
|
description: 'Verified',
|
|
isDefault: false,
|
|
},
|
|
badgeTrophiesSelected: [
|
|
{
|
|
id: 'trophy1',
|
|
icon: '/icons/trophy1',
|
|
description: 'Trophy 1',
|
|
isDefault: false,
|
|
},
|
|
{
|
|
id: 'trophy2',
|
|
icon: '/icons/trophy2',
|
|
description: 'Trophy 2',
|
|
isDefault: false,
|
|
},
|
|
{
|
|
id: 'empty',
|
|
icon: '/icons/empty',
|
|
description: 'Empty',
|
|
isDefault: true,
|
|
},
|
|
],
|
|
}
|
|
|
|
describe('UserTeaser', () => {
|
|
const Wrapper = ({
|
|
isModerator = false,
|
|
withLinkToProfile = true,
|
|
onTouchScreen = false,
|
|
withAvatar = true,
|
|
showSlug = true,
|
|
user = userTilda,
|
|
withPopoverEnabled = true,
|
|
}) => {
|
|
mockIsTouchDevice = onTouchScreen
|
|
|
|
const store = new Vuex.Store({
|
|
getters: {
|
|
'auth/user': () => {
|
|
return {}
|
|
},
|
|
'auth/isModerator': () => isModerator,
|
|
},
|
|
})
|
|
return render(UserTeaser, {
|
|
localVue,
|
|
store,
|
|
propsData: {
|
|
user,
|
|
linkToProfile: withLinkToProfile,
|
|
showAvatar: withAvatar,
|
|
showSlug: showSlug,
|
|
showPopover: withPopoverEnabled,
|
|
},
|
|
stubs: {
|
|
NuxtLink: RouterLinkStub,
|
|
'user-teaser-popover': true,
|
|
'v-popover': true,
|
|
'client-only': true,
|
|
},
|
|
mocks: {
|
|
$t: jest.fn((t) => t),
|
|
$i18n: {
|
|
locale: jest.fn(() => 'en'),
|
|
},
|
|
$apollo: {
|
|
query: jest.fn(() => Promise.resolve({ data: { user } })),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
it('renders anonymous user', () => {
|
|
const wrapper = Wrapper({ user: null })
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
|
|
describe('given an user', () => {
|
|
describe('without linkToProfile, on touch screen', () => {
|
|
let wrapper
|
|
beforeEach(() => {
|
|
wrapper = Wrapper({ withLinkToProfile: false, onTouchScreen: true })
|
|
})
|
|
|
|
it('renders', () => {
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
|
|
describe('when clicking the user name', () => {
|
|
beforeEach(async () => {
|
|
const userName = screen.getByText('Tilda Swinton')
|
|
await fireEvent.click(userName)
|
|
await waitForPopover()
|
|
})
|
|
|
|
it('renders the popover', () => {
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
})
|
|
|
|
describe('when clicking the user avatar', () => {
|
|
beforeEach(async () => {
|
|
const userAvatar = screen.getByAltText('Tilda Swinton')
|
|
await fireEvent.click(userAvatar)
|
|
await waitForPopover()
|
|
})
|
|
|
|
it('renders the popover', () => {
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('with linkToProfile, on touch screen', () => {
|
|
let wrapper
|
|
beforeEach(() => {
|
|
wrapper = Wrapper({ withLinkToProfile: true, onTouchScreen: true })
|
|
})
|
|
|
|
it('renders', () => {
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
|
|
describe('when clicking the user name', () => {
|
|
beforeEach(async () => {
|
|
const userName = screen.getByText('Tilda Swinton')
|
|
await fireEvent.click(userName)
|
|
})
|
|
|
|
it('renders the popover', () => {
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('without linkToProfile, on desktop', () => {
|
|
let wrapper
|
|
beforeEach(() => {
|
|
wrapper = Wrapper({ withLinkToProfile: false, onTouchScreen: false })
|
|
})
|
|
|
|
it('renders', () => {
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
|
|
describe('when hovering the user name', () => {
|
|
beforeEach(async () => {
|
|
const userName = screen.getByText('Tilda Swinton')
|
|
await fireEvent.mouseOver(userName)
|
|
await waitForPopover()
|
|
})
|
|
|
|
it('renders the popover', () => {
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
})
|
|
|
|
describe('when hovering the user avatar', () => {
|
|
beforeEach(async () => {
|
|
const userAvatar = screen.getByAltText('Tilda Swinton')
|
|
await fireEvent.mouseOver(userAvatar)
|
|
await waitForPopover()
|
|
})
|
|
|
|
it('renders the popover', () => {
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('with linkToProfile, on desktop', () => {
|
|
let wrapper
|
|
beforeEach(() => {
|
|
wrapper = Wrapper({ withLinkToProfile: true, onTouchScreen: false })
|
|
})
|
|
|
|
it('renders', () => {
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
|
|
describe('when hovering the user name', () => {
|
|
beforeEach(async () => {
|
|
const userName = screen.getByText('Tilda Swinton')
|
|
await fireEvent.mouseOver(userName)
|
|
await waitForPopover()
|
|
})
|
|
|
|
it('renders the popover', () => {
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('avatar is disabled', () => {
|
|
it('does not render the avatar', () => {
|
|
const wrapper = Wrapper({ withAvatar: false })
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
})
|
|
|
|
describe('user is deleted', () => {
|
|
it('renders anonymous user', () => {
|
|
const wrapper = Wrapper({ user: { ...userTilda, deleted: true } })
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
|
|
describe('even if the current user is a moderator', () => {
|
|
it('renders anonymous user', () => {
|
|
const wrapper = Wrapper({
|
|
user: { ...userTilda, deleted: true },
|
|
isModerator: true,
|
|
})
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('user is disabled', () => {
|
|
it('renders anonymous user', () => {
|
|
const wrapper = Wrapper({ user: { ...userTilda, disabled: true } })
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
|
|
describe('current user is a moderator', () => {
|
|
it('renders user name', () => {
|
|
const wrapper = Wrapper({ user: { ...userTilda, disabled: true }, isModerator: true })
|
|
expect(wrapper.container).toMatchSnapshot()
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|