Merge pull request #846 from h3poteto/iss-209

refs #209 Add integration tests for AddListMember modal
This commit is contained in:
AkiraFukushima 2019-03-11 22:49:16 +09:00 committed by GitHub
commit c8ae6a1544
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 318 additions and 1 deletions

View File

@ -28,6 +28,15 @@ const initStore = () => {
}
}
const app = {
namespaced: true,
actions: {
loadPreferences (_) {
return true
}
}
}
describe('Preferences/General', () => {
let store
let localVue
@ -37,7 +46,8 @@ describe('Preferences/General', () => {
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Preferences: initStore()
Preferences: initStore(),
App: app
}
})
})

View File

@ -0,0 +1,99 @@
import Mastodon from 'megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import AddListMember from '~/src/renderer/store/TimelineSpace/Modals/AddListMember'
jest.genMockFromModule('megalodon')
jest.mock('megalodon')
const state = () => {
return {
modalOpen: false,
accounts: [],
targetListId: null
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: AddListMember.actions,
mutations: AddListMember.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
_id: '0'
}
}
}
describe('AddListMember', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
AddListMember: initStore(),
TimelineSpace: timelineState
}
})
Mastodon.mockClear()
})
describe('changeModal', () => {
it('should change modal', () => {
store.dispatch('AddListMember/changeModal', true)
expect(store.state.AddListMember.modalOpen).toEqual(true)
})
})
describe('search', () => {
it('should be searched', async () => {
const mockClient = {
get: () => {
return new Promise((resolve, reject) => {
resolve({
data: [
{ id: 1, name: 'h3poteto' },
{ id: 2, name: 'akito19' }
]
})
})
}
}
Mastodon.mockImplementation(() => mockClient)
await store.dispatch('AddListMember/search', 'akira')
expect(store.state.AddListMember.accounts).toEqual([
{ id: 1, name: 'h3poteto' },
{ id: 2, name: 'akito19' }
])
})
})
describe('add', () => {
it('should be added a member to the list', async () => {
const mockClient = {
post: () => {
return new Promise((resolve, reject) => {
resolve({
data: true
})
})
}
}
Mastodon.mockImplementation(() => mockClient)
const result = await store.dispatch('AddListMember/add', 'akira')
expect(result.data).toEqual(true)
})
})
})

View File

@ -0,0 +1,208 @@
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import ImageViewer from '~/src/renderer/store/TimelineSpace/Modals/ImageViewer'
const state = () => {
return {
modalOpen: false,
currentIndex: -1,
mediaList: [],
loading: false
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: ImageViewer.actions,
mutations: ImageViewer.mutations,
getters: ImageViewer.getters
}
}
describe('ImageViewer', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
ImageViewer: initStore()
}
})
})
// Actions
describe('openModal', () => {
it('should be changed', () => {
store.dispatch('ImageViewer/openModal', {
currentIndex: 1,
mediaList: ['media1', 'media2']
})
expect(store.state.ImageViewer.modalOpen).toEqual(true)
expect(store.state.ImageViewer.currentIndex).toEqual(1)
expect(store.state.ImageViewer.mediaList).toEqual(['media1', 'media2'])
expect(store.state.ImageViewer.loading).toEqual(true)
})
})
describe('closeModal', () => {
beforeEach(() => {
store.dispatch('ImageViewer/openModal', {
currentIndex: 1,
mediaList: ['media1', 'media2']
})
})
it('should be changed', () => {
store.dispatch('ImageViewer/closeModal')
expect(store.state.ImageViewer.modalOpen).toEqual(false)
expect(store.state.ImageViewer.currentIndex).toEqual(-1)
expect(store.state.ImageViewer.mediaList).toEqual([])
expect(store.state.ImageViewer.loading).toEqual(false)
})
})
describe('incrementIndex', () => {
it('should be changed', () => {
store.dispatch('ImageViewer/incrementIndex')
expect(store.state.ImageViewer.currentIndex).toEqual(0)
expect(store.state.ImageViewer.loading).toEqual(true)
})
})
describe('decrementIndex', () => {
it('should be changed', () => {
store.dispatch('ImageViewer/decrementIndex')
expect(store.state.ImageViewer.currentIndex).toEqual(-2)
expect(store.state.ImageViewer.loading).toEqual(true)
})
})
// Getters
describe('imageURL', () => {
describe('currentIndex exists', () => {
beforeEach(() => {
store.dispatch('ImageViewer/openModal', {
currentIndex: 0,
mediaList: [
{
url: 'http://github.com'
},
{
url: 'http://google.com'
}
]
})
})
it('should return url', () => {
const url = store.getters['ImageViewer/imageURL']
expect(url).toEqual('http://github.com')
})
})
})
describe('imageType', () => {
describe('currentIndex exists', () => {
beforeEach(() => {
store.dispatch('ImageViewer/openModal', {
currentIndex: 0,
mediaList: [
{
type: 'image/png'
},
{
type: 'image/jpg'
}
]
})
})
it('should return type', () => {
const type = store.getters['ImageViewer/imageType']
expect(type).toEqual('image/png')
})
})
})
describe('showLeft', () => {
describe('currentIndex > 0', () => {
describe('mediaList > 1', () => {
beforeEach(() => {
store.dispatch('ImageViewer/openModal', {
currentIndex: 1,
mediaList: [
{
type: 'image/png'
},
{
type: 'image/jpg'
}
]
})
})
it('should return true', () => {
const left = store.getters['ImageViewer/showLeft']
expect(left).toEqual(true)
})
})
describe('mediaList < 1', () => {
beforeEach(() => {
store.dispatch('ImageViewer/openModal', {
currentIndex: 0,
mediaList: [
{
type: 'image/png'
}
]
})
})
it('should not return true', () => {
const left = store.getters['ImageViewer/showLeft']
expect(left).toEqual(false)
})
})
})
})
describe('showRight', () => {
describe('current index is lower than media list length', () => {
describe('media list length > 1', () => {
beforeEach(() => {
store.dispatch('ImageViewer/openModal', {
currentIndex: 0,
mediaList: [
{
type: 'image/png'
},
{
type: 'image/jpeg'
}
]
})
})
it('should return true', () => {
const right = store.getters['ImageViewer/showRight']
expect(right).toEqual(true)
})
})
describe('media list length <= 1', () => {
beforeEach(() => {
store.dispatch('ImageViewer/openModal', {
currentIndex: 0,
mediaList: [
{
type: 'image/png'
}
]
})
})
it('should not return true', () => {
const right = store.getters['ImageViewer/showRight']
expect(right).toEqual(false)
})
})
})
})
})