mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge pull request #836 from Human-Connection/835-use-vuex-to-make-editor-placeholder-reactive
Set up editor placeholder to use Vuex
This commit is contained in:
commit
0c3e53a239
@ -1,9 +1,11 @@
|
|||||||
import { config, mount, createLocalVue } from '@vue/test-utils'
|
import { config, mount, createLocalVue } from '@vue/test-utils'
|
||||||
import ContributionForm from './index.vue'
|
import ContributionForm from './index.vue'
|
||||||
import Styleguide from '@human-connection/styleguide'
|
import Styleguide from '@human-connection/styleguide'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
const localVue = createLocalVue()
|
const localVue = createLocalVue()
|
||||||
|
|
||||||
|
localVue.use(Vuex)
|
||||||
localVue.use(Styleguide)
|
localVue.use(Styleguide)
|
||||||
|
|
||||||
config.stubs['no-ssr'] = '<span><slot /></span>'
|
config.stubs['no-ssr'] = '<span><slot /></span>'
|
||||||
@ -53,8 +55,16 @@ describe('ContributionForm.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('mount', () => {
|
describe('mount', () => {
|
||||||
|
const getters = {
|
||||||
|
'editor/placeholder': () => {
|
||||||
|
return 'some cool placeholder'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const store = new Vuex.Store({
|
||||||
|
getters,
|
||||||
|
})
|
||||||
const Wrapper = () => {
|
const Wrapper = () => {
|
||||||
return mount(ContributionForm, { mocks, localVue, computed })
|
return mount(ContributionForm, { mocks, localVue, computed, store })
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
@ -12,9 +12,7 @@
|
|||||||
@{{ user.slug }}
|
@{{ user.slug }}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div v-else class="suggestion-list__item is-empty">
|
<div v-else class="suggestion-list__item is-empty">No users found</div>
|
||||||
No users found
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<editor-menu-bubble :editor="editor">
|
<editor-menu-bubble :editor="editor">
|
||||||
@ -175,6 +173,7 @@ import {
|
|||||||
History,
|
History,
|
||||||
} from 'tiptap-extensions'
|
} from 'tiptap-extensions'
|
||||||
import Mention from './nodes/Mention.js'
|
import Mention from './nodes/Mention.js'
|
||||||
|
import { mapGetters } from 'vuex'
|
||||||
|
|
||||||
let throttleInputEvent
|
let throttleInputEvent
|
||||||
|
|
||||||
@ -212,7 +211,7 @@ export default {
|
|||||||
new ListItem(),
|
new ListItem(),
|
||||||
new Placeholder({
|
new Placeholder({
|
||||||
emptyNodeClass: 'is-empty',
|
emptyNodeClass: 'is-empty',
|
||||||
emptyNodeText: this.$t('editor.placeholder'),
|
emptyNodeText: this.placeholder || this.$t('editor.placeholder'),
|
||||||
}),
|
}),
|
||||||
new History(),
|
new History(),
|
||||||
new Mention({
|
new Mention({
|
||||||
@ -297,6 +296,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
...mapGetters({ placeholder: 'editor/placeholder' }),
|
||||||
hasResults() {
|
hasResults() {
|
||||||
return this.filteredUsers.length
|
return this.filteredUsers.length
|
||||||
},
|
},
|
||||||
@ -316,20 +316,20 @@ export default {
|
|||||||
this.editor.setContent(content)
|
this.editor.setContent(content)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
placeholder: {
|
||||||
mounted() {
|
immediate: true,
|
||||||
this.$root.$on('changeLanguage', () => {
|
handler: function(val) {
|
||||||
this.changePlaceHolderText()
|
if (!val) {
|
||||||
})
|
return
|
||||||
|
}
|
||||||
|
this.editor.extensions.options.placeholder.emptyNodeText = val
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.$root.$off('changeLanguage')
|
|
||||||
this.editor.destroy()
|
this.editor.destroy()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
changePlaceHolderText() {
|
|
||||||
this.editor.extensions.options.placeholder.emptyNodeText = this.$t('editor.placeholder')
|
|
||||||
},
|
|
||||||
// navigate to the previous item
|
// navigate to the previous item
|
||||||
// if it's the first item, navigate to the last one
|
// if it's the first item, navigate to the last one
|
||||||
upHandler() {
|
upHandler() {
|
||||||
|
|||||||
@ -1,31 +1,43 @@
|
|||||||
import { mount, createLocalVue } from '@vue/test-utils'
|
import { mount, createLocalVue } from '@vue/test-utils'
|
||||||
import Editor from './'
|
import Editor from './'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
import Styleguide from '@human-connection/styleguide'
|
import Styleguide from '@human-connection/styleguide'
|
||||||
|
|
||||||
const localVue = createLocalVue()
|
const localVue = createLocalVue()
|
||||||
|
localVue.use(Vuex)
|
||||||
localVue.use(Styleguide)
|
localVue.use(Styleguide)
|
||||||
|
|
||||||
describe('Editor.vue', () => {
|
describe('Editor.vue', () => {
|
||||||
let wrapper
|
let wrapper
|
||||||
let propsData
|
let propsData
|
||||||
let mocks
|
let mocks
|
||||||
|
let getters
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
propsData = {}
|
propsData = {}
|
||||||
mocks = {
|
mocks = {
|
||||||
$t: () => {},
|
$t: () => {},
|
||||||
}
|
}
|
||||||
|
getters = {
|
||||||
|
'editor/placeholder': () => {
|
||||||
|
return 'some cool placeholder'
|
||||||
|
},
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mount', () => {
|
describe('mount', () => {
|
||||||
let Wrapper = () => {
|
let Wrapper = () => {
|
||||||
|
const store = new Vuex.Store({
|
||||||
|
getters,
|
||||||
|
})
|
||||||
return (wrapper = mount(Editor, {
|
return (wrapper = mount(Editor, {
|
||||||
mocks,
|
mocks,
|
||||||
propsData,
|
propsData,
|
||||||
localVue,
|
localVue,
|
||||||
sync: false,
|
sync: false,
|
||||||
stubs: { transition: false },
|
stubs: { transition: false },
|
||||||
|
store,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,5 +55,13 @@ describe('Editor.vue', () => {
|
|||||||
expect(wrapper.find('.ProseMirror').text()).toContain('I am a piece of text')
|
expect(wrapper.find('.ProseMirror').text()).toContain('I am a piece of text')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('uses the placeholder', () => {
|
||||||
|
it('from the store', () => {
|
||||||
|
expect(wrapper.vm.editor.extensions.options.placeholder.emptyNodeText).toEqual(
|
||||||
|
'some cool placeholder',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
68
webapp/components/LocaleSwitch/LocaleSwitch.spec.js
Normal file
68
webapp/components/LocaleSwitch/LocaleSwitch.spec.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { mount, createLocalVue } from '@vue/test-utils'
|
||||||
|
import Styleguide from '@human-connection/styleguide'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
import VTooltip from 'v-tooltip'
|
||||||
|
import LocaleSwitch from './LocaleSwitch.vue'
|
||||||
|
import { mutations } from '~/store/editor'
|
||||||
|
|
||||||
|
const localVue = createLocalVue()
|
||||||
|
|
||||||
|
localVue.use(Vuex)
|
||||||
|
localVue.use(Styleguide)
|
||||||
|
localVue.use(VTooltip)
|
||||||
|
|
||||||
|
describe('LocaleSwitch.vue', () => {
|
||||||
|
let wrapper
|
||||||
|
let mocks
|
||||||
|
let computed
|
||||||
|
let deutschLanguageItem
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mocks = {
|
||||||
|
$i18n: {
|
||||||
|
locale: () => 'de',
|
||||||
|
set: jest.fn(),
|
||||||
|
},
|
||||||
|
$t: jest.fn(),
|
||||||
|
setPlaceholderText: jest.fn(),
|
||||||
|
}
|
||||||
|
computed = {
|
||||||
|
current: () => {
|
||||||
|
return { code: 'en' }
|
||||||
|
},
|
||||||
|
routes: () => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
name: 'English',
|
||||||
|
path: 'en',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Deutsch',
|
||||||
|
path: 'de',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mount', () => {
|
||||||
|
const store = new Vuex.Store({
|
||||||
|
mutations: {
|
||||||
|
'editor/SET_PLACEHOLDER_TEXT': mutations.SET_PLACEHOLDER_TEXT,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const Wrapper = () => {
|
||||||
|
return mount(LocaleSwitch, { mocks, localVue, store, computed })
|
||||||
|
}
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = Wrapper()
|
||||||
|
wrapper.find('.locale-menu').trigger('click')
|
||||||
|
deutschLanguageItem = wrapper.findAll('li').at(1)
|
||||||
|
deutschLanguageItem.trigger('click')
|
||||||
|
})
|
||||||
|
|
||||||
|
it("changes a user's locale", () => {
|
||||||
|
expect(mocks.$i18n.set).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -36,6 +36,7 @@
|
|||||||
import Dropdown from '~/components/Dropdown'
|
import Dropdown from '~/components/Dropdown'
|
||||||
import find from 'lodash/find'
|
import find from 'lodash/find'
|
||||||
import orderBy from 'lodash/orderBy'
|
import orderBy from 'lodash/orderBy'
|
||||||
|
import { mapMutations } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -65,10 +66,11 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
...mapMutations({ setPlaceholderText: 'editor/SET_PLACEHOLDER_TEXT' }),
|
||||||
changeLanguage(locale, toggleMenu) {
|
changeLanguage(locale, toggleMenu) {
|
||||||
this.$i18n.set(locale)
|
this.$i18n.set(locale)
|
||||||
toggleMenu()
|
toggleMenu()
|
||||||
this.$root.$emit('changeLanguage')
|
this.setPlaceholderText(this.$t('editor.placeholder'))
|
||||||
},
|
},
|
||||||
matcher(locale) {
|
matcher(locale) {
|
||||||
return locale === this.$i18n.locale()
|
return locale === this.$i18n.locale()
|
||||||
@ -1,9 +1,10 @@
|
|||||||
import { mount, createLocalVue, createWrapper } from '@vue/test-utils'
|
import { mount, createLocalVue, createWrapper } from '@vue/test-utils'
|
||||||
import CommentForm from './index.vue'
|
import CommentForm from './index.vue'
|
||||||
import Styleguide from '@human-connection/styleguide'
|
import Styleguide from '@human-connection/styleguide'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
const localVue = createLocalVue()
|
const localVue = createLocalVue()
|
||||||
|
localVue.use(Vuex)
|
||||||
localVue.use(Styleguide)
|
localVue.use(Styleguide)
|
||||||
|
|
||||||
describe('CommentForm.vue', () => {
|
describe('CommentForm.vue', () => {
|
||||||
@ -35,8 +36,16 @@ describe('CommentForm.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('mount', () => {
|
describe('mount', () => {
|
||||||
|
const getters = {
|
||||||
|
'editor/placeholder': () => {
|
||||||
|
return 'some cool placeholder'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const store = new Vuex.Store({
|
||||||
|
getters,
|
||||||
|
})
|
||||||
const Wrapper = () => {
|
const Wrapper = () => {
|
||||||
return mount(CommentForm, { mocks, localVue, propsData })
|
return mount(CommentForm, { mocks, localVue, propsData, store })
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
@ -92,7 +92,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapGetters, mapActions } from 'vuex'
|
import { mapGetters, mapActions } from 'vuex'
|
||||||
import LocaleSwitch from '~/components/LocaleSwitch'
|
import LocaleSwitch from '~/components/LocaleSwitch/LocaleSwitch'
|
||||||
import SearchInput from '~/components/SearchInput.vue'
|
import SearchInput from '~/components/SearchInput.vue'
|
||||||
import Modal from '~/components/Modal'
|
import Modal from '~/components/Modal'
|
||||||
import NotificationMenu from '~/components/notifications/NotificationMenu'
|
import NotificationMenu from '~/components/notifications/NotificationMenu'
|
||||||
|
|||||||
@ -73,7 +73,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import LocaleSwitch from '~/components/LocaleSwitch'
|
import LocaleSwitch from '~/components/LocaleSwitch/LocaleSwitch'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
17
webapp/store/editor.js
Normal file
17
webapp/store/editor.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export const state = () => {
|
||||||
|
return {
|
||||||
|
placeholder: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getters = {
|
||||||
|
placeholder(state) {
|
||||||
|
return state.placeholder
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export const mutations = {
|
||||||
|
SET_PLACEHOLDER_TEXT(state, text) {
|
||||||
|
state.placeholder = text
|
||||||
|
},
|
||||||
|
}
|
||||||
20
webapp/store/editor.spec.js
Normal file
20
webapp/store/editor.spec.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { getters, mutations } from './editor.js'
|
||||||
|
|
||||||
|
let state
|
||||||
|
|
||||||
|
describe('getters', () => {
|
||||||
|
describe('placeholder', () => {
|
||||||
|
it('return the value in state', () => {
|
||||||
|
state = { placeholder: null }
|
||||||
|
expect(getters.placeholder(state)).toBe(null)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mutations', () => {
|
||||||
|
it('SET_PLACEHOLDER_TEXT', () => {
|
||||||
|
state = { placeholder: null }
|
||||||
|
mutations.SET_PLACEHOLDER_TEXT(state, 'new placeholder')
|
||||||
|
expect(getters.placeholder(state)).toBe('new placeholder')
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user