Max ce1844e521
feat(webapp): several group and personal invitation links (#8504)
* invite codes refactor

typo

* lint fixes

* remove duplicate initeCodes on User

* fix typo

* clean permissionMiddleware

* dummy permissions

* separate validateInviteCode call

* permissions group & user

* test validateInviteCode + adjustments

* more validateInviteCode fixes

* missing test

* generatePersonalInviteCode

* generateGroupInviteCode

* old tests

* lint fixes

* more lint fixes

* fix validateInviteCode

* fix redeemInviteCode, fix signup

* fix all tests

* fix lint

* uniform types in config

* test & fix invalidateInviteCode

* cleanup test

* fix & test redeemInviteCode

* permissions

* fix Group->inviteCodes

* more cleanup

* improve tests

* fix code generation

* cleanup

* order inviteCodes result on User and Group

* lint

* test max invite codes + fix

* better description of collision

* tests: properly define group ids

* reused old group query

* reuse old Groupmembers query

* remove duplicate skip

* update comment

* fix uniqueInviteCode

* fix test

* fix lint

* Get invite codes

* Show invitation data in registration

* Add invitation list to menu (WIP)

* Add mutations, add CreateInvitation, some fixes

* Improve style, fix long comments

* Lock scrolling when popover is open, but prevent layout change

* small fixes

* instant updates

* Introduce config for link limit; add texts, layout changes

* Validate comment length

* Improve layout

* Add message to copied link

* Add invite link section to group settings

* Handle hidden groups

* Add menu entry for group invite links

* Fix locale

* hotfix invite codes

* Add copy messages

* More styling (WIP)

* Design update

* Don't forget user state

* Localize placeholder

* Add locale

* Instant updates for group invites

* fix registration with invite code

* Fix text overflow

* Fix instant updates

* Overhaul styles, add locales, add heading

* Add test and snapshot for CreateInvitation

* Improve accessability; add invitation test

* Add tests for InvitationList

* Fix locales

* Round plus button

* Fix tests

* Fix tests

* fix locales

* fix linting

* Don't show name of hidden group in invite message

* Add more tests

* Update webapp/locales/de.json

Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>

* Update webapp/locales/de.json

Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>

---------

Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>
Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
2025-05-10 08:25:03 +00:00

114 lines
3.1 KiB
JavaScript

import { render, screen, fireEvent } from '@testing-library/vue'
import '@testing-library/jest-dom'
import InvitationList from './InvitationList.vue'
const localVue = global.localVue
Object.assign(navigator, {
clipboard: {
writeText: jest.fn(),
},
})
const sampleInviteCodes = [
{
code: 'test-invite-code-1',
comment: 'test-comment',
redeemedByCount: 0,
isValid: true,
},
{
code: 'test-invite-code-2',
comment: 'test-comment-2',
redeemedByCount: 1,
isValid: true,
},
{
code: 'test-invite-code-3',
comment: 'test-comment-3',
redeemedByCount: 0,
isValid: false,
},
]
describe('InvitationList.vue', () => {
let wrapper
const Wrapper = ({ withInviteCodes, withCopymessage = false, limit = 3 }) => {
const propsData = {
inviteCodes: withInviteCodes ? sampleInviteCodes : [],
copyMessage: withCopymessage ? 'test-copy-message' : undefined,
}
return render(InvitationList, {
localVue,
propsData,
mocks: {
$t: jest.fn((v) => v),
$toast: {
success: jest.fn(),
error: jest.fn(),
},
$env: {
INVITE_LINK_LIMIT: limit,
},
},
stubs: {
'client-only': true,
},
})
}
it('renders', () => {
wrapper = Wrapper({ withInviteCodes: true })
expect(wrapper.container).toMatchSnapshot()
})
it('renders empty state', () => {
wrapper = Wrapper({ withInviteCodes: false })
expect(wrapper.container).toMatchSnapshot()
})
it('does not render invalid invite codes', () => {
wrapper = Wrapper({ withInviteCodes: true })
const invalidInviteCode = screen.queryByText('invite-codes.test-invite-code-3')
expect(invalidInviteCode).not.toBeInTheDocument()
})
describe('without copy message', () => {
beforeEach(() => {
wrapper = Wrapper({ withCopymessage: false, withInviteCodes: true })
})
it('can copy a link', async () => {
const clipboardMock = jest.spyOn(navigator.clipboard, 'writeText').mockResolvedValue()
const copyButton = screen.getAllByLabelText('invite-codes.copy-code')[0]
await fireEvent.click(copyButton)
expect(clipboardMock).toHaveBeenCalledWith(
'http://localhost/registration?method=invite-code&inviteCode=test-invite-code-1',
)
})
})
describe('with copy message', () => {
beforeEach(() => {
wrapper = Wrapper({ withCopymessage: true, withInviteCodes: true })
})
it('can copy the link with message', async () => {
const clipboardMock = jest.spyOn(navigator.clipboard, 'writeText').mockResolvedValue()
const copyButton = screen.getAllByLabelText('invite-codes.copy-code')[0]
await fireEvent.click(copyButton)
expect(clipboardMock).toHaveBeenCalledWith(
'test-copy-message http://localhost/registration?method=invite-code&inviteCode=test-invite-code-1',
)
})
})
it('cannot generate more than the limit of invite codes', () => {
wrapper = Wrapper({ withInviteCodes: true, limit: 2 })
const generateButton = screen.getByLabelText('invite-codes.generate-code')
expect(generateButton).toBeDisabled()
})
})