-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcd9b24
commit 26e6ec5
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/components/chats/MediaMessage/Previews/__tests__/Imagem.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { beforeEach, describe, expect } from 'vitest'; | ||
|
||
import Image from '../Image.vue'; | ||
|
||
describe('ImagePreview', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(Image, { | ||
props: { | ||
url: 'https://example.com/image.png', | ||
alt: 'Example image', | ||
tooltip: 'View image', | ||
objectFit: 'contain', | ||
fullscreen: false, | ||
fullscreenOnClick: true, | ||
}, | ||
}); | ||
}); | ||
|
||
it('renders the image with the correct attributes', () => { | ||
const img = wrapper.find('[data-testid="image-preview"]'); | ||
expect(img.attributes('src')).toBe('https://example.com/image.png'); | ||
expect(img.attributes('alt')).toBe('Example image'); | ||
expect(img.attributes('style')).toContain('object-fit: contain'); | ||
}); | ||
|
||
it('renders the tooltip with the correct text', async () => { | ||
const tooltip = wrapper.findComponent( | ||
'[data-testid="image-preview-tooltip"]', | ||
); | ||
expect(tooltip.exists()).toBe(true); | ||
expect(tooltip.props('text')).toBe('View image'); | ||
|
||
await wrapper.setProps({ tooltip: '' }); | ||
expect(tooltip.props('text')).toBe(wrapper.vm.$t('fullscreen_view')); | ||
}); | ||
|
||
it('emits "click" event when the image is clicked', async () => { | ||
const img = wrapper.find('[data-testid="image-preview"]'); | ||
await img.trigger('click'); | ||
expect(wrapper.emitted('click')).toHaveLength(1); | ||
}); | ||
|
||
it('sets `isFullscreenByUserClick` to true when `fullscreenOnClick` is enabled and the image is clicked', async () => { | ||
const img = wrapper.find('[data-testid="image-preview"]'); | ||
expect(wrapper.vm.isFullscreenByUserClick).toBe(false); | ||
await img.trigger('click'); | ||
expect(wrapper.vm.isFullscreenByUserClick).toBe(true); | ||
}); | ||
|
||
it('computes `isFullscreen` correctly when `fullscreen` prop is true', async () => { | ||
await wrapper.setProps({ fullscreen: true }); | ||
expect(wrapper.vm.isFullscreen).toBe(true); | ||
}); | ||
|
||
it('computes `isFullscreen` correctly when `fullscreenOnClick` is true and image is clicked', async () => { | ||
const img = wrapper.find('[data-testid="image-preview"]'); | ||
await img.trigger('click'); | ||
expect(wrapper.vm.isFullscreen).toBe(true); | ||
}); | ||
|
||
it('does not set `isFullscreenByUserClick` when `fullscreenOnClick` is false', async () => { | ||
await wrapper.setProps({ fullscreenOnClick: false }); | ||
const img = wrapper.find('[data-testid="image-preview"]'); | ||
await img.trigger('click'); | ||
expect(wrapper.vm.isFullscreenByUserClick).toBe(false); | ||
}); | ||
|
||
it('handles Enter key press to emit "click"', async () => { | ||
const img = wrapper.find('[data-testid="image-preview"]'); | ||
await img.trigger('keypress', { key: 'Enter' }); | ||
expect(wrapper.emitted('click')).toHaveLength(1); | ||
}); | ||
}); |