-
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
bfdb484
commit fcd9b24
Showing
2 changed files
with
56 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
54 changes: 54 additions & 0 deletions
54
src/components/chats/MediaMessage/Previews/__tests__/Document.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,54 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { beforeAll, beforeEach, describe, expect, vi } from 'vitest'; | ||
|
||
import Document from '../Document.vue'; | ||
|
||
describe('DocumentPreview', () => { | ||
let wrapper; | ||
|
||
const defaultWindowOpen = window.open; | ||
|
||
beforeEach(() => { | ||
window.open = defaultWindowOpen; | ||
wrapper = mount(Document, { | ||
props: { | ||
fullFilename: 'example.pdf', | ||
url: 'https://example.com/file.pdf', | ||
highlight: false, | ||
size: 'md', | ||
}, | ||
}); | ||
}); | ||
|
||
beforeAll(() => { | ||
window.open = defaultWindowOpen; | ||
}); | ||
|
||
it('renders the filename correctly', () => { | ||
const filenameElement = wrapper.find('[data-testid="filename"]'); | ||
expect(filenameElement.text()).toBe('example.pdf'); | ||
}); | ||
|
||
it('renders the correct icon scheme', async () => { | ||
const icon = wrapper.findComponent('[data-testid="icon"]'); | ||
expect(icon.exists()).toBe(true); | ||
expect(icon.props().scheme).toBe('neutral-darkest'); | ||
await wrapper.setProps({ highlight: true }); | ||
expect(icon.props().scheme).toBe('weni-600'); | ||
}); | ||
|
||
it('emits "download" event when clicked', async () => { | ||
window.open = vi.fn(); | ||
const openFileSpy = vi.spyOn(wrapper.vm, 'openFile'); | ||
await wrapper.trigger('click'); | ||
expect(wrapper.emitted('download')).toHaveLength(1); | ||
expect(openFileSpy).toHaveBeenCalledWith(wrapper.vm.url); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('emits "download" event when clicked', async () => { | ||
window.open = vi.fn(); | ||
await wrapper.trigger('keypress', { key: 'Enter' }); | ||
expect(wrapper.emitted('download')).toHaveLength(1); | ||
}); | ||
}); |