123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- import { generateObjectData } from '#tests/graphql/builders/index.ts'
- import { renderComponent } from '#tests/support/components/index.ts'
- import type { Ticket } from '#shared/graphql/types.ts'
- import { convertToGraphQLId } from '#shared/graphql/utils.ts'
- import ActivityMessage from '../ActivityMessage.vue'
- import type { Props } from '../ActivityMessage.vue'
- const now = vi.hoisted(() => {
- const now = new Date('2022-01-03 00:00:00')
- vi.setSystemTime(now)
- return now
- })
- // this is not required, but Vitest is bugged and does not hoist "now" otherwise
- // https://github.com/vitest-dev/vitest/pull/4285/files
- vi.mock('non-existing')
- const userId = convertToGraphQLId('User', 100)
- const renderActivityMessage = (props: Partial<Props> = {}) => {
- const finishedProps: Props = {
- objectName: 'Ticket',
- typeName: 'update',
- createdBy: {
- id: userId,
- fullname: 'John Doe',
- firstname: 'John',
- lastname: 'Doe',
- active: true,
- },
- createdAt: new Date('2022-01-01 00:00:00').toISOString(),
- metaObject: generateObjectData<Ticket>('Ticket', {
- title: 'Ticket Title',
- id: convertToGraphQLId('Ticket', '1'),
- internalId: 1,
- }),
- ...props,
- }
- return renderComponent(ActivityMessage, {
- props: finishedProps,
- router: true,
- })
- }
- describe('NotificationItem.vue', () => {
- afterEach(() => {
- vi.useRealTimers()
- })
- it('check update activity message output', () => {
- const view = renderActivityMessage()
- expect(view.container).toHaveTextContent(
- 'John Doe updated ticket Ticket Title',
- )
- })
- it('check create activity message output', () => {
- const view = renderActivityMessage({
- typeName: 'create',
- })
- expect(view.container).toHaveTextContent(
- 'John Doe created ticket Ticket Title',
- )
- })
- it('check that avatar exists', () => {
- const view = renderActivityMessage()
- const avatar = view.getByTestId('common-avatar')
- expect(avatar).toHaveTextContent('JD')
- })
- it('check that link exists', () => {
- const view = renderActivityMessage()
- const link = view.getByRole('link')
- expect(link).toHaveAttribute('href', 'tickets/1')
- })
- it('check that create date exists', () => {
- vi.setSystemTime(now)
- const view = renderActivityMessage()
- expect(view.getByText(/2 days ago/)).toBeInTheDocument()
- })
- it('check that default message and avatar for no meta object is visible', () => {
- const view = renderActivityMessage({
- metaObject: undefined,
- createdBy: undefined,
- })
- expect(view.container).toHaveTextContent(
- 'You can no longer see the ticket.',
- )
- expect(view.getByIconName('lock')).toBeInTheDocument()
- })
- it('should emit "seen" event on click for none linked notifications', async () => {
- const view = renderActivityMessage({
- metaObject: undefined,
- createdBy: undefined,
- })
- const item = view.getByText('You can no longer see the ticket.')
- await view.events.click(item)
- expect(view.emitted().seen).toBeTruthy()
- })
- it('no output for not existing builder', (context) => {
- context.skipConsole = true
- const view = renderActivityMessage({
- objectName: 'NotExisting',
- })
- expect(view.html()).not.toContain('a')
- })
- })
|