Whalebird-desktop-client-ma.../spec/renderer/integration/store/TimelineSpace/Modals/ImageViewer.spec.ts

220 lines
6.1 KiB
TypeScript
Raw Normal View History

2022-04-25 15:33:49 +02:00
import { RootState } from '@/store'
import { createStore, Store } from 'vuex'
2019-04-10 17:30:54 +02:00
import ImageViewer, { ImageViewerState } from '~/src/renderer/store/TimelineSpace/Modals/ImageViewer'
2019-04-10 17:30:54 +02:00
const state = (): ImageViewerState => {
return {
modalOpen: false,
currentIndex: -1,
mediaList: [],
loading: false
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: ImageViewer.actions,
mutations: ImageViewer.mutations,
getters: ImageViewer.getters
}
}
2022-04-25 15:33:49 +02:00
const modalsStore = () => ({
namespaced: true,
modules: {
ImageViewer: initStore()
}
})
const timelineStore = () => ({
namespaced: true,
modules: {
Modals: modalsStore()
}
})
describe('ImageViewer', () => {
2022-04-25 15:33:49 +02:00
let store: Store<RootState>
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store = createStore({
modules: {
2022-04-25 15:33:49 +02:00
TimelineSpace: timelineStore()
}
})
})
// Actions
describe('openModal', () => {
it('should be changed', () => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/openModal', {
currentIndex: 1,
mediaList: ['media1', 'media2']
})
2022-04-25 15:33:49 +02:00
expect(store.state.TimelineSpace.Modals.ImageViewer.modalOpen).toEqual(true)
expect(store.state.TimelineSpace.Modals.ImageViewer.currentIndex).toEqual(1)
expect(store.state.TimelineSpace.Modals.ImageViewer.mediaList).toEqual(['media1', 'media2'])
expect(store.state.TimelineSpace.Modals.ImageViewer.loading).toEqual(true)
})
})
describe('closeModal', () => {
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/openModal', {
currentIndex: 1,
mediaList: ['media1', 'media2']
})
})
it('should be changed', () => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/closeModal')
expect(store.state.TimelineSpace.Modals.ImageViewer.modalOpen).toEqual(false)
expect(store.state.TimelineSpace.Modals.ImageViewer.currentIndex).toEqual(-1)
expect(store.state.TimelineSpace.Modals.ImageViewer.mediaList).toEqual([])
expect(store.state.TimelineSpace.Modals.ImageViewer.loading).toEqual(false)
})
})
describe('incrementIndex', () => {
it('should be changed', () => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/incrementIndex')
expect(store.state.TimelineSpace.Modals.ImageViewer.currentIndex).toEqual(0)
expect(store.state.TimelineSpace.Modals.ImageViewer.loading).toEqual(true)
})
})
describe('decrementIndex', () => {
it('should be changed', () => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/decrementIndex')
expect(store.state.TimelineSpace.Modals.ImageViewer.currentIndex).toEqual(-2)
expect(store.state.TimelineSpace.Modals.ImageViewer.loading).toEqual(true)
})
})
// Getters
describe('imageURL', () => {
describe('currentIndex exists', () => {
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/openModal', {
currentIndex: 0,
mediaList: [
{
2021-08-20 12:17:38 +02:00
url: 'http://joinmastodon.org'
},
{
2021-08-22 15:18:00 +02:00
url: 'https://docs-develop.pleroma.social'
}
]
})
})
it('should return url', () => {
2022-04-25 15:33:49 +02:00
const url = store.getters['TimelineSpace/Modals/ImageViewer/imageURL']
2021-08-20 12:17:38 +02:00
expect(url).toEqual('http://joinmastodon.org')
})
})
})
describe('imageType', () => {
describe('currentIndex exists', () => {
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/openModal', {
currentIndex: 0,
mediaList: [
{
type: 'image/png'
},
{
type: 'image/jpg'
}
]
})
})
it('should return type', () => {
2022-04-25 15:33:49 +02:00
const type = store.getters['TimelineSpace/Modals/ImageViewer/imageType']
expect(type).toEqual('image/png')
})
})
})
describe('showLeft', () => {
describe('currentIndex > 0', () => {
describe('mediaList > 1', () => {
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/openModal', {
currentIndex: 1,
mediaList: [
{
type: 'image/png'
},
{
type: 'image/jpg'
}
]
})
})
it('should return true', () => {
2022-04-25 15:33:49 +02:00
const left = store.getters['TimelineSpace/Modals/ImageViewer/showLeft']
expect(left).toEqual(true)
})
})
describe('mediaList < 1', () => {
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/openModal', {
currentIndex: 0,
mediaList: [
{
type: 'image/png'
}
]
})
})
it('should not return true', () => {
2022-04-25 15:33:49 +02:00
const left = store.getters['TimelineSpace/Modals/ImageViewer/showLeft']
expect(left).toEqual(false)
})
})
})
})
describe('showRight', () => {
describe('current index is lower than media list length', () => {
describe('media list length > 1', () => {
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/openModal', {
currentIndex: 0,
mediaList: [
{
type: 'image/png'
},
{
type: 'image/jpeg'
}
]
})
})
it('should return true', () => {
2022-04-25 15:33:49 +02:00
const right = store.getters['TimelineSpace/Modals/ImageViewer/showRight']
expect(right).toEqual(true)
})
})
describe('media list length <= 1', () => {
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/ImageViewer/openModal', {
currentIndex: 0,
mediaList: [
{
type: 'image/png'
}
]
})
})
it('should not return true', () => {
2022-04-25 15:33:49 +02:00
const right = store.getters['TimelineSpace/Modals/ImageViewer/showRight']
expect(right).toEqual(false)
})
})
})
})
})