From 8aec798820316875cacb7a76b353d58d55c8003f Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Tue, 18 Jun 2019 20:16:43 +0900
Subject: [PATCH] refs #209 Add integration tests for Lists/Index
---
.../Contents/Lists/Index.spec.ts | 98 +++++++++++++++++++
1 file changed, 98 insertions(+)
create mode 100644 spec/renderer/integration/store/TimelineSpace/Contents/Lists/Index.spec.ts
diff --git a/spec/renderer/integration/store/TimelineSpace/Contents/Lists/Index.spec.ts b/spec/renderer/integration/store/TimelineSpace/Contents/Lists/Index.spec.ts
new file mode 100644
index 00000000..6e562250
--- /dev/null
+++ b/spec/renderer/integration/store/TimelineSpace/Contents/Lists/Index.spec.ts
@@ -0,0 +1,98 @@
+import { Response, List } from 'megalodon'
+import mockedMegalodon from '~/spec/mock/megalodon'
+import { createLocalVue } from '@vue/test-utils'
+import Vuex from 'vuex'
+import Index, { IndexState } from '@/store/TimelineSpace/Contents/Lists/Index'
+
+jest.mock('megalodon')
+
+const list: List = {
+ id: '1',
+ title: 'list1'
+}
+
+let state = (): IndexState => {
+ return {
+ lists: []
+ }
+}
+
+const initStore = () => {
+ return {
+ namespaced: true,
+ state: state(),
+ actions: Index.actions,
+ mutations: Index.mutations
+ }
+}
+
+const timelineState = {
+ namespaced: true,
+ state: {
+ account: {
+ accessToken: 'token',
+ baseURL: 'http://localhost'
+ }
+ }
+}
+
+describe('Lists/Index', () => {
+ let store
+ let localVue
+
+ beforeEach(() => {
+ localVue = createLocalVue()
+ localVue.use(Vuex)
+ store = new Vuex.Store({
+ modules: {
+ Index: initStore(),
+ TimelineSpace: timelineState
+ }
+ })
+ mockedMegalodon.mockClear()
+ })
+
+ describe('fetchLists', () => {
+ it('should be updated', async () => {
+ const mockClient = {
+ get: (_path: string, _params: object) => {
+ return new Promise>>(resolve => {
+ const res: Response> = {
+ data: [list],
+ status: 200,
+ statusText: 'OK',
+ headers: {}
+ }
+ resolve(res)
+ })
+ }
+ }
+
+ mockedMegalodon.mockImplementation(() => mockClient)
+ await store.dispatch('Index/fetchLists')
+ expect(store.state.Index.lists).toEqual([list])
+ })
+ })
+
+ describe('createList', () => {
+ it('should be created', async () => {
+ const mockClient = {
+ post: (_path: string, _params: object) => {
+ return new Promise>(resolve => {
+ const res: Response = {
+ data: list,
+ status: 200,
+ statusText: 'OK',
+ headers: {}
+ }
+ resolve(res)
+ })
+ }
+ }
+
+ mockedMegalodon.mockImplementation(() => mockClient)
+ const res: List = await store.dispatch('Index/createList', 'list1')
+ expect(res.title).toEqual('list1')
+ })
+ })
+})