Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[full-ci] Use provide/inject for service injection #9222

Merged
merged 3 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function getWrapper() {
},
global: {
mocks,
provide: mocks,
plugins: [...defaultPlugins(), store]
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function getWrapper({ mountType = shallowMount, props = {} } = {}) {
global: {
plugins: [...defaultPlugins()],
mocks,
provide: mocks,
stubs: {
OcCheckbox: true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function getWrapper() {
},
global: {
mocks,
provide: mocks,
plugins: [...defaultPlugins(), store],
stubs: {
'oc-text-input': true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function getWrapper({ mountType = mount, spaces = [], selectedSpaces = [] } = {}
global: {
plugins: [...defaultPlugins()],
mocks,
provide: mocks,
stubs: {
OcCheckbox: true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function getWrapper() {
},
global: {
mocks,
provide: mocks,
plugins: [...defaultPlugins(), store]
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function getWrapper({
},
global: {
mocks,
provide: mocks,
plugins: [...defaultPlugins(), store]
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ function getWrapper({ mountType = shallowMount, props = {} } = {}) {
global: {
plugins: [...defaultPlugins()],
mocks,
provide: mocks,
stubs: {
OcCheckbox: true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ function getWrapper({
},
{
store,
mocks
mocks,
provide: mocks
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ function getWrapper({
},
{
store,
mocks
mocks,
provide: mocks
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function getWrapper({
const instance = useGroupActionsDelete({ store })
setup(instance, { storeOptions, clientService: mocks.$clientService })
},
{ store, mocks }
{ store, mocks, provide: mocks }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function getWrapper({
const instance = useUserActionsDelete({ store })
setup(instance, { storeOptions, clientService: mocks.$clientService })
},
{ store, mocks }
{ store, mocks, provide: mocks }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ function getWrapper({ clientService = getClientServiceMock() } = {}) {
global: {
plugins: [...defaultPlugins(), store],
mocks,
provide: mocks,
stubs: {
CreateGroupModal: true,
AppLoadingSpinner: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function getWrapper({ spaces = [{ name: 'Some Space' }] } = {}) {
global: {
plugins: [...defaultPlugins(), store],
mocks,
provide: mocks,
stubs: {
AppLoadingSpinner: true,
NoContentMessage: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ function getMountedWrapper({
global: {
plugins: [...defaultPlugins(), store],
mocks,
provide: mocks,
stubs: {
CreateUserModal: true,
AppLoadingSpinner: true,
Expand Down
13 changes: 8 additions & 5 deletions packages/web-app-external/tests/unit/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,19 @@ function createShallowMountWrapper(makeRequest = jest.fn().mockResolvedValue({ s
}))

const store = createStore(storeOptions)
const mocks = {
...defaultComponentMocks({
currentRoute: mock<RouteLocation>({ query: { app: 'exampleApp' } })
})
}

return {
wrapper: shallowMount(App, {
global: {
plugins: [...defaultPlugins(), store],
stubs: componentStubs,
mocks: {
...defaultComponentMocks({
currentRoute: mock<RouteLocation>({ query: { app: 'exampleApp' } })
})
}
mocks,
provide: mocks
}
})
}
Expand Down
1 change: 0 additions & 1 deletion packages/web-app-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"p-queue": "^6.6.2",
"qs": "^6.10.3",
"sanitize-html": "^2.7.0",
"semver": "^7.3.8",
"uuid": "^9.0.0",
"vue-concurrency": "4.0.1",
"vue3-gettext": "^2.3.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from 'web-pkg/src/composables'
import { FileAction, FileActionOptions } from 'web-pkg/src/composables/actions'
import { useGettext } from 'vue3-gettext'
import { useArchiverService } from 'web-app-files/src/composables/archiverService'
import { useArchiverService } from 'web-pkg/src/composables/archiverService'
import { formatFileSize } from 'web-pkg/src/helpers/filesize'

export const useFileActionsDownloadArchive = ({ store }: { store?: Store<any> } = {}) => {
Expand All @@ -31,7 +31,7 @@ export const useFileActionsDownloadArchive = ({ store }: { store?: Store<any> }
const isFilesAppActive = useIsFilesAppActive()

const handler = ({ space, resources }: FileActionOptions) => {
const fileOptions = archiverService.fileIdsSupported
const fileOptions = unref(archiverService.fileIdsSupported)
? {
fileIds: resources.map((resource) => resource.fileId)
}
Expand Down Expand Up @@ -62,7 +62,7 @@ export const useFileActionsDownloadArchive = ({ store }: { store?: Store<any> }
}

const areArchiverLimitsExceeded = (resources: Resource[]) => {
const archiverCapabilities = archiverService.capability
const archiverCapabilities = unref(archiverService.capability)
if (!archiverCapabilities) {
return
}
Expand All @@ -89,7 +89,7 @@ export const useFileActionsDownloadArchive = ({ store }: { store?: Store<any> }
? $gettextInterpolate(
$gettext('The selection exceeds the allowed archive size (max. %{maxSize})'),
{
maxSize: formatFileSize(archiverService.capability.max_size, current)
maxSize: formatFileSize(unref(archiverService.capability).max_size, current)
}
)
: ''
Expand Down Expand Up @@ -121,11 +121,11 @@ export const useFileActionsDownloadArchive = ({ store }: { store?: Store<any> }
if (isProjectSpaceResource(resources[0]) && resources[0].disabled) {
return false
}
if (!archiverService.available) {
if (!unref(archiverService.available)) {
return false
}
if (
!archiverService.fileIdsSupported &&
!unref(archiverService.fileIdsSupported) &&
isLocationCommonActive(router, 'files-common-favorites')
) {
return false
Expand Down
1 change: 0 additions & 1 deletion packages/web-app-files/src/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './actions'
export * from './archiverService'
export * from './resourcesViewDefaults'
export * from './router'
export * from './selection'
Expand Down
15 changes: 1 addition & 14 deletions packages/web-app-files/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import quickActions from './quickActions'
import store from './store'
import { SDKSearch } from './search'
import { eventBus } from 'web-pkg/src/services/eventBus'
import { Registry, ArchiverService } from './services'
import { Registry } from './services'
import fileSideBars from './fileSideBars'
import { buildRoutes } from './router'
import get from 'lodash-es/get'
import { AppNavigationItem, AppReadyHookArgs } from 'web-pkg/src/apps'

// dirty: importing view from other extension within project
Expand Down Expand Up @@ -131,17 +130,5 @@ export default {
// when discussing the boot process of applications we need to implement a
// registry that does not rely on call order, aka first register "on" and only after emit.
eventBus.publish('app.search.register.provider', Registry.sdkSearch)
globalProperties.$archiverService = new ArchiverService(
$clientService,
store.getters.configuration.server || window.location.origin,
get(store, 'getters.capabilities.files.archivers', [
{
enabled: true,
version: '1.0.0',
formats: ['tar', 'zip'],
archiver_url: `${store.getters.configuration.server}index.php/apps/files/ajax/download.php`
}
])
)
}
}
1 change: 0 additions & 1 deletion packages/web-app-files/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './archiver'
export { default as Registry } from './registry'
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
defaultStoreMockOptions,
RouteLocation
} from 'web-test-helpers'
import { ArchiverService } from 'web-app-files/src/services'
import { ArchiverService } from 'web-pkg/src/services'
import { ViewModeConstants } from 'web-pkg/src/composables'

const selectors = {
Expand Down Expand Up @@ -187,7 +187,7 @@ function getShallowWrapper(
slots,
global: {
plugins: [...defaultPlugins(), store],
provide: { isMobileWidth: ref(isMobileWidth) },
provide: { ...mocks, isMobileWidth: ref(isMobileWidth) },
mocks
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function getWrapper({
stubs: { OcButton: false },
renderStubDefaultSlot: true,
mocks,
provide: mocks,
plugins: [...defaultPlugins(), store]
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function getWrapper() {
wrapper: mount(CreateSpace, {
global: {
mocks,
provide: mocks,
plugins: [...defaultPlugins(), store]
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function getWrapper({ currentRouteName = locationSharesWithMe.name } = {}) {
stubs: defaultStubs,
renderStubDefaultSlot: true,
mocks,
provide: mocks,
plugins: [...defaultPlugins(), store]
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function getWrapper() {
},
global: {
mocks,
provide: { currentSpace: mock<SpaceResource>() },
provide: { ...mocks, currentSpace: mock<SpaceResource>() },
stubs: { ...defaultStubs, 'action-menu-item': true },
plugins: [...defaultPlugins(), store]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ describe('NotFoundMessage', () => {
})

function getWrapper(space, route) {
const mocks = defaultComponentMocks({ currentRoute: route })
return {
wrapper: shallowMount(NotFoundMessage, {
props: { space },
global: {
renderStubDefaultSlot: true,
mocks: defaultComponentMocks({ currentRoute: route }),
mocks,
provide: mocks,
plugins: [...defaultPlugins()]
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ function getMountedWrapper({ props = {}, isUserContextReady = true } = {}) {
mocks: {
$route: router.currentRoute,
$router: router
},
provide: {
$router: router
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function getWrapper({
wrapper: shallowMount(List, {
global: {
mocks,
provide: mocks,
stubs: {
FilesViewWrapper: false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ function getWrapper({
}
storeOptions.modules.runtime.modules.spaces.getters.spaces.mockImplementation(() => spaces)
const store = createStore(storeOptions)
const mocks = defaultComponentMocks({ currentRoute: route })
return {
wrapper: shallowMount(Preview, {
props: {
searchResult
},
global: {
provide: mocks,
renderStubDefaultSlot: true,
mocks: defaultComponentMocks({ currentRoute: route }),
mocks,
plugins: [...defaultPlugins(), store]
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,18 @@ function createWrapper({
isPublicLinkContext
)
const store = createStore(storeOptions)
const mocks = { ...defaultComponentMocks() }
return {
wrapper: shallowMount(FileDetails, {
global: {
stubs: { 'router-link': true, 'oc-resource-icon': true },
provide: {
...mocks,
resource,
space: mockDeep<SpaceResource>()
},
plugins: [...defaultPlugins(), store],
mocks: { ...defaultComponentMocks() }
mocks
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ function getWrapper({
files_sharing: { federation: { incoming: true, outgoing: true } }
}))
const store = createStore(storeOptions)
const mocks = defaultComponentMocks({
currentRoute: mock<RouteLocation>({ params: { storageId } })
})
return {
wrapper: shallowMount(InviteCollaboratorForm, {
data() {
Expand All @@ -93,10 +96,8 @@ function getWrapper({
},
global: {
plugins: [...defaultPlugins(), store],
provide: { resource },
mocks: defaultComponentMocks({
currentRoute: mock<RouteLocation>({ params: { storageId } })
})
provide: { ...mocks, resource },
mocks
}
})
}
Expand Down
Loading