mirror of https://github.com/doccano/doccano.git
10 changed files with 0 additions and 374 deletions
Split View
Diff Options
-
40frontend/test/unit/components/containers/ProjectCreationButton.spec.js
-
40frontend/test/unit/components/containers/ProjectDeletionButton.spec.js
-
40frontend/test/unit/components/containers/ProjectList.spec.js
-
0frontend/test/unit/components/molecules/.gitkeep
-
58frontend/test/unit/components/organisms/ProjecCreationForm.spec.js
-
64frontend/test/unit/components/organisms/ProjectList.spec.js
-
18frontend/test/unit/plugins/filters.spec.js
-
56frontend/test/unit/services/api.service.spec.js
-
12frontend/test/unit/services/csv.service.spec.js
-
46frontend/test/unit/services/project.service.spec.js
@ -1,40 +0,0 @@ |
|||
import { shallowMount, createLocalVue } from '@vue/test-utils' |
|||
import Vue from 'vue' |
|||
import Vuex from 'vuex' |
|||
import Vuetify from 'vuetify' |
|||
import ProjectCreationButton from '@/components/containers/ProjectCreationButton' |
|||
const localVue = createLocalVue() |
|||
localVue.use(Vuex) |
|||
Vue.use(Vuetify) |
|||
|
|||
describe('ProjectCreationButtonContainer', () => { |
|||
let store |
|||
let projects |
|||
let actions |
|||
let mutations |
|||
|
|||
beforeEach(() => { |
|||
actions = { |
|||
createProject: jest.fn() |
|||
} |
|||
mutations = {} |
|||
projects = { |
|||
namespaced: true, |
|||
actions, |
|||
mutations, |
|||
state: {} |
|||
} |
|||
|
|||
store = new Vuex.Store({ |
|||
modules: { |
|||
projects |
|||
} |
|||
}) |
|||
}) |
|||
|
|||
test('called createProject action', () => { |
|||
const wrapper = shallowMount(ProjectCreationButton, { store, localVue }) |
|||
wrapper.vm.createProject() |
|||
expect(actions.createProject).toHaveBeenCalled() |
|||
}) |
|||
}) |
@ -1,40 +0,0 @@ |
|||
import { shallowMount, createLocalVue } from '@vue/test-utils' |
|||
import Vue from 'vue' |
|||
import Vuex from 'vuex' |
|||
import Vuetify from 'vuetify' |
|||
import ProjectDeletionButton from '@/components/containers/ProjectDeletionButton' |
|||
const localVue = createLocalVue() |
|||
localVue.use(Vuex) |
|||
Vue.use(Vuetify) |
|||
|
|||
describe('ProjectDeletionButtonContainer', () => { |
|||
let store |
|||
let projects |
|||
let actions |
|||
let mutations |
|||
|
|||
beforeEach(() => { |
|||
actions = { |
|||
deleteProject: jest.fn() |
|||
} |
|||
mutations = {} |
|||
projects = { |
|||
namespaced: true, |
|||
actions, |
|||
mutations, |
|||
state: {} |
|||
} |
|||
|
|||
store = new Vuex.Store({ |
|||
modules: { |
|||
projects |
|||
} |
|||
}) |
|||
}) |
|||
|
|||
test('called deleteProject action', () => { |
|||
const wrapper = shallowMount(ProjectDeletionButton, { store, localVue }) |
|||
wrapper.vm.handleDeleteProject() |
|||
expect(actions.deleteProject).toHaveBeenCalled() |
|||
}) |
|||
}) |
@ -1,40 +0,0 @@ |
|||
import { shallowMount, createLocalVue } from '@vue/test-utils' |
|||
import Vuex from 'vuex' |
|||
import ProjectList from '@/components/containers/ProjectList' |
|||
|
|||
const localVue = createLocalVue() |
|||
localVue.use(Vuex) |
|||
|
|||
describe('ProjectListContainer', () => { |
|||
let store |
|||
let projects |
|||
let actions |
|||
let mutations |
|||
|
|||
beforeEach(() => { |
|||
actions = { |
|||
getProjectList: jest.fn() |
|||
} |
|||
mutations = { |
|||
updateSelected: jest.fn() |
|||
} |
|||
projects = { |
|||
namespaced: true, |
|||
actions, |
|||
mutations, |
|||
state: {} |
|||
} |
|||
|
|||
store = new Vuex.Store({ |
|||
modules: { |
|||
projects |
|||
} |
|||
}) |
|||
}) |
|||
|
|||
test('called updateSelected method', () => { |
|||
const wrapper = shallowMount(ProjectList, { store, localVue }) |
|||
wrapper.vm.update() |
|||
expect(mutations.updateSelected).toHaveBeenCalled() |
|||
}) |
|||
}) |
@ -1,58 +0,0 @@ |
|||
import { shallowMount } from '@vue/test-utils' |
|||
import Vue from 'vue' |
|||
import Vuetify from 'vuetify' |
|||
import ProjectCreationForm from '@/components/organisms/ProjectCreationForm' |
|||
|
|||
Vue.use(Vuetify) |
|||
|
|||
describe('ProjectCreationForm', () => { |
|||
const factory = (propsData) => { |
|||
return shallowMount(ProjectCreationForm, { |
|||
propsData: { |
|||
...propsData |
|||
} |
|||
}) |
|||
} |
|||
const createProject = () => { } |
|||
const projectTypes = [] |
|||
|
|||
test('can receive props', () => { |
|||
const wrapper = factory({ createProject, projectTypes }) |
|||
expect(wrapper.props()).toEqual({ createProject, projectTypes }) |
|||
}) |
|||
|
|||
test('emit close event', () => { |
|||
const wrapper = factory({ createProject, projectTypes }) |
|||
wrapper.vm.cancel() |
|||
expect(wrapper.emitted('close')).toBeTruthy() |
|||
}) |
|||
|
|||
test('emit close event when form is valid', () => { |
|||
const wrapper = factory({ createProject, projectTypes }) |
|||
wrapper.setMethods({ |
|||
validate: jest.fn(() => true), |
|||
reset: jest.fn() |
|||
}) |
|||
wrapper.vm.create() |
|||
expect(wrapper.emitted('close')).toBeTruthy() |
|||
}) |
|||
|
|||
test('do not emit close event when form is invalid', () => { |
|||
const wrapper = factory({ createProject, projectTypes }) |
|||
wrapper.setMethods({ |
|||
validate: jest.fn(() => false), |
|||
reset: jest.fn() |
|||
}) |
|||
wrapper.vm.create() |
|||
expect(wrapper.emitted('close')).toBeFalsy() |
|||
}) |
|||
|
|||
test('raise warning when passing no props', () => { |
|||
const spy = jest.spyOn(console, 'error') |
|||
spy.mockImplementation() |
|||
expect(spy).toBeCalledWith( |
|||
expect.stringContaining('[Vue warn]: Missing required prop') |
|||
) |
|||
spy.mockRestore() |
|||
}) |
|||
}) |
@ -1,64 +0,0 @@ |
|||
import { shallowMount } from '@vue/test-utils' |
|||
import Vue from 'vue' |
|||
import Vuetify from 'vuetify' |
|||
import ProjectList from '@/components/organisms/ProjectList' |
|||
|
|||
Vue.use(Vuetify) |
|||
|
|||
describe('ProjectList', () => { |
|||
const projects = [ |
|||
{ |
|||
id: 1, |
|||
name: 'CoNLL 2003', |
|||
description: 'This is a project for NER.', |
|||
guideline: 'Please write annotation guideline.', |
|||
users: [ |
|||
1 |
|||
], |
|||
project_type: 'SequenceLabeling', |
|||
image: '/static/assets/images/cats/sequence_labeling.jpg', |
|||
updated_at: '2019-07-09T06:19:29.789091Z', |
|||
randomize_document_order: false, |
|||
resourcetype: 'SequenceLabelingProject' |
|||
} |
|||
] |
|||
const headers = [ |
|||
{ |
|||
text: 'Name', |
|||
align: 'left', |
|||
value: 'name' |
|||
}, |
|||
{ |
|||
text: 'Description', |
|||
value: 'description' |
|||
}, |
|||
{ |
|||
text: 'Type', |
|||
value: 'project_type' |
|||
} |
|||
] |
|||
const selected = [] |
|||
const loading = false |
|||
|
|||
test('can receive props', () => { |
|||
const propsData = { projects, headers, selected, loading } |
|||
const wrapper = shallowMount(ProjectList, { propsData }) |
|||
expect(wrapper.props()).toEqual(propsData) |
|||
}) |
|||
|
|||
test('emitted update event', () => { |
|||
const propsData = { projects, headers, selected, loading } |
|||
const wrapper = shallowMount(ProjectList, { propsData }) |
|||
wrapper.vm.update(propsData) |
|||
expect(wrapper.emitted('update')).toBeTruthy() |
|||
}) |
|||
|
|||
test('raise warning when passing props', () => { |
|||
const spy = jest.spyOn(console, 'error') |
|||
spy.mockImplementation() |
|||
expect(spy).toBeCalledWith( |
|||
expect.stringContaining('[Vue warn]: Missing required prop') |
|||
) |
|||
spy.mockRestore() |
|||
}) |
|||
}) |
@ -1,18 +0,0 @@ |
|||
import { truncate } from '@/plugins/filters.js' |
|||
|
|||
describe('Truncate', () => { |
|||
test('dont do nothing', () => { |
|||
const string = 'aiueo' |
|||
expect(truncate(string)).toEqual(string) |
|||
}) |
|||
|
|||
test('cut the string and add clamp if string length is larger than specified length', () => { |
|||
const string = 'aiueo' |
|||
expect(truncate(string, 3)).toEqual('aiu...') |
|||
}) |
|||
|
|||
test('dont cut anything if string length is smaller than specified length', () => { |
|||
const string = 'aiueo' |
|||
expect(truncate(string, 10)).toEqual(string) |
|||
}) |
|||
}) |
@ -1,56 +0,0 @@ |
|||
import MockAdapter from 'axios-mock-adapter' |
|||
import ApiService from '@/services/api.service' |
|||
|
|||
describe('Request', () => { |
|||
const r = new ApiService('') |
|||
const mockAxios = new MockAdapter(r.instance) |
|||
|
|||
test('can get resources', async() => { |
|||
const data = [ |
|||
{ |
|||
id: 1, |
|||
title: 'title', |
|||
body: 'body' |
|||
} |
|||
] |
|||
mockAxios.onGet('/posts').reply(200, data) |
|||
const response = await r.get('/posts') |
|||
expect(response).toEqual(data) |
|||
}) |
|||
|
|||
test('can create a resource', async() => { |
|||
const data = { |
|||
title: 'foo', |
|||
body: 'bar' |
|||
} |
|||
mockAxios.onPost('/posts').reply(201, data) |
|||
const response = await r.post('/posts', data) |
|||
expect(response.title).toEqual(data.title) |
|||
}) |
|||
|
|||
test('can update a resource', async() => { |
|||
const data = { |
|||
id: 1, |
|||
title: 'foo', |
|||
body: 'bar' |
|||
} |
|||
mockAxios.onPut('/posts/1').reply(204, data) |
|||
const response = await r.put('/posts/1', data) |
|||
expect(response.title).toEqual(data.title) |
|||
}) |
|||
|
|||
test('can partially update a resource', async() => { |
|||
const data = { |
|||
title: 'foo' |
|||
} |
|||
mockAxios.onPatch('/posts/1').reply(200, data) |
|||
const response = await r.patch('/posts/1', data) |
|||
expect(response.title).toEqual(data.title) |
|||
}) |
|||
|
|||
test('can delete a resource', async() => { |
|||
mockAxios.onDelete('/posts/1').reply(204, {}) |
|||
const response = await r.delete('/posts/1') |
|||
expect(response).toEqual({}) |
|||
}) |
|||
}) |
@ -1,12 +0,0 @@ |
|||
import CSVParser from '@/services/parsers/csv.service' |
|||
|
|||
describe('Request', () => { |
|||
const parser = new CSVParser() |
|||
|
|||
test('can parse text', () => { |
|||
const text = 'col 1,col 2\n1,2' |
|||
const parsed = parser.parse(text) |
|||
expect(parsed.meta.fields).toEqual(['col 1', 'col 2']) |
|||
expect(parsed.data[0]['col 1']).toEqual('1') |
|||
}) |
|||
}) |
@ -1,46 +0,0 @@ |
|||
import MockAdapter from 'axios-mock-adapter' |
|||
import ProjectService from '@/services/project.service.js' |
|||
|
|||
describe('Project.service', () => { |
|||
const mockAxios = new MockAdapter(ProjectService.request.instance) |
|||
|
|||
test('can get project list', async() => { |
|||
const data = [ |
|||
{ |
|||
id: 1, |
|||
name: 'CoNLL 2003', |
|||
description: 'This is a project for NER.', |
|||
guideline: 'Please write annotation guideline.', |
|||
users: [1], |
|||
project_type: 'SequenceLabeling', |
|||
image: '/static/assets/images/cats/sequence_labeling.jpg', |
|||
updated_at: '2019-07-09T06:19:29.789091Z', |
|||
randomize_document_order: false, |
|||
resourcetype: 'SequenceLabelingProject' |
|||
} |
|||
] |
|||
mockAxios.onGet('/projects').reply(200, data) |
|||
const response = await ProjectService.getProjectList() |
|||
expect(response).toEqual(data) |
|||
}) |
|||
|
|||
test('can create a project', async() => { |
|||
const data = { |
|||
name: 'test project', |
|||
description: 'test description', |
|||
guideline: 'Please write annotation guideline.', |
|||
project_type: 'SequenceLabeling', |
|||
randomize_document_order: false |
|||
} |
|||
mockAxios.onPost('/projects').reply(201, data) |
|||
const response = await ProjectService.createProject(data) |
|||
expect(response.title).toEqual(data.title) |
|||
}) |
|||
|
|||
test('can delete a project', async() => { |
|||
const projectId = 1 |
|||
mockAxios.onDelete(`/projects/${projectId}`).reply(204, {}) |
|||
const response = await ProjectService.deleteProject(projectId) |
|||
expect(response).toEqual({}) |
|||
}) |
|||
}) |
Write
Preview
Loading…
Cancel
Save