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

140 lines
2.9 KiB
TypeScript
Raw Normal View History

2020-03-15 09:48:02 +01:00
import { Response, Entity } from 'megalodon'
2022-04-25 15:33:49 +02:00
import { createStore, Store } from 'vuex'
2019-04-10 17:30:54 +02:00
import AddListMember, { AddListMemberState } from '@/store/TimelineSpace/Modals/AddListMember'
2022-04-25 15:33:49 +02:00
import { RootState } from '@/store'
2020-03-15 09:48:02 +01:00
const mockClient = {
searchAccount: () => {
return new Promise<Response<Entity.Account[]>>(resolve => {
const res: Response<Entity.Account[]> = {
data: [account],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
addAccountsToList: () => {
return new Promise<Response>(resolve => {
const res: Response = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
2020-03-15 09:48:02 +01:00
jest.mock('megalodon', () => ({
2020-09-13 10:24:36 +02:00
...jest.requireActual<object>('megalodon'),
2020-03-15 09:48:02 +01:00
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
2019-05-27 16:04:53 +02:00
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
2019-04-10 17:30:54 +02:00
const state = (): AddListMemberState => {
return {
modalOpen: false,
accounts: [],
targetListId: null
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: AddListMember.actions,
mutations: AddListMember.mutations
}
}
2022-04-25 15:33:49 +02:00
const modalsStore = () => ({
namespaced: true,
modules: {
AddListMember: initStore()
}
})
const timelineStore = () => ({
namespaced: true,
state: {
account: {
2023-01-01 17:12:53 +01:00
id: 0,
accessToken: 'token'
2020-03-15 09:48:02 +01:00
},
2023-01-01 17:12:53 +01:00
server: {
sns: 'mastodon'
}
2022-04-25 15:33:49 +02:00
},
modules: {
Modals: modalsStore()
}
2022-04-25 15:33:49 +02:00
})
const appState = {
namespaced: true,
state: {
proxyConfiguration: false
}
}
describe('AddListMember', () => {
2022-04-25 15:33:49 +02:00
let store: Store<RootState>
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store = createStore({
modules: {
AddListMember: initStore(),
2022-04-25 15:33:49 +02:00
TimelineSpace: timelineStore(),
App: appState
}
})
})
describe('changeModal', () => {
it('should change modal', () => {
2022-04-25 15:33:49 +02:00
store.dispatch('TimelineSpace/Modals/AddListMember/changeModal', true)
expect(store.state.TimelineSpace.Modals.AddListMember.modalOpen).toEqual(true)
})
})
describe('search', () => {
it('should be searched', async () => {
2022-04-25 15:33:49 +02:00
await store.dispatch('TimelineSpace/Modals/AddListMember/search', 'akira')
expect(store.state.TimelineSpace.Modals.AddListMember.accounts).toEqual([account])
})
})
describe('add', () => {
it('should be added a member to the list', async () => {
2022-04-25 15:33:49 +02:00
const result = await store.dispatch('TimelineSpace/Modals/AddListMember/add', 'akira')
2019-04-10 17:30:54 +02:00
expect(result).toEqual({})
})
})
})