import { createLocalVue, shallowMount } from '@vue/test-utils'
import { cloneDeep } from 'lodash'
import { createPinia, setActivePinia } from 'pinia'
import Vuex from 'vuex'
import PlayCircleOutline from 'vue-material-design-icons/PlayCircleOutline.vue'
import { getCapabilities } from '@nextcloud/capabilities'
import { imagePath, generateRemoteUrl } from '@nextcloud/router'
import { getUploader } from '@nextcloud/upload'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import FilePreview from './FilePreview.vue'
import storeConfig from '../../../../../store/storeConfig.js'
jest.mock('@nextcloud/capabilities', () => ({
getCapabilities: jest.fn(),
}))
describe('FilePreview.vue', () => {
let store
let localVue
let testStoreConfig
let propsData
let imageMock
let getUserIdMock
let oldPixelRatio
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
setActivePinia(createPinia())
oldPixelRatio = window.devicePixelRatio
testStoreConfig = cloneDeep(storeConfig)
getUserIdMock = jest.fn().mockReturnValue('current-user-id')
testStoreConfig.modules.actorStore.getters.getUserId = () => getUserIdMock
store = new Vuex.Store(testStoreConfig)
imageMock = {
onload: jest.fn(),
onerror: jest.fn(),
src: null,
}
jest.spyOn(global, 'Image')
.mockImplementation(() => {
return imageMock
})
propsData = {
token: 'TOKEN',
id: '123',
name: 'test.jpg',
path: 'path/to/test.jpg',
size: '128',
etag: '1872ade88f3013edeb33decd74a4f947',
permissions: '15',
mimetype: 'image/jpeg',
previewAvailable: 'yes',
}
})
afterEach(() => {
jest.clearAllMocks()
window.devicePixelRatio = oldPixelRatio
})
/**
* @param {string} url Relative URL to parse (starting with / )
*/
function parseRelativeUrl(url) {
return new URL('https://localhost' + url)