refs #850 Convert TimelineSpace's tests to typescript
This commit is contained in:
parent
e49d27c30a
commit
95b7ace37c
|
@ -139,8 +139,8 @@ describe('Home', () => {
|
|||
it('should be updated', async () => {
|
||||
const mockClient = {
|
||||
get: (_path: string, _params: object) => {
|
||||
return new Promise<Response<[Status]>>((resolve, _) => {
|
||||
const res: Response<[Status]> = {
|
||||
return new Promise<Response<Status[]>>((resolve, _) => {
|
||||
const res: Response<Status[]> = {
|
||||
data: [
|
||||
status1
|
||||
],
|
||||
|
|
|
@ -1,178 +0,0 @@
|
|||
import Mastodon from 'megalodon'
|
||||
import { createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import Mentions from '~/src/renderer/store/TimelineSpace/Contents/Mentions'
|
||||
|
||||
jest.genMockFromModule('megalodon')
|
||||
jest.mock('megalodon')
|
||||
|
||||
let state = () => {
|
||||
return {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
mentions: [],
|
||||
unreadMentions: [],
|
||||
filter: ''
|
||||
}
|
||||
}
|
||||
|
||||
const initStore = () => {
|
||||
return {
|
||||
namespaced: true,
|
||||
state: state(),
|
||||
actions: Mentions.actions,
|
||||
mutations: Mentions.mutations,
|
||||
getters: Mentions.getters
|
||||
}
|
||||
}
|
||||
const timelineState = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
account: {
|
||||
accessToken: 'token',
|
||||
baseURL: 'http://localhost'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('Mentions', () => {
|
||||
let store
|
||||
let localVue
|
||||
|
||||
beforeEach(() => {
|
||||
localVue = createLocalVue()
|
||||
localVue.use(Vuex)
|
||||
store = new Vuex.Store({
|
||||
modules: {
|
||||
Mentions: initStore(),
|
||||
TimelineSpace: timelineState
|
||||
}
|
||||
})
|
||||
Mastodon.mockClear()
|
||||
})
|
||||
|
||||
describe('fetchMentions', () => {
|
||||
it('should be updated', async () => {
|
||||
const mockClient = {
|
||||
get: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
data: [
|
||||
{ id: 1, type: 'mention' },
|
||||
{ id: 2, type: 'favourite' },
|
||||
{ id: 3, type: 'reblog' },
|
||||
{ id: 4, type: 'follow' }
|
||||
]
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Mastodon.mockImplementation(() => mockClient)
|
||||
await store.dispatch('Mentions/fetchMentions')
|
||||
expect(store.state.Mentions.mentions).toEqual([
|
||||
{ id: 1, type: 'mention' },
|
||||
{ id: 2, type: 'favourite' },
|
||||
{ id: 3, type: 'reblog' },
|
||||
{ id: 4, type: 'follow' }
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('lazyFetchMentions', () => {
|
||||
describe('last is null', () => {
|
||||
it('should not be updated', async () => {
|
||||
const result = await store.dispatch('Mentions/lazyFetchMentions', null)
|
||||
expect(result).toEqual(null)
|
||||
})
|
||||
})
|
||||
|
||||
describe('loading', () => {
|
||||
beforeAll(() => {
|
||||
state = () => {
|
||||
return {
|
||||
lazyLoading: true,
|
||||
heading: true,
|
||||
mentions: [],
|
||||
unreadMentions: [],
|
||||
filter: ''
|
||||
}
|
||||
}
|
||||
})
|
||||
it('should not be updated', async () => {
|
||||
const result = await store.dispatch('Mentions/lazyFetchMentions', {})
|
||||
expect(result).toEqual(null)
|
||||
})
|
||||
})
|
||||
|
||||
describe('success', () => {
|
||||
beforeAll(() => {
|
||||
state = () => {
|
||||
return {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
mentions: [
|
||||
{ id: 1, type: 'mention' },
|
||||
{ id: 2, type: 'favourite' },
|
||||
{ id: 3, type: 'reblog' },
|
||||
{ id: 4, type: 'follow' }
|
||||
],
|
||||
unreadMentions: [],
|
||||
filter: ''
|
||||
}
|
||||
}
|
||||
})
|
||||
it('should be updated', async () => {
|
||||
const mockClient = {
|
||||
get: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
data: [
|
||||
{ id: 5, type: 'mention' },
|
||||
{ id: 6, type: 'favourite' }
|
||||
]
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Mastodon.mockImplementation(() => mockClient)
|
||||
await store.dispatch('Mentions/lazyFetchMentions', { id: 1 })
|
||||
expect(store.state.Mentions.mentions).toEqual([
|
||||
{ id: 1, type: 'mention' },
|
||||
{ id: 2, type: 'favourite' },
|
||||
{ id: 3, type: 'reblog' },
|
||||
{ id: 4, type: 'follow' },
|
||||
{ id: 5, type: 'mention' },
|
||||
{ id: 6, type: 'favourite' }
|
||||
])
|
||||
expect(store.state.Mentions.lazyLoading).toEqual(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('mentions', () => {
|
||||
beforeAll(() => {
|
||||
state = () => {
|
||||
return {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
mentions: [
|
||||
{ id: 1, type: 'mention' },
|
||||
{ id: 2, type: 'favourite' },
|
||||
{ id: 3, type: 'reblog' },
|
||||
{ id: 4, type: 'follow' }
|
||||
],
|
||||
unreadMentions: [],
|
||||
filter: ''
|
||||
}
|
||||
}
|
||||
})
|
||||
it('should return only mentions', () => {
|
||||
const mentions = store.getters['Mentions/mentions']
|
||||
expect(mentions).toEqual([
|
||||
{ id: 1, type: 'mention' }
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
|
@ -0,0 +1,267 @@
|
|||
import { Response, Account, Notification, Status, Application } from 'megalodon'
|
||||
import mockedMegalodon from '~/spec/mock/megalodon'
|
||||
import { createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import Mentions from '~/src/renderer/store/TimelineSpace/Contents/Mentions'
|
||||
|
||||
jest.mock('megalodon')
|
||||
|
||||
const account: Account = {
|
||||
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,
|
||||
}
|
||||
|
||||
const status: Status = {
|
||||
id: 1,
|
||||
uri: "http://example.com",
|
||||
url: "http://example.com",
|
||||
account: account,
|
||||
in_reply_to_id: null,
|
||||
in_reply_to_account_id: null,
|
||||
reblog: null,
|
||||
content: "hoge",
|
||||
created_at: "2019-03-26T21:40:32",
|
||||
emojis: [],
|
||||
replies_count: 0,
|
||||
reblogs_count: 0,
|
||||
favourites_count: 0,
|
||||
reblogged: null,
|
||||
favourited: null,
|
||||
muted: null,
|
||||
sensitive: false,
|
||||
spoiler_text: "",
|
||||
visibility: 'public',
|
||||
media_attachments: [],
|
||||
mentions: [],
|
||||
tags: [],
|
||||
card: null,
|
||||
application: {
|
||||
name: "Web"
|
||||
} as Application,
|
||||
language: null,
|
||||
pinned: null
|
||||
}
|
||||
|
||||
const mention: Notification = {
|
||||
account: account,
|
||||
created_at: '2019-03-26T21:40:32',
|
||||
id: 1,
|
||||
status: status,
|
||||
type: 'mention'
|
||||
}
|
||||
|
||||
const reblog: Notification = {
|
||||
account: account,
|
||||
created_at: '2019-03-26T21:40:32',
|
||||
id: 2,
|
||||
status: status,
|
||||
type: 'reblog'
|
||||
}
|
||||
|
||||
const favourite: Notification = {
|
||||
account: account,
|
||||
created_at: '2019-03-26T21:40:32',
|
||||
id: 3,
|
||||
status: status,
|
||||
type: 'favourite'
|
||||
}
|
||||
|
||||
const follow: Notification = {
|
||||
account: account,
|
||||
created_at: '2019-03-26T21:40:32',
|
||||
id: 4,
|
||||
status: null,
|
||||
type: 'follow'
|
||||
}
|
||||
|
||||
let state: Function = () => {
|
||||
return {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
mentions: [],
|
||||
unreadMentions: [],
|
||||
filter: ''
|
||||
}
|
||||
}
|
||||
|
||||
const initStore = () => {
|
||||
return {
|
||||
namespaced: true,
|
||||
state: state(),
|
||||
actions: Mentions.actions,
|
||||
mutations: Mentions.mutations,
|
||||
getters: Mentions.getters
|
||||
}
|
||||
}
|
||||
const timelineState = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
account: {
|
||||
accessToken: 'token',
|
||||
baseURL: 'http://localhost'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('Mentions', () => {
|
||||
let store
|
||||
let localVue
|
||||
|
||||
beforeEach(() => {
|
||||
localVue = createLocalVue()
|
||||
localVue.use(Vuex)
|
||||
store = new Vuex.Store({
|
||||
modules: {
|
||||
Mentions: initStore(),
|
||||
TimelineSpace: timelineState
|
||||
}
|
||||
})
|
||||
mockedMegalodon.mockClear()
|
||||
})
|
||||
|
||||
describe('fetchMentions', () => {
|
||||
it('should be updated', async () => {
|
||||
const mockClient = {
|
||||
get: (_path: string, _params: object) => {
|
||||
return new Promise<Response<Notification[]>>((resolve, _) => {
|
||||
const res: Response<Notification[]> = {
|
||||
data: [
|
||||
mention,
|
||||
reblog,
|
||||
favourite,
|
||||
follow
|
||||
],
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {}
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
mockedMegalodon.mockImplementation(() => mockClient)
|
||||
await store.dispatch('Mentions/fetchMentions')
|
||||
expect(store.state.Mentions.mentions).toEqual([
|
||||
mention,
|
||||
reblog,
|
||||
favourite,
|
||||
follow
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('lazyFetchMentions', () => {
|
||||
describe('last is null', () => {
|
||||
it('should not be updated', async () => {
|
||||
const result = await store.dispatch('Mentions/lazyFetchMentions', null)
|
||||
expect(result).toEqual(null)
|
||||
})
|
||||
})
|
||||
|
||||
describe('loading', () => {
|
||||
beforeAll(() => {
|
||||
state = () => {
|
||||
return {
|
||||
lazyLoading: true,
|
||||
heading: true,
|
||||
mentions: [],
|
||||
unreadMentions: [],
|
||||
filter: ''
|
||||
}
|
||||
}
|
||||
})
|
||||
it('should not be updated', async () => {
|
||||
const result = await store.dispatch('Mentions/lazyFetchMentions', {})
|
||||
expect(result).toEqual(null)
|
||||
})
|
||||
})
|
||||
|
||||
describe('success', () => {
|
||||
beforeAll(() => {
|
||||
state = () => {
|
||||
return {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
mentions: [
|
||||
mention,
|
||||
reblog
|
||||
],
|
||||
unreadMentions: [],
|
||||
filter: ''
|
||||
}
|
||||
}
|
||||
})
|
||||
it('should be updated', async () => {
|
||||
const mockClient = {
|
||||
get: (_path: string, _params: object) => {
|
||||
return new Promise<Response<Notification[]>>((resolve, _) => {
|
||||
const res: Response<Notification[]> = {
|
||||
data: [
|
||||
favourite,
|
||||
follow
|
||||
],
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {}
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
mockedMegalodon.mockImplementation(() => mockClient)
|
||||
await store.dispatch('Mentions/lazyFetchMentions', { id: 1 })
|
||||
expect(store.state.Mentions.mentions).toEqual([
|
||||
mention,
|
||||
reblog,
|
||||
favourite,
|
||||
follow
|
||||
])
|
||||
expect(store.state.Mentions.lazyLoading).toEqual(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('mentions', () => {
|
||||
beforeAll(() => {
|
||||
state = () => {
|
||||
return {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
mentions: [
|
||||
mention,
|
||||
favourite,
|
||||
reblog,
|
||||
follow
|
||||
],
|
||||
unreadMentions: [],
|
||||
filter: ''
|
||||
}
|
||||
}
|
||||
})
|
||||
it('should return only mentions', () => {
|
||||
const mentions = store.getters['Mentions/mentions']
|
||||
expect(mentions).toEqual([
|
||||
mention
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,11 +1,16 @@
|
|||
import Mastodon from 'megalodon'
|
||||
import { Response, List } from 'megalodon'
|
||||
import mockedMegalodon from '~/spec/mock/megalodon'
|
||||
import { createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import HeaderMenu from '~/src/renderer/store/TimelineSpace/HeaderMenu'
|
||||
|
||||
jest.genMockFromModule('megalodon')
|
||||
jest.mock('megalodon')
|
||||
|
||||
const list: List = {
|
||||
id: 1,
|
||||
title: "example"
|
||||
}
|
||||
|
||||
const state = () => {
|
||||
return {
|
||||
title: 'Home',
|
||||
|
@ -45,29 +50,29 @@ describe('HeaderMenu', () => {
|
|||
TimelineSpace: timelineState
|
||||
}
|
||||
})
|
||||
Mastodon.mockClear()
|
||||
mockedMegalodon.mockClear()
|
||||
})
|
||||
|
||||
describe('fetchLists', () => {
|
||||
it('should be updated', async () => {
|
||||
const mockClient = {
|
||||
get: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
data: {
|
||||
title: 'list1'
|
||||
}
|
||||
})
|
||||
get: (_path: string, _params: object) => {
|
||||
return new Promise<Response<List>>((resolve, _) => {
|
||||
const res: Response<List> = {
|
||||
data: list,
|
||||
status: 200,
|
||||
statusText: "OK",
|
||||
headers: {}
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Mastodon.mockImplementation(() => mockClient)
|
||||
const list = await store.dispatch('HeaderMenu/fetchList', 1)
|
||||
expect(list).toEqual({
|
||||
title: 'list1'
|
||||
})
|
||||
expect(store.state.HeaderMenu.title).toEqual('#list1')
|
||||
mockedMegalodon.mockImplementation(() => mockClient)
|
||||
const l = await store.dispatch('HeaderMenu/fetchList', list.id)
|
||||
expect(l).toEqual(list)
|
||||
expect(store.state.HeaderMenu.title).toEqual(`#${list.title}`)
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,11 +1,34 @@
|
|||
import Mastodon from 'megalodon'
|
||||
import { Response, Account } from 'megalodon'
|
||||
import mockedMegalodon from '~/spec/mock/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 account: Account = {
|
||||
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,
|
||||
}
|
||||
|
||||
|
||||
const state = () => {
|
||||
return {
|
||||
modalOpen: false,
|
||||
|
@ -45,7 +68,7 @@ describe('AddListMember', () => {
|
|||
TimelineSpace: timelineState
|
||||
}
|
||||
})
|
||||
Mastodon.mockClear()
|
||||
mockedMegalodon.mockClear()
|
||||
})
|
||||
|
||||
describe('changeModal', () => {
|
||||
|
@ -59,22 +82,24 @@ describe('AddListMember', () => {
|
|||
it('should be searched', async () => {
|
||||
const mockClient = {
|
||||
get: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
return new Promise<Response<Account[]>>((resolve, _) => {
|
||||
const res: Response<Account[]> = {
|
||||
data: [
|
||||
{ id: 1, name: 'h3poteto' },
|
||||
{ id: 2, name: 'akito19' }
|
||||
]
|
||||
})
|
||||
account
|
||||
],
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {}
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Mastodon.mockImplementation(() => mockClient)
|
||||
mockedMegalodon.mockImplementation(() => mockClient)
|
||||
await store.dispatch('AddListMember/search', 'akira')
|
||||
expect(store.state.AddListMember.accounts).toEqual([
|
||||
{ id: 1, name: 'h3poteto' },
|
||||
{ id: 2, name: 'akito19' }
|
||||
account
|
||||
])
|
||||
})
|
||||
})
|
||||
|
@ -83,17 +108,21 @@ describe('AddListMember', () => {
|
|||
it('should be added a member to the list', async () => {
|
||||
const mockClient = {
|
||||
post: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
data: true
|
||||
})
|
||||
return new Promise<Response>((resolve, _) => {
|
||||
const res: Response = {
|
||||
data: {},
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {}
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Mastodon.mockImplementation(() => mockClient)
|
||||
mockedMegalodon.mockImplementation(() => mockClient)
|
||||
const result = await store.dispatch('AddListMember/add', 'akira')
|
||||
expect(result.data).toEqual(true)
|
||||
expect(result.data).toEqual({})
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,12 +1,22 @@
|
|||
import Mastodon from 'megalodon'
|
||||
import { Response, List } from 'megalodon'
|
||||
import mockedMegalodon from '~/spec/mock/megalodon'
|
||||
import { createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import ListMembership from '~/src/renderer/store/TimelineSpace/Modals/ListMembership'
|
||||
|
||||
jest.genMockFromModule('megalodon')
|
||||
jest.mock('megalodon')
|
||||
|
||||
let state = () => {
|
||||
const list1: List = {
|
||||
id: 1,
|
||||
title: 'list1'
|
||||
}
|
||||
|
||||
const list2: List = {
|
||||
id: 2,
|
||||
title: 'list2'
|
||||
}
|
||||
|
||||
let state: any = () => {
|
||||
return {
|
||||
modalOpen: false,
|
||||
account: null,
|
||||
|
@ -46,53 +56,57 @@ describe('ListMembership', () => {
|
|||
TimelineSpace: timelineState
|
||||
}
|
||||
})
|
||||
Mastodon.mockClear()
|
||||
})
|
||||
|
||||
describe('fetchListMembership', () => {
|
||||
it('should be changed', async () => {
|
||||
const mockClient = {
|
||||
get: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
get: (_path: string, _params: object) => {
|
||||
return new Promise<Response<List[]>>((resolve, _) => {
|
||||
const res: Response<List[]> = {
|
||||
data: [
|
||||
{ id: 1 },
|
||||
{ id: 2 },
|
||||
{ id: 3 }
|
||||
]
|
||||
})
|
||||
list1,
|
||||
list2
|
||||
],
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {}
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
Mastodon.mockImplementation(() => mockClient)
|
||||
mockedMegalodon.mockImplementation(() => mockClient)
|
||||
await store.dispatch('ListMembership/fetchListMembership', {
|
||||
id: 5
|
||||
})
|
||||
expect(store.state.ListMembership.belongToLists).toEqual([1, 2, 3])
|
||||
expect(store.state.ListMembership.belongToLists).toEqual([1, 2])
|
||||
})
|
||||
})
|
||||
|
||||
describe('fetchLists', () => {
|
||||
it('should be changed', async () => {
|
||||
const mockClient = {
|
||||
get: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
get: (_path: string, _params: object) => {
|
||||
return new Promise<Response<List[]>>((resolve, _) => {
|
||||
const res: Response<List[]> = {
|
||||
data: [
|
||||
{ id: 1, name: 'list1' },
|
||||
{ id: 2, name: 'list2' },
|
||||
{ id: 3, name: 'list3' }
|
||||
]
|
||||
})
|
||||
list1,
|
||||
list2
|
||||
],
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {}
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
Mastodon.mockImplementation(() => mockClient)
|
||||
mockedMegalodon.mockImplementation(() => mockClient)
|
||||
await store.dispatch('ListMembership/fetchLists')
|
||||
expect(store.state.ListMembership.lists).toEqual([
|
||||
{ id: 1, name: 'list1' },
|
||||
{ id: 2, name: 'list2' },
|
||||
{ id: 3, name: 'list3' }
|
||||
list1,
|
||||
list2
|
||||
])
|
||||
})
|
||||
})
|
||||
|
@ -107,31 +121,39 @@ describe('ListMembership', () => {
|
|||
},
|
||||
lists: [],
|
||||
belongToLists: [
|
||||
{ id: 2, name: 'list2' }
|
||||
list2
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
it('should be changed', async () => {
|
||||
const mockClient = {
|
||||
del: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
data: true
|
||||
})
|
||||
del: (_path: string, _params: object) => {
|
||||
return new Promise<Response>((resolve, _) => {
|
||||
const res: Response = {
|
||||
data: {},
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {}
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
},
|
||||
post: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
data: true
|
||||
})
|
||||
post: (_path: string, _params: object) => {
|
||||
return new Promise<Response>((resolve, _) => {
|
||||
const res: Response = {
|
||||
data: {},
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {}
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
Mastodon.mockImplementation(() => mockClient)
|
||||
await store.dispatch('ListMembership/changeBelongToLists', [{ id: 1, name: 'list1' }])
|
||||
expect(store.state.ListMembership.belongToLists).toEqual([{ id: 1, name: 'list1' }])
|
||||
mockedMegalodon.mockImplementation(() => mockClient)
|
||||
await store.dispatch('ListMembership/changeBelongToLists', [list1])
|
||||
expect(store.state.ListMembership.belongToLists).toEqual([list1])
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,12 +1,22 @@
|
|||
import Mastodon from 'megalodon'
|
||||
import { Response, List } from 'megalodon'
|
||||
import mockedMegalodon from '~/spec/mock/megalodon'
|
||||
import { createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import { ipcMain } from '~/spec/mock/electron'
|
||||
import SideMenu from '~/src/renderer/store/TimelineSpace/SideMenu'
|
||||
|
||||
jest.genMockFromModule('megalodon')
|
||||
jest.mock('megalodon')
|
||||
|
||||
const list1: List = {
|
||||
id: 1,
|
||||
title: "example1"
|
||||
}
|
||||
|
||||
const list2: List = {
|
||||
id: 2,
|
||||
title: "example2"
|
||||
}
|
||||
|
||||
const state = () => {
|
||||
return {
|
||||
unreadHomeTimeline: false,
|
||||
|
@ -41,32 +51,36 @@ describe('SideMenu', () => {
|
|||
SideMenu: initStore()
|
||||
}
|
||||
})
|
||||
Mastodon.mockClear()
|
||||
mockedMegalodon.mockClear()
|
||||
})
|
||||
|
||||
describe('fetchLists', () => {
|
||||
it('should be updated', async () => {
|
||||
const mockClient = {
|
||||
get: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
get: (_path: string, _params: object) => {
|
||||
return new Promise<Response<List[]>>((resolve, _) => {
|
||||
const res: Response<List[]> = {
|
||||
data: [
|
||||
'list1',
|
||||
'list2'
|
||||
]
|
||||
})
|
||||
list1,
|
||||
list2
|
||||
],
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {}
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Mastodon.mockImplementation(() => mockClient)
|
||||
mockedMegalodon.mockImplementation(() => mockClient)
|
||||
const account = {
|
||||
accessToken: 'token',
|
||||
baseURL: 'http://localhost'
|
||||
}
|
||||
const lists = await store.dispatch('SideMenu/fetchLists', account)
|
||||
expect(store.state.SideMenu.lists).toEqual(['list1', 'list2'])
|
||||
expect(lists).toEqual(['list1', 'list2'])
|
||||
expect(store.state.SideMenu.lists).toEqual([list1, list2])
|
||||
expect(lists).toEqual([list1, list2])
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -90,7 +104,7 @@ describe('SideMenu', () => {
|
|||
|
||||
describe('readCollapse', () => {
|
||||
it('should be read', async () => {
|
||||
ipcMain.once('get-collapse', (event, _) => {
|
||||
ipcMain.once('get-collapse', (event: any, _) => {
|
||||
event.sender.send('response-get-collapse', true)
|
||||
})
|
||||
await store.dispatch('SideMenu/readCollapse')
|
||||
|
@ -100,7 +114,7 @@ describe('SideMenu', () => {
|
|||
|
||||
describe('listTags', () => {
|
||||
it('should be listed', async () => {
|
||||
ipcMain.once('list-hashtags', (event, _) => {
|
||||
ipcMain.once('list-hashtags', (event: any, _) => {
|
||||
event.sender.send('response-list-hashtags', ['tag1', 'tag2'])
|
||||
})
|
||||
await store.dispatch('SideMenu/listTags')
|
Loading…
Reference in New Issue