Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly inject the loadingService
Browse files Browse the repository at this point in the history
JammingBen committed Mar 15, 2023

Unverified

This user has not yet uploaded their public signing key.
1 parent 5138e30 commit 247d115
Showing 23 changed files with 81 additions and 54 deletions.
3 changes: 2 additions & 1 deletion packages/web-app-admin-settings/src/views/Users.vue
Original file line number Diff line number Diff line change
@@ -170,6 +170,7 @@ import {
useAccessToken,
useCapabilitySpacesMaxQuota,
useGraphClient,
useLoadingService,
useRouteQuery,
useStore
} from 'web-pkg/src/composables'
@@ -200,7 +201,6 @@ import GroupsModal from '../components/Users/GroupsModal.vue'
import { useRemoveFromGroups } from '../mixins/users/removeFromGroups'
import { useAddToGroups } from '../mixins/users/addToGroups'
import { configurationManager } from 'web-pkg'
import { loadingService } from 'web-pkg/src/services'
export default defineComponent({
name: 'UsersView',
@@ -221,6 +221,7 @@ export default defineComponent({
const store = useStore()
const accessToken = useAccessToken({ store })
const { graphClient } = useGraphClient()
const loadingService = useLoadingService()
const { actions: removeFromGroupsActions } = useRemoveFromGroups()
const { actions: addToGroupsActions } = useAddToGroups()
Original file line number Diff line number Diff line change
@@ -341,6 +341,7 @@ export default defineComponent({
this.pasteSelectedFiles({
targetSpace: this.space,
clientService: this.$clientService,
loadingService: this.$loadingService,
createModal: this.createModal,
hideModal: this.hideModal,
showMessage: this.showMessage,
Original file line number Diff line number Diff line change
@@ -5,19 +5,10 @@
<script lang="ts">
import keycode from 'keycode'
import { eventBus } from 'web-pkg/src/services/eventBus'
import {
defineComponent,
getCurrentInstance,
onBeforeUnmount,
onMounted,
PropType,
computed,
ref,
unref
} from 'vue'
import { defineComponent, onBeforeUnmount, onMounted, PropType, computed, ref, unref } from 'vue'
import { Resource, SpaceResource } from 'web-client/src/helpers'
import { useScrollTo } from 'web-app-files/src/composables/scrollTo'
import { useClientService, useStore } from 'web-pkg'
import { useClientService, useLoadingService, useStore } from 'web-pkg'
import { useGettext } from 'vue3-gettext'
export default defineComponent({
@@ -37,11 +28,11 @@ export default defineComponent({
}
},
setup(props) {
const instance = getCurrentInstance().proxy as any
const store = useStore()
const language = useGettext()
const clientService = useClientService()
const { scrollToResource } = useScrollTo()
const loadingService = useLoadingService()
const selectionCursor = ref(0)
let fileListClickedEvent
@@ -106,6 +97,7 @@ export default defineComponent({
store.dispatch('Files/pasteSelectedFiles', {
targetSpace: props.space,
clientService: clientService,
loadingService: loadingService,
createModal: (modal) => {
store.dispatch('createModal', modal)
},
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Resource } from 'web-client'
import { join } from 'path'
import { SpaceResource } from 'web-client/src/helpers'
import { ClientService, loadingService, LoadingTaskState } from 'web-pkg/src/services'
import { ClientService, LoadingService, LoadingTaskState } from 'web-pkg/src/services'
import {
ConflictDialog,
ResolveStrategy,
@@ -18,6 +18,7 @@ export class ResourceTransfer extends ConflictDialog {
private targetSpace: SpaceResource,
private targetFolder: Resource,
private clientService: ClientService,
private loadingService: LoadingService,
createModal: (modal: object) => void,
hideModal: () => void,
showMessage: (data: object) => void,
@@ -117,7 +118,7 @@ export class ResourceTransfer extends ConflictDialog {
targetFolderResources
)

return loadingService.addTask(
return this.loadingService.addTask(
({ setProgress }) => {
return this.moveResources(
resolvedConflicts,
3 changes: 1 addition & 2 deletions packages/web-app-files/src/mixins/actions/downloadArchive.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ import first from 'lodash-es/first'
import { archiverService } from '../../services'
import { isPublicSpaceResource, Resource } from 'web-client/src/helpers'
import { mapGetters } from 'vuex'
import { loadingService } from 'web-pkg/src/services'

export default {
mixins: [isFilesAppActive],
@@ -79,7 +78,7 @@ export default {
dir: path.dirname(first<Resource>(resources).path) || '/',
files: resources.map((resource) => resource.name)
}
return loadingService.addTask(() => {
return this.$loadingService.addTask(() => {
return archiverService
.triggerDownload({
...fileOptions,
3 changes: 1 addition & 2 deletions packages/web-app-files/src/mixins/actions/emptyTrashBin.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import { isLocationTrashActive } from '../../router'
import { buildWebDavFilesTrashPath } from '../../helpers/resources'
import { buildWebDavSpacesTrashPath } from 'web-client/src/helpers'
import { isProjectSpaceResource } from 'web-client/src/helpers'
import { loadingService } from 'web-pkg'

export default {
computed: {
@@ -71,7 +70,7 @@ export default {
? buildWebDavSpacesTrashPath(this.space.id)
: buildWebDavFilesTrashPath(this.user.id)

return loadingService.addTask(() => {
return this.$loadingService.addTask(() => {
return this.$client.fileTrash
.clearTrashBin(path)
.then(() => {
1 change: 1 addition & 0 deletions packages/web-app-files/src/mixins/actions/paste.ts
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ export default {
this.pasteSelectedFiles({
targetSpace: this.space,
clientService: this.$clientService,
loadingService: this.$loadingService,
createModal: this.createModal,
hideModal: this.hideModal,
showMessage: this.showMessage,
4 changes: 2 additions & 2 deletions packages/web-app-files/src/mixins/actions/restore.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { mapActions, mapGetters, mapMutations, mapState } from 'vuex'
import { dirname } from 'path'
import { isLocationTrashActive } from '../../router'

import { clientService, loadingService, LoadingTaskState } from 'web-pkg/src/services'
import { clientService, LoadingTaskState } from 'web-pkg/src/services'
import { Resource, isProjectSpaceResource, extractExtensionFromFile } from 'web-client/src/helpers'
import {
ResolveStrategy,
@@ -281,7 +281,7 @@ export default {
resource.path = urlJoin(parentPath, resolvedName)
resolvedResources.push(resource)
}
return loadingService.addTask(
return this.$loadingService.addTask(
({ setProgress }) => {
return this.$_restore_restoreResources(resolvedResources, missingFolderPaths, setProgress)
},
4 changes: 2 additions & 2 deletions packages/web-app-files/src/mixins/deleteResources.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { buildWebDavFilesTrashPath } from '../helpers/resources'
import { buildWebDavSpacesTrashPath } from 'web-client/src/helpers'
import PQueue from 'p-queue'
import { isLocationTrashActive, isLocationSpacesActive } from '../router'
import { clientService, loadingService } from 'web-pkg/src/services'
import { clientService } from 'web-pkg/src/services'
import { dirname } from 'path'
import { createFileRouteOptions } from 'web-pkg/src/helpers/router'

@@ -153,7 +153,7 @@ export default {
},

$_deleteResources_filesList_delete() {
return loadingService.addTask(
return this.$loadingService.addTask(
({ setProgress }) => {
return this.deleteFiles({
...this.$language,
4 changes: 3 additions & 1 deletion packages/web-app-files/src/store/actions.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ import {
SpaceResource
} from 'web-client/src/helpers'
import { WebDAV } from 'web-client/src/webdav'
import { ClientService, loadingService, LoadingTaskState } from 'web-pkg/src/services'
import { ClientService, LoadingTaskState } from 'web-pkg/src/services'
import { Language } from 'vue3-gettext'
import { DavProperty } from 'web-client/src/webdav/constants'
import { AncestorMetaData } from 'web-app-files/src/helpers/resource/ancestorMetaData'
@@ -78,6 +78,7 @@ export default {
{
targetSpace,
clientService,
loadingService,
createModal,
hideModal,
showMessage,
@@ -92,6 +93,7 @@ export default {
targetSpace,
context.state.currentFolder,
clientService,
loadingService,
createModal,
hideModal,
showMessage,
1 change: 1 addition & 0 deletions packages/web-app-files/src/views/spaces/GenericSpace.vue
Original file line number Diff line number Diff line change
@@ -443,6 +443,7 @@ export default defineComponent({
this.space,
targetFolder,
this.$clientService,
this.$loadingService,
this.createModal,
this.hideModal,
this.showMessage,
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { ClientService } from 'web-pkg/src/services'
import { ClientService, LoadingService } from 'web-pkg/src/services'
import {
ResolveConflict,
ResourceTransfer,
TransferType,
resolveFileNameDuplicate
} from '../../../../src/helpers/resource'
import { mockDeep, mockReset } from 'jest-mock-extended'
import { mock, mockDeep, mockReset } from 'jest-mock-extended'
import { buildSpace, Resource } from 'web-client/src/helpers'
import { ListFilesResult } from 'web-client/src/webdav/listFiles'

const clientServiceMock = mockDeep<ClientService>()
const loadingServiceMock = mock<LoadingService>({
addTask: (callback) => {
return callback({ setProgress: jest.fn() })
}
})
let resourcesToMove
let sourceSpace
let targetSpace
@@ -60,6 +65,7 @@ describe('resourcesTransfer', () => {
targetSpace,
resourcesToMove[0],
clientServiceMock,
loadingServiceMock,
jest.fn(),
jest.fn(),
jest.fn(),
@@ -88,6 +94,7 @@ describe('resourcesTransfer', () => {
targetSpace,
targetFolder,
clientServiceMock,
loadingServiceMock,
jest.fn(),
jest.fn(),
jest.fn(),
@@ -127,6 +134,7 @@ describe('resourcesTransfer', () => {
targetSpace,
resourcesToMove[0],
clientServiceMock,
loadingServiceMock,
jest.fn(),
jest.fn(),
jest.fn(),
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import EmptyTrashBin from 'web-app-files/src/mixins/actions/emptyTrashBin'
import { createLocationTrash, createLocationSpaces } from '../../../../src/router'
import { mockDeep } from 'jest-mock-extended'
import { mock, mockDeep } from 'jest-mock-extended'
import { OwnCloudSdk } from 'web-client/src/types'
import { createStore, defaultPlugins, mount, defaultStoreMockOptions } from 'web-test-helpers'
import { LoadingService } from 'web-pkg'

const Component = {
template: '<div></div>',
mixins: [EmptyTrashBin]
}

describe('emptyTrashBin', () => {
afterEach(() => jest.clearAllMocks())

describe('isEnabled property', () => {
it('should be false when resource is given', () => {
const { wrapper } = getWrapper()
@@ -86,6 +85,11 @@ function getWrapper({
$gettext: jest.fn(),
$pgettext: jest.fn(),
space: { driveType, isEditor: () => false, isManager: () => false },
$loadingService: mock<LoadingService>({
addTask: (callback) => {
return callback({ setProgress: jest.fn() })
}
}),
$client: {
...clientMock,
fileTrash: {
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ describe('restore', () => {
const { wrapper } = getWrapper({ resolveClearTrashBin: false })
const showMessageStub = jest.spyOn(wrapper.vm, 'showMessage')
const removeFilesFromTrashbinStub = jest.spyOn(wrapper.vm, 'removeFilesFromTrashbin')
await wrapper.vm.$_restore_restoreResources([{ id: '1', path: '/1' }], [])
await wrapper.vm.$_restore_restoreResources([{ id: '1', path: '/1' }], [], jest.fn())

expect(showMessageStub).toHaveBeenCalledTimes(1)
expect(removeFilesFromTrashbinStub).toHaveBeenCalledTimes(0)
5 changes: 3 additions & 2 deletions packages/web-pkg/src/components/LoadingIndicator.vue
Original file line number Diff line number Diff line change
@@ -11,12 +11,13 @@

<script lang="ts">
import { defineComponent, onBeforeUnmount, onMounted, ref } from 'vue'
import { eventBus } from 'web-pkg'
import { loadingService, LoadingEventTopics } from 'web-pkg/src/services'
import { eventBus, useLoadingService } from 'web-pkg'
import { LoadingEventTopics } from 'web-pkg/src/services'
export default defineComponent({
name: 'LoadingIndicator',
setup() {
const loadingService = useLoadingService()
let addLoadingEventToken
let removeLoadingEventToken
let setProgressToken
1 change: 1 addition & 0 deletions packages/web-pkg/src/composables/index.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ export * from './capability'
export * from './clientService'
export * from './driveResolver'
export * from './graphClient'
export * from './loadingService'
export * from './localStorage'
export * from './router'
export * from './store'
1 change: 1 addition & 0 deletions packages/web-pkg/src/composables/loadingService/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useLoadingService'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LoadingService } from '../../services'
import { useService } from '../service'

export const useLoadingService = (): LoadingService => {
return useService('$loadingService')
}
2 changes: 0 additions & 2 deletions packages/web-pkg/src/services/loadingService.ts
Original file line number Diff line number Diff line change
@@ -96,5 +96,3 @@ export class LoadingService {
eventBus.publish(LoadingEventTopics.setProgress)
}
}

export const loadingService = new LoadingService()
26 changes: 11 additions & 15 deletions packages/web-pkg/tests/unit/components/LoadingIndicator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import LoadingIndicator from 'web-pkg/src/components/LoadingIndicator.vue'
import { defaultPlugins, shallowMount } from 'web-test-helpers'
import { mock } from 'jest-mock-extended'
import { LoadingService } from 'web-pkg'

const selectors = {
loadingIndicator: '#oc-loading-indicator',
@@ -11,34 +13,28 @@ describe('LoadingIndicator', () => {
const { wrapper } = getWrapper()
expect(wrapper.find(selectors.loadingIndicator).exists()).toBeFalsy()
})
it('should render when loading', async () => {
const { wrapper } = getWrapper()
wrapper.vm.isLoading = true
await wrapper.vm.$nextTick()
it('should render when loading', () => {
const { wrapper } = getWrapper({ isLoading: true })
expect(wrapper.find(selectors.loadingIndicator).exists()).toBeTruthy()
})
describe('indeterminate', () => {
it('progress bar should be in indeterminate when no progress given', async () => {
const { wrapper } = getWrapper()
wrapper.vm.isLoading = true
await wrapper.vm.$nextTick()
it('progress bar should be in indeterminate when no progress given', () => {
const { wrapper } = getWrapper({ isLoading: true })
expect(wrapper.findComponent<any>(selectors.progressStub).props('indeterminate')).toBeTruthy()
})
it('progress bar should not be in indeterminate when progress given', async () => {
const { wrapper } = getWrapper()
wrapper.vm.isLoading = true
wrapper.vm.currentProgress = 50
await wrapper.vm.$nextTick()
it('progress bar should not be in indeterminate when progress given', () => {
const { wrapper } = getWrapper({ isLoading: true, currentProgress: 50 })
expect(wrapper.findComponent<any>(selectors.progressStub).props('indeterminate')).toBeFalsy()
})
})
})

function getWrapper() {
function getWrapper({ isLoading = false, currentProgress = null } = {}) {
return {
wrapper: shallowMount(LoadingIndicator, {
global: {
plugins: [...defaultPlugins()]
plugins: [...defaultPlugins()],
mocks: { $loadingService: mock<LoadingService>({ isLoading, currentProgress }) }
}
})
}
Loading

0 comments on commit 247d115

Please sign in to comment.