Browse Source

Merge pull request #1542 from doccano/fix/1541

Display guideline
pull/1543/head
Hiroki Nakayama 3 years ago
committed by GitHub
parent
commit
a6fec7cd7e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 1124 additions and 1058 deletions
  1. 2
      frontend/components/tasks/toolbar/forms/FormGuideline.vue
  2. 6
      frontend/jest.config.js
  3. 4
      frontend/package.json
  4. 24
      frontend/pages/projects/_id/guideline/index.vue
  5. 40
      frontend/test/unit/components/containers/ProjectCreationButton.spec.js
  6. 40
      frontend/test/unit/components/containers/ProjectDeletionButton.spec.js
  7. 40
      frontend/test/unit/components/containers/ProjectList.spec.js
  8. 0
      frontend/test/unit/components/molecules/.gitkeep
  9. 58
      frontend/test/unit/components/organisms/ProjecCreationForm.spec.js
  10. 64
      frontend/test/unit/components/organisms/ProjectList.spec.js
  11. 23
      frontend/test/unit/components/tasks/toolbar/forms/formGuideline.spec.js
  12. 18
      frontend/test/unit/plugins/filters.spec.js
  13. 56
      frontend/test/unit/services/api.service.spec.js
  14. 12
      frontend/test/unit/services/csv.service.spec.js
  15. 46
      frontend/test/unit/services/project.service.spec.js
  16. 1749
      frontend/yarn.lock

2
frontend/components/tasks/toolbar/forms/FormGuideline.vue

@ -6,7 +6,7 @@
>
<template #content>
<viewer
:value="guidelineText"
:initialValue="guidelineText"
/>
</template>
</base-card>

6
frontend/jest.config.js

@ -2,12 +2,14 @@ module.exports = {
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
'^~/(.*)$': '<rootDir>/$1',
'^vue$': 'vue/dist/vue.common.js'
'^vue$': 'vue/dist/vue.common.js',
"^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
},
moduleFileExtensions: ['js', 'vue', 'json'],
transform: {
'^.+\\.js$': 'babel-jest',
'.*\\.(vue)$': 'vue-jest'
'.*\\.(vue)$': 'vue-jest',
'^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub'
},
collectCoverage: true,
collectCoverageFrom: [

4
frontend/package.json

@ -53,6 +53,7 @@
"devDependencies": {
"@babel/core": "^7.14.8",
"@babel/eslint-parser": "^7.14.7",
"@babel/preset-env": "^7.15.8",
"@nuxt/types": "^2.15.7",
"@nuxt/typescript-build": "^2.1.0",
"@nuxtjs/eslint-config": "^6.0.1",
@ -63,7 +64,7 @@
"@types/wavesurfer.js": "^5.1.0",
"@vue/test-utils": "^1.2.2",
"axios-mock-adapter": "^1.19.0",
"babel-core": "^6.26.3",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^27.0.6",
"core-js": "^3.15.*",
"eslint": "^7.31.0",
@ -76,6 +77,7 @@
"eslint-plugin-promise": "5.1.0",
"eslint-plugin-vue": "^7.14.0",
"jest": "^27.0.6",
"jest-transform-stub": "^2.0.0",
"nodemon": "^2.0.12",
"prettier": "^2.3.2",
"raw-loader": "^4.0.2",

24
frontend/pages/projects/_id/guideline/index.vue

@ -1,9 +1,11 @@
<template>
<editor
v-model="project.guideline"
:initialValue="project.guideline"
:options="editorOptions"
preview-style="vertical"
height="inherit"
:options="editorOptions"
ref="toastuiEditor"
@change="updateProject"
/>
</template>
@ -27,24 +29,24 @@ export default {
editorOptions: {
language: this.$t('toastui.localeCode')
},
project: {}
}
},
watch: {
'project.guideline'() {
this.updateProject()
project: {},
mounted: false,
}
},
async created() {
async mounted() {
const projectId = this.$route.params.id
this.project = await this.$services.project.findById(projectId)
this.$refs.toastuiEditor.invoke('setMarkdown', this.project.guideline)
this.mounted = true
},
methods: {
updateProject: _.debounce(function() {
this.$services.project.update(this.project)
if (this.mounted) {
this.project.guideline = this.$refs.toastuiEditor.invoke('getMarkdown')
this.$services.project.update(this.project)
}
}, 1000)
},

40
frontend/test/unit/components/containers/ProjectCreationButton.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()
})
})

40
frontend/test/unit/components/containers/ProjectDeletionButton.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 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()
})
})

40
frontend/test/unit/components/containers/ProjectList.spec.js

@ -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()
})
})

0
frontend/test/unit/components/molecules/.gitkeep

58
frontend/test/unit/components/organisms/ProjecCreationForm.spec.js

@ -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()
})
})

64
frontend/test/unit/components/organisms/ProjectList.spec.js

@ -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()
})
})

23
frontend/test/unit/components/tasks/toolbar/forms/formGuideline.spec.js

@ -0,0 +1,23 @@
/**
* @jest-environment jsdom
*/
import { mount } from '@vue/test-utils'
import FormGuideline from '@/components/tasks/toolbar/forms/FormGuideline'
const $t = () => {}
const factory = (values = {}) => {
return mount(FormGuideline, {
propsData: {
guidelineText: 'Hello'
},
mocks:{ $t }
})
}
describe('Foo', () => {
it('welcome メッセージを描画する', () => {
const wrapper = factory()
expect(wrapper.find('.tui-editor-contents').text()).toEqual('Hello')
})
})

18
frontend/test/unit/plugins/filters.spec.js

@ -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)
})
})

56
frontend/test/unit/services/api.service.spec.js

@ -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({})
})
})

12
frontend/test/unit/services/csv.service.spec.js

@ -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')
})
})

46
frontend/test/unit/services/project.service.spec.js

@ -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({})
})
})

1749
frontend/yarn.lock
File diff suppressed because it is too large
View File

Loading…
Cancel
Save