Skip to content

Commit

Permalink
set default translation language to en for files-app
Browse files Browse the repository at this point in the history
fix bug on initial event emit for expirationDatepicker after adding group or user
  • Loading branch information
fschade committed Dec 21, 2021
1 parent 926bc0b commit e1da726
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,6 @@ export default defineComponent({
},
set(val) {
date = val
const dateCurrent = DateTime.fromJSDate(val)
.setLocale(language.value.current)
.endOf('day')
emit('optionChange', {
expirationDate: dateCurrent.isValid
? dateCurrent.toFormat("yyyy-MM-dd'T'HH:mm:ssZZZ")
: null
})
trigger()
}
}
Expand All @@ -137,6 +127,15 @@ export default defineComponent({
.toRelative()
)
watch(dateCurrent, (val) => {
const dateCurrent = DateTime.fromJSDate(val).setLocale(language.value.current).endOf('day')
emit('optionChange', {
expirationDate: dateCurrent.isValid
? dateCurrent.toFormat("yyyy-MM-dd'T'HH:mm:ssZZZ")
: null
})
})
watch(dateMax, (val) => {
if (!val || dateCurrent.value < val) {
return
Expand Down
6 changes: 6 additions & 0 deletions packages/web-app-files/src/composables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ export * from './store'
export * from './useDefaults'
export * from './useFileListHeaderPosition'
export * from './usePagination'

declare module 'vue/types/vue' {
interface Vue {
[key: string]: any
}
}
2 changes: 1 addition & 1 deletion packages/web-app-files/src/gettext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { translate } from 'vue-gettext'
import translations from '../l10n/translations.json'

const config = {
language: 'de', // TODO BEFORE MERGE: Access current locale
language: 'en', // TODO BEFORE MERGE: Access current locale
getTextPluginSilent: false,
getTextPluginMuteLanguages: [],
silent: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Vuex from 'vuex'
import FileDetails from 'packages/web-app-files/src/components/SideBar/Details/FileDetails.vue'
import FileDetails from '../../../../../src/components/SideBar/Details/FileDetails.vue'
import stubs from '../../../../../../../tests/unit/stubs'
import GetTextPlugin from 'vue-gettext'
import AsyncComputed from 'vue-async-computed'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Vuex from 'vuex'
import FileDetailsMultiple from 'packages/web-app-files/src/components/SideBar/Details/FileDetailsMultiple.vue'
import FileDetailsMultiple from '../../../../../src/components/SideBar/Details/FileDetailsMultiple.vue'
import stubs from '../../../../../../../tests/unit/stubs'
import GetTextPlugin from 'vue-gettext'
import AsyncComputed from 'vue-async-computed'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createLocalVue, mount } from '@vue/test-utils'
import Vuex from 'vuex'
import ListItem from 'packages/web-app-files/src/components/SideBar/Shares/Collaborators/ListItem.vue'
import ListItem from '../../../../../../src/components/SideBar/Shares/Collaborators/ListItem.vue'
import stubs from '../../../../../../../../tests/unit/stubs'
import GetTextPlugin from 'vue-gettext'
import { peopleRoleViewerFolder, ShareTypes } from '../../../../../../src/helpers/share'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Vuex from 'vuex'
import AutocompleteItem from 'packages/web-app-files/src/components/SideBar/Shares/InviteCollaborator/AutocompleteItem.vue'
import AutocompleteItem from '../../../../../../src/components/SideBar/Shares/InviteCollaborator/AutocompleteItem.vue'
import stubs from '../../../../../../../../tests/unit/stubs'
import { ShareTypes } from '../../../../../../src/helpers/share'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,44 @@ describe('InviteCollaborator ExpirationDatepicker', () => {

it('emits an event if date changes', async () => {
const wrapper = createWrapper(asCapabilitiesGetter(enabledCapabilities))
const manualDate = DateTime.now().plus({ days: 5 })
const checker = jest.fn()
wrapper.vm.$on('optionChange', checker as any)
wrapper.setData({ dateCurrent: manualDate.toJSDate() })

expect(checker).toBeCalledTimes(0)

await wrapper.setProps({ shareTypes: [ShareTypes.user.value] })
await nextTick()
expect(checker).toBeCalledTimes(1)
expect(manualDate.toISODate()).toBe(
DateTime.fromISO(checker.mock.calls[0][0].expirationDate).toISODate()
expect(DateTime.fromISO(checker.mock.calls[0][0].expirationDate).toISODate()).toBe(
DateTime.now().plus({ days: enabledCapabilities.user.expire_date.days }).toISODate()
)

wrapper.vm.$store.hotUpdate(asCapabilitiesGetter(enforcedCapabilities))
await wrapper.setProps({ shareTypes: [ShareTypes.group.value, ShareTypes.user.value] })
await wrapper.setProps({ shareTypes: [ShareTypes.group.value] })
await nextTick()
expect(checker).toBeCalledTimes(2)
expect(
DateTime.now().plus({ days: enforcedCapabilities.user.expire_date.days }).toISODate()
).toBe(DateTime.fromISO(checker.mock.calls[1][0].expirationDate).toISODate())
expect(DateTime.fromISO(checker.mock.calls[1][0].expirationDate).toISODate()).toBe(
DateTime.now().plus({ days: enabledCapabilities.group.expire_date.days }).toISODate()
)

await wrapper.setProps({ shareTypes: [] })
await nextTick()
expect(checker).toBeCalledTimes(3)
expect(checker.mock.calls[2][0].expirationDate).toBe(null)

const manualDate = DateTime.now().plus({ days: 5 })
wrapper.setData({ dateCurrent: manualDate.toJSDate() })
await nextTick()
expect(checker).toBeCalledTimes(4)
expect(DateTime.fromISO(checker.mock.calls[3][0].expirationDate).toISODate()).toBe(
manualDate.toISODate()
)

wrapper.setData({ dateCurrent: null })
await wrapper.setProps({ shareTypes: [ShareTypes.user.value, ShareTypes.group.value] })
await nextTick()
expect(checker).toBeCalledTimes(5)
expect(DateTime.fromISO(checker.mock.calls[4][0].expirationDate).toISODate()).toBe(
DateTime.now().plus({ days: enabledCapabilities.user.expire_date.days }).toISODate()
)
})
})
2 changes: 1 addition & 1 deletion packages/web-app-files/tests/unit/views/Favorites.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils'
import { createFile, localVue, getStore } from './views.setup'
import Favorites from 'packages/web-app-files/src/views/Favorites.vue'
import Favorites from '../../../src/views/Favorites.vue'

import VueRouter from 'vue-router'
localVue.use(VueRouter)
Expand Down
3 changes: 1 addition & 2 deletions web.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
declare module 'vue/types/web' {
import { ILanguageComponent } from 'vue/types/vue'
interface Vue extends ILanguageComponent {
interface Vue {
[key: string]: any
}
}
Expand Down

0 comments on commit e1da726

Please sign in to comment.