fix(web): break web-pkg/design-system/web-test-helpers dependency cycle
web-pkg, design-system and web-test-helpers formed a cycle: the mount
helpers have to install the design system (its components are registered
globally) and web-pkg's mocked pinia stores, so web-test-helpers was
imported by both packages that imported it back.
Resolved by layering the helpers onto the packages that already need
them, instead of adding another one:
design-system/testing mount/shallowMount, prop types, design system +
gettext + router-link stub plugins
web-pkg/src/testing the above, extended with casl abilities, mocked
pinia stores and component mocks
web-test-helpers re-export of web-pkg/src/testing
design-system sits at the bottom of the workspace graph, so it cannot
depend on a package that installs it - hence the generic half lives
there. web-pkg composes those plugins rather than duplicating them, so
every helper is still defined exactly once, and no package depends on
one above it.
The public API of `@ownclouders/web-test-helpers` is unchanged, so
external extensions are unaffected.
Also:
- pin `typescript` via `pnpm.overrides` - without it, a second peer-
resolved typescript version forks `vue`, which forks `vue3-gettext`
into two module instances, breaking `inject(GetTextSymbol)` for any
component mounted through these helpers.
- keep `@ownclouders/design-system/testing` external in web-pkg's lib
build. rollup matches `external` strings exactly, so the subpath was
inlined, shipping a second copy of the design system and of
@vue/test-utils into the published bundle - components and wrappers
were then not identity-equal to the consumer's own, and gettext
injection broke.
- name the web-test-helpers umd output `.cjs`. The package is ESM, so the
`.js` file that publishConfig.exports pointed `require` at could not be
required.
Verified: `pnpm install --frozen-lockfile` clean, zero cyclic-workspace
warnings; `pnpm test:unit` 380 files / 3129 tests pass; `pnpm check:types`
0 errors; `pnpm lint`/`check:format` 0 errors; `pnpm build` succeeds;
published artifacts checked by mounting through the built `dist/` bundles
the way an external extension resolves them via publishConfig.exports.
131 lines
5.6 KiB
TypeScript
131 lines
5.6 KiB
TypeScript
import { mock } from 'vitest-mock-extended'
|
|
import { Resource, SpaceResource } from '@ownclouders/web-client'
|
|
import { getIndicators } from '../../../src/helpers/statusIndicators'
|
|
import { User } from '@ownclouders/web-client/graph/generated'
|
|
import { AncestorMetaDataValue } from '../../../src/types'
|
|
import { ResourceIndicator } from '../../../src/helpers'
|
|
import { createTestingPinia } from '../../../src/testing'
|
|
import {
|
|
ResourceIndicatorExtension,
|
|
useExtensionRegistry
|
|
} from '../../../src/composables/piniaStores/extensionRegistry'
|
|
|
|
describe('status indicators', () => {
|
|
const user = mock<User>()
|
|
|
|
createTestingPinia()
|
|
|
|
describe('indicator extensions', () => {
|
|
it('should be requested from the extension registry', () => {
|
|
const space = mock<SpaceResource>({ driveType: 'project' })
|
|
const resource = mock<Resource>({ id: 'resource' })
|
|
|
|
const { requestExtensions } = useExtensionRegistry()
|
|
vi.mocked(requestExtensions<ResourceIndicatorExtension>).mockReturnValue([
|
|
{
|
|
id: 'test.files.resource-indicator.stub',
|
|
type: 'resourceIndicator',
|
|
extensionPointIds: ['global.files.resource-indicator'],
|
|
getResourceIndicators: (resource: Resource): ResourceIndicator[] => {
|
|
return [
|
|
{
|
|
id: 'some-id',
|
|
accessibleDescription: 'some accessible description',
|
|
label: 'some label',
|
|
icon: 'check_box_outline_blank',
|
|
fillType: 'line',
|
|
type: 'some-type',
|
|
category: 'system'
|
|
}
|
|
]
|
|
}
|
|
} satisfies ResourceIndicatorExtension
|
|
])
|
|
|
|
const indicators = getIndicators({ space, resource, ancestorMetaData: {}, user })
|
|
|
|
expect(requestExtensions).toHaveBeenCalled()
|
|
expect(indicators.some(({ id }) => id === 'some-id')).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
describe('locked indicator', () => {
|
|
it.each([true, false])('should only be present if the file is locked', (locked) => {
|
|
const space = mock<SpaceResource>({ id: 'space' })
|
|
const resource = mock<Resource>({ id: 'resource', locked })
|
|
const indicators = getIndicators({ space, resource, ancestorMetaData: {}, user })
|
|
|
|
expect(indicators.some(({ type }) => type === 'resource-locked')).toBe(locked)
|
|
})
|
|
})
|
|
|
|
describe('processing indicator', () => {
|
|
it.each([true, false])('should only be present if the file is processing', (processing) => {
|
|
const space = mock<SpaceResource>({ id: 'space' })
|
|
const resource = mock<Resource>({ id: 'resource', processing })
|
|
const indicators = getIndicators({ space, resource, ancestorMetaData: {}, user })
|
|
|
|
expect(indicators.some(({ type }) => type === 'resource-processing')).toBe(processing)
|
|
})
|
|
})
|
|
|
|
describe('sharing indicators', () => {
|
|
it('should not be present if the user is not a member of the project space', () => {
|
|
const space = mock<SpaceResource>({ driveType: 'project', isMember: () => false })
|
|
const resource = mock<Resource>({ id: 'resource', shareTypes: [0, 3] })
|
|
const indicators = getIndicators({ space, resource, ancestorMetaData: {}, user })
|
|
|
|
expect(indicators.some(({ category }) => category === 'sharing')).toBeFalsy()
|
|
})
|
|
it("should not be present in another user's personal space", () => {
|
|
const space = mock<SpaceResource>({ driveType: 'personal', isOwner: () => false })
|
|
const resource = mock<Resource>({ id: 'resource', shareTypes: [0, 3] })
|
|
const indicators = getIndicators({ space, resource, ancestorMetaData: {}, user })
|
|
|
|
expect(indicators.some(({ category }) => category === 'sharing')).toBeFalsy()
|
|
})
|
|
it('should not be present in a share space', () => {
|
|
const space = mock<SpaceResource>({ driveType: 'share' })
|
|
const resource = mock<Resource>({ id: 'resource', shareTypes: [0, 3] })
|
|
const indicators = getIndicators({ space, resource, ancestorMetaData: {}, user })
|
|
|
|
expect(indicators.some(({ category }) => category === 'sharing')).toBeFalsy()
|
|
})
|
|
it('should not be present in a public space', () => {
|
|
const space = mock<SpaceResource>({ driveType: 'public' })
|
|
const resource = mock<Resource>({ id: 'resource', shareTypes: [0, 3] })
|
|
const indicators = getIndicators({ space, resource, ancestorMetaData: {}, user })
|
|
|
|
expect(indicators.some(({ category }) => category === 'sharing')).toBeFalsy()
|
|
})
|
|
it('should be present for direct collaborator and link shares', () => {
|
|
const space = mock<SpaceResource>({ driveType: 'project', isMember: () => true })
|
|
const resource = mock<Resource>({ id: 'resource', shareTypes: [0, 3] })
|
|
const indicators = getIndicators({ space, resource, ancestorMetaData: {}, user })
|
|
|
|
expect(
|
|
indicators.some(({ type, category }) => category === 'sharing' && 'link-direct')
|
|
).toBeTruthy()
|
|
expect(
|
|
indicators.some(({ type, category }) => category === 'sharing' && 'user-direct')
|
|
).toBeTruthy()
|
|
})
|
|
it('should be present for indirect collaborator and link shares', () => {
|
|
const ancestorMetaData = {
|
|
'/': mock<AncestorMetaDataValue>({ shareTypes: [0, 3] })
|
|
}
|
|
|
|
const space = mock<SpaceResource>({ driveType: 'project', isMember: () => true })
|
|
const resource = mock<Resource>({ id: 'resource', shareTypes: [] })
|
|
const indicators = getIndicators({ space, resource, ancestorMetaData, user })
|
|
|
|
expect(
|
|
indicators.some(({ type, category }) => category === 'sharing' && type === 'link-indirect')
|
|
).toBeTruthy()
|
|
expect(
|
|
indicators.some(({ type, category }) => category === 'sharing' && type === 'user-indirect')
|
|
).toBeTruthy()
|
|
})
|
|
})
|
|
})
|