@backstage/plugin-catalog-react 1.14.0-next.1 → 1.14.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @backstage/plugin-catalog-react
2
2
 
3
+ ## 1.14.0-next.2
4
+
5
+ ### Minor Changes
6
+
7
+ - 0801db6: Add catalog service mocks under the `/testUtils` subpath export.
8
+
9
+ You can now use e.g. `const catalog = catalogApiMock.mock()` in your test and then do assertions on `catalog.getEntities` without awkward type casting.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+ - @backstage/frontend-test-utils@0.2.1-next.2
15
+ - @backstage/catalog-client@1.7.1-next.0
16
+ - @backstage/catalog-model@1.7.0
17
+ - @backstage/core-compat-api@0.3.1-next.2
18
+ - @backstage/core-components@0.15.1-next.2
19
+ - @backstage/core-plugin-api@1.10.0-next.1
20
+ - @backstage/errors@1.2.4
21
+ - @backstage/frontend-plugin-api@0.9.0-next.2
22
+ - @backstage/integration-react@1.2.0-next.2
23
+ - @backstage/types@1.1.1
24
+ - @backstage/version-bridge@1.0.10-next.0
25
+ - @backstage/plugin-catalog-common@1.1.0
26
+ - @backstage/plugin-permission-common@0.8.1
27
+ - @backstage/plugin-permission-react@0.4.27-next.1
28
+
3
29
  ## 1.14.0-next.1
4
30
 
5
31
  ### Minor Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-react__alpha",
3
- "version": "1.14.0-next.1",
3
+ "version": "1.14.0-next.2",
4
4
  "main": "../dist/alpha.esm.js",
5
5
  "module": "../dist/alpha.esm.js",
6
6
  "types": "../dist/alpha.d.ts"
@@ -1,5 +1,5 @@
1
1
  import React, { useState, useCallback, useMemo } from 'react';
2
- import { EntityListContext } from '../hooks/useEntityListProvider.esm.js';
2
+ import { EntityListContext } from './hooks/useEntityListProvider.esm.js';
3
3
 
4
4
  function MockEntityListContextProvider(props) {
5
5
  const { children, value } = props;
@@ -44,4 +44,4 @@ function MockEntityListContextProvider(props) {
44
44
  }
45
45
 
46
46
  export { MockEntityListContextProvider };
47
- //# sourceMappingURL=providers.esm.js.map
47
+ //# sourceMappingURL=deprecated.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deprecated.esm.js","sources":["../src/deprecated.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, {\n PropsWithChildren,\n useCallback,\n useMemo,\n useState,\n} from 'react';\nimport {\n DefaultEntityFilters,\n EntityListContext,\n EntityListContextProps,\n} from './hooks/useEntityListProvider';\n\n/**\n * @public\n * @deprecated Moved to `@backstage/plugin-catalog-react/testUtils`\n */\nexport function MockEntityListContextProvider<\n T extends DefaultEntityFilters = DefaultEntityFilters,\n>(\n props: PropsWithChildren<{\n value?: Partial<EntityListContextProps<T>>;\n }>,\n) {\n const { children, value } = props;\n\n // Provides a default implementation that stores filter state, for testing components that\n // reflect filter state.\n const [filters, setFilters] = useState<T>(value?.filters ?? ({} as T));\n\n const updateFilters = useCallback(\n (update: Partial<T> | ((prevFilters: T) => Partial<T>)) => {\n setFilters(prevFilters => {\n const newFilters =\n typeof update === 'function' ? update(prevFilters) : update;\n return { ...prevFilters, ...newFilters };\n });\n },\n [],\n );\n\n // Memoize the default values since pickers have useEffect triggers on these; naively defaulting\n // below with `?? <X>` breaks referential equality on subsequent updates.\n const defaultValues = useMemo(\n () => ({\n entities: [],\n backendEntities: [],\n queryParameters: {},\n }),\n [],\n );\n\n const resolvedValue: EntityListContextProps<T> = useMemo(\n () => ({\n entities: value?.entities ?? defaultValues.entities,\n backendEntities: value?.backendEntities ?? defaultValues.backendEntities,\n updateFilters: value?.updateFilters ?? updateFilters,\n filters,\n loading: value?.loading ?? false,\n queryParameters: value?.queryParameters ?? defaultValues.queryParameters,\n error: value?.error,\n totalItems:\n value?.totalItems ?? (value?.entities ?? defaultValues.entities).length,\n limit: value?.limit ?? 20,\n offset: value?.offset,\n setLimit: value?.setLimit ?? (() => {}),\n setOffset: value?.setOffset,\n paginationMode: value?.paginationMode ?? 'none',\n }),\n [value, defaultValues, filters, updateFilters],\n );\n\n return (\n <EntityListContext.Provider value={resolvedValue}>\n {children}\n </EntityListContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;AAgCO,SAAS,8BAGd,KAGA,EAAA;AACA,EAAM,MAAA,EAAE,QAAU,EAAA,KAAA,EAAU,GAAA,KAAA,CAAA;AAI5B,EAAM,MAAA,CAAC,SAAS,UAAU,CAAA,GAAI,SAAY,KAAO,EAAA,OAAA,IAAY,EAAQ,CAAA,CAAA;AAErE,EAAA,MAAM,aAAgB,GAAA,WAAA;AAAA,IACpB,CAAC,MAA0D,KAAA;AACzD,MAAA,UAAA,CAAW,CAAe,WAAA,KAAA;AACxB,QAAA,MAAM,aACJ,OAAO,MAAA,KAAW,UAAa,GAAA,MAAA,CAAO,WAAW,CAAI,GAAA,MAAA,CAAA;AACvD,QAAA,OAAO,EAAE,GAAG,WAAa,EAAA,GAAG,UAAW,EAAA,CAAA;AAAA,OACxC,CAAA,CAAA;AAAA,KACH;AAAA,IACA,EAAC;AAAA,GACH,CAAA;AAIA,EAAA,MAAM,aAAgB,GAAA,OAAA;AAAA,IACpB,OAAO;AAAA,MACL,UAAU,EAAC;AAAA,MACX,iBAAiB,EAAC;AAAA,MAClB,iBAAiB,EAAC;AAAA,KACpB,CAAA;AAAA,IACA,EAAC;AAAA,GACH,CAAA;AAEA,EAAA,MAAM,aAA2C,GAAA,OAAA;AAAA,IAC/C,OAAO;AAAA,MACL,QAAA,EAAU,KAAO,EAAA,QAAA,IAAY,aAAc,CAAA,QAAA;AAAA,MAC3C,eAAA,EAAiB,KAAO,EAAA,eAAA,IAAmB,aAAc,CAAA,eAAA;AAAA,MACzD,aAAA,EAAe,OAAO,aAAiB,IAAA,aAAA;AAAA,MACvC,OAAA;AAAA,MACA,OAAA,EAAS,OAAO,OAAW,IAAA,KAAA;AAAA,MAC3B,eAAA,EAAiB,KAAO,EAAA,eAAA,IAAmB,aAAc,CAAA,eAAA;AAAA,MACzD,OAAO,KAAO,EAAA,KAAA;AAAA,MACd,YACE,KAAO,EAAA,UAAA,IAAA,CAAe,KAAO,EAAA,QAAA,IAAY,cAAc,QAAU,EAAA,MAAA;AAAA,MACnE,KAAA,EAAO,OAAO,KAAS,IAAA,EAAA;AAAA,MACvB,QAAQ,KAAO,EAAA,MAAA;AAAA,MACf,QAAA,EAAU,KAAO,EAAA,QAAA,KAAa,MAAM;AAAA,OAAC,CAAA;AAAA,MACrC,WAAW,KAAO,EAAA,SAAA;AAAA,MAClB,cAAA,EAAgB,OAAO,cAAkB,IAAA,MAAA;AAAA,KAC3C,CAAA;AAAA,IACA,CAAC,KAAA,EAAO,aAAe,EAAA,OAAA,EAAS,aAAa,CAAA;AAAA,GAC/C,CAAA;AAEA,EAAA,2CACG,iBAAkB,CAAA,QAAA,EAAlB,EAA2B,KAAA,EAAO,iBAChC,QACH,CAAA,CAAA;AAEJ;;;;"}
package/dist/index.d.ts CHANGED
@@ -929,11 +929,6 @@ declare function entityRouteParams(entity: Entity): {
929
929
  readonly name: string;
930
930
  };
931
931
 
932
- /** @public */
933
- declare function MockEntityListContextProvider<T extends DefaultEntityFilters = DefaultEntityFilters>(props: PropsWithChildren<{
934
- value?: Partial<EntityListContextProps<T>>;
935
- }>): React__default.JSX.Element;
936
-
937
932
  /** @public */
938
933
  type CatalogReactComponentsNameToClassKey = {
939
934
  CatalogReactUserListPicker: CatalogReactUserListPickerClassKey;
@@ -973,4 +968,12 @@ type EntitySourceLocation = {
973
968
  /** @public */
974
969
  declare function getEntitySourceLocation(entity: Entity, scmIntegrationsApi: typeof scmIntegrationsApiRef.T): EntitySourceLocation | undefined;
975
970
 
971
+ /**
972
+ * @public
973
+ * @deprecated Moved to `@backstage/plugin-catalog-react/testUtils`
974
+ */
975
+ declare function MockEntityListContextProvider<T extends DefaultEntityFilters = DefaultEntityFilters>(props: PropsWithChildren<{
976
+ value?: Partial<EntityListContextProps<T>>;
977
+ }>): React__default.JSX.Element;
978
+
976
979
  export { type AllowedEntityFilters, AsyncEntityProvider, type AsyncEntityProviderProps, type BackstageOverrides, CatalogFilterLayout, type CatalogReactComponentsNameToClassKey, type CatalogReactEntityAutocompletePickerClassKey, type CatalogReactEntityDisplayNameClassKey, type CatalogReactEntityLifecyclePickerClassKey, type CatalogReactEntityNamespacePickerClassKey, type CatalogReactEntityOwnerPickerClassKey, type CatalogReactEntityProcessingStatusPickerClassKey, type CatalogReactEntitySearchBarClassKey, type CatalogReactEntityTagPickerClassKey, type CatalogReactUserListPickerClassKey, type DefaultEntityFilters, DefaultFilters, type DefaultFiltersProps, EntityAutocompletePicker, type EntityAutocompletePickerProps, EntityDisplayName, type EntityDisplayNameProps, EntityErrorFilter, type EntityFilter, EntityKindFilter, EntityKindPicker, type EntityKindPickerProps, EntityLifecycleFilter, EntityLifecyclePicker, EntityListContext, type EntityListContextProps, type EntityListPagination, EntityListProvider, type EntityListProviderProps, type EntityLoadingStatus, EntityNamespaceFilter, EntityNamespacePicker, type EntityNamespacePickerProps, EntityOrphanFilter, EntityOwnerFilter, EntityOwnerPicker, type EntityOwnerPickerProps, EntityPeekAheadPopover, type EntityPeekAheadPopoverProps, type EntityPresentationApi, EntityProcessingStatusPicker, EntityProvider, type EntityProviderProps, EntityRefLink, type EntityRefLinkProps, EntityRefLinks, type EntityRefLinksProps, type EntityRefPresentation, type EntityRefPresentationSnapshot, EntitySearchBar, type EntitySourceLocation, EntityTable, type EntityTableProps, EntityTagFilter, EntityTagPicker, type EntityTagPickerProps, EntityTextFilter, EntityTypeFilter, EntityTypePicker, type EntityTypePickerProps, EntityUserFilter, FavoriteEntity, type FavoriteEntityProps, type FixedWidthFormControlLabelClassKey, InspectEntityDialog, MissingAnnotationEmptyState, type MissingAnnotationEmptyStateClassKey, MockEntityListContextProvider, MockStarredEntitiesApi, type PaginationMode, type StarredEntitiesApi, UnregisterEntityDialog, type UnregisterEntityDialogProps, UserListFilter, type UserListFilterKind, UserListPicker, type UserListPickerProps, catalogApiRef, columnFactories, defaultEntityPresentation, entityPresentationApiRef, entityRouteParams, entityRouteRef, getEntityRelations, getEntitySourceLocation, humanizeEntityRef, starredEntitiesApiRef, useAsyncEntity, useEntity, useEntityList, useEntityOwnership, useEntityPresentation, useEntityTypeFilter, useRelatedEntities, useStarredEntities, useStarredEntity };
package/dist/index.esm.js CHANGED
@@ -37,8 +37,8 @@ export { useStarredEntity } from './hooks/useStarredEntity.esm.js';
37
37
  export { useEntityOwnership } from './hooks/useEntityOwnership.esm.js';
38
38
  export { EntityErrorFilter, EntityKindFilter, EntityLifecycleFilter, EntityNamespaceFilter, EntityOrphanFilter, EntityOwnerFilter, EntityTagFilter, EntityTextFilter, EntityTypeFilter, EntityUserFilter, UserListFilter } from './filters.esm.js';
39
39
  export { entityRouteParams, entityRouteRef } from './routes.esm.js';
40
- export { MockEntityListContextProvider } from './testUtils/providers.esm.js';
41
40
  export { getEntityRelations } from './utils/getEntityRelations.esm.js';
42
41
  export { getEntitySourceLocation } from './utils/getEntitySourceLocation.esm.js';
43
42
  import '@backstage/catalog-model';
43
+ export { MockEntityListContextProvider } from './deprecated.esm.js';
44
44
  //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1,47 @@
1
+ import React, { useState, useCallback, useMemo } from 'react';
2
+ import { EntityListContext } from '@backstage/plugin-catalog-react';
3
+
4
+ function MockEntityListContextProvider(props) {
5
+ const { children, value } = props;
6
+ const [filters, setFilters] = useState(value?.filters ?? {});
7
+ const updateFilters = useCallback(
8
+ (update) => {
9
+ setFilters((prevFilters) => {
10
+ const newFilters = typeof update === "function" ? update(prevFilters) : update;
11
+ return { ...prevFilters, ...newFilters };
12
+ });
13
+ },
14
+ []
15
+ );
16
+ const defaultValues = useMemo(
17
+ () => ({
18
+ entities: [],
19
+ backendEntities: [],
20
+ queryParameters: {}
21
+ }),
22
+ []
23
+ );
24
+ const resolvedValue = useMemo(
25
+ () => ({
26
+ entities: value?.entities ?? defaultValues.entities,
27
+ backendEntities: value?.backendEntities ?? defaultValues.backendEntities,
28
+ updateFilters: value?.updateFilters ?? updateFilters,
29
+ filters,
30
+ loading: value?.loading ?? false,
31
+ queryParameters: value?.queryParameters ?? defaultValues.queryParameters,
32
+ error: value?.error,
33
+ totalItems: value?.totalItems ?? (value?.entities ?? defaultValues.entities).length,
34
+ limit: value?.limit ?? 20,
35
+ offset: value?.offset,
36
+ setLimit: value?.setLimit ?? (() => {
37
+ }),
38
+ setOffset: value?.setOffset,
39
+ paginationMode: value?.paginationMode ?? "none"
40
+ }),
41
+ [value, defaultValues, filters, updateFilters]
42
+ );
43
+ return /* @__PURE__ */ React.createElement(EntityListContext.Provider, { value: resolvedValue }, children);
44
+ }
45
+
46
+ export { MockEntityListContextProvider };
47
+ //# sourceMappingURL=MockEntityListContextProvider.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MockEntityListContextProvider.esm.js","sources":["../../src/testUtils/MockEntityListContextProvider.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, {\n PropsWithChildren,\n useCallback,\n useMemo,\n useState,\n} from 'react';\nimport {\n DefaultEntityFilters,\n EntityListContext,\n EntityListContextProps,\n} from '@backstage/plugin-catalog-react';\n\n/**\n * Simplifies testing of code that uses the entity list hooks.\n *\n * @public\n */\nexport function MockEntityListContextProvider<\n T extends DefaultEntityFilters = DefaultEntityFilters,\n>(\n props: PropsWithChildren<{\n value?: Partial<EntityListContextProps<T>>;\n }>,\n) {\n const { children, value } = props;\n\n // Provides a default implementation that stores filter state, for testing components that\n // reflect filter state.\n const [filters, setFilters] = useState<T>(value?.filters ?? ({} as T));\n\n const updateFilters = useCallback(\n (update: Partial<T> | ((prevFilters: T) => Partial<T>)) => {\n setFilters(prevFilters => {\n const newFilters =\n typeof update === 'function' ? update(prevFilters) : update;\n return { ...prevFilters, ...newFilters };\n });\n },\n [],\n );\n\n // Memoize the default values since pickers have useEffect triggers on these; naively defaulting\n // below with `?? <X>` breaks referential equality on subsequent updates.\n const defaultValues = useMemo(\n () => ({\n entities: [],\n backendEntities: [],\n queryParameters: {},\n }),\n [],\n );\n\n const resolvedValue: EntityListContextProps<T> = useMemo(\n () => ({\n entities: value?.entities ?? defaultValues.entities,\n backendEntities: value?.backendEntities ?? defaultValues.backendEntities,\n updateFilters: value?.updateFilters ?? updateFilters,\n filters,\n loading: value?.loading ?? false,\n queryParameters: value?.queryParameters ?? defaultValues.queryParameters,\n error: value?.error,\n totalItems:\n value?.totalItems ?? (value?.entities ?? defaultValues.entities).length,\n limit: value?.limit ?? 20,\n offset: value?.offset,\n setLimit: value?.setLimit ?? (() => {}),\n setOffset: value?.setOffset,\n paginationMode: value?.paginationMode ?? 'none',\n }),\n [value, defaultValues, filters, updateFilters],\n );\n\n return (\n <EntityListContext.Provider value={resolvedValue}>\n {children}\n </EntityListContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;AAiCO,SAAS,8BAGd,KAGA,EAAA;AACA,EAAM,MAAA,EAAE,QAAU,EAAA,KAAA,EAAU,GAAA,KAAA,CAAA;AAI5B,EAAM,MAAA,C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,KAAa,MAAM;AAAA,OAAC,CAAA;AAAA,MACrC,WAAW,KAAO,EAAA,SAAA;AAAA,MAClB,cAAA,EAAgB,OAAO,cAAkB,IAAA,MAAA;AAAA,KAC3C,CAAA;AAAA,IACA,CAAC,KAAA,EAAO,aAAe,EAAA,OAAA,EAAS,aAAa,CAAA;AAAA,GAC/C,CAAA;AAEA,EAAA,2CACG,iBAAkB,CAAA,QAAA,EAAlB,EAA2B,KAAA,EAAO,iBAChC,QACH,CAAA,CAAA;AAEJ;;;;"}
@@ -0,0 +1,54 @@
1
+ import { createApiFactory } from '@backstage/frontend-plugin-api';
2
+ import { InMemoryCatalogClient } from '@backstage/catalog-client/testUtils';
3
+ import { catalogApiRef } from '@backstage/plugin-catalog-react';
4
+
5
+ function simpleMock(ref, mockFactory) {
6
+ return (partialImpl) => {
7
+ const mock = mockFactory();
8
+ if (partialImpl) {
9
+ for (const [key, impl] of Object.entries(partialImpl)) {
10
+ if (typeof impl === "function") {
11
+ mock[key].mockImplementation(impl);
12
+ } else {
13
+ mock[key] = impl;
14
+ }
15
+ }
16
+ }
17
+ return Object.assign(mock, {
18
+ factory: createApiFactory({
19
+ api: ref,
20
+ deps: {},
21
+ factory: () => mock
22
+ })
23
+ });
24
+ };
25
+ }
26
+ function catalogApiMock(options) {
27
+ return new InMemoryCatalogClient(options);
28
+ }
29
+ ((catalogApiMock2) => {
30
+ catalogApiMock2.factory = (options) => createApiFactory({
31
+ api: catalogApiRef,
32
+ deps: {},
33
+ factory: () => new InMemoryCatalogClient(options)
34
+ });
35
+ catalogApiMock2.mock = simpleMock(catalogApiRef, () => ({
36
+ getEntities: jest.fn(),
37
+ getEntitiesByRefs: jest.fn(),
38
+ queryEntities: jest.fn(),
39
+ getEntityAncestors: jest.fn(),
40
+ getEntityByRef: jest.fn(),
41
+ removeEntityByUid: jest.fn(),
42
+ refreshEntity: jest.fn(),
43
+ getEntityFacets: jest.fn(),
44
+ getLocationById: jest.fn(),
45
+ getLocationByRef: jest.fn(),
46
+ addLocation: jest.fn(),
47
+ removeLocationById: jest.fn(),
48
+ getLocationByEntity: jest.fn(),
49
+ validateEntity: jest.fn()
50
+ }));
51
+ })(catalogApiMock || (catalogApiMock = {}));
52
+
53
+ export { catalogApiMock };
54
+ //# sourceMappingURL=catalogApiMock.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalogApiMock.esm.js","sources":["../../src/testUtils/catalogApiMock.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ApiFactory,\n ApiRef,\n createApiFactory,\n} from '@backstage/frontend-plugin-api';\nimport { InMemoryCatalogClient } from '@backstage/catalog-client/testUtils';\nimport { Entity } from '@backstage/catalog-model';\nimport { catalogApiRef } from '@backstage/plugin-catalog-react';\nimport { CatalogApi } from '@backstage/catalog-client';\nimport { ApiMock } from '@backstage/frontend-test-utils';\n\n/** @internal */\nfunction simpleMock<TApi>(\n ref: ApiRef<TApi>,\n mockFactory: () => jest.Mocked<TApi>,\n): (partialImpl?: Partial<TApi>) => ApiMock<TApi> {\n return partialImpl => {\n const mock = mockFactory();\n if (partialImpl) {\n for (const [key, impl] of Object.entries(partialImpl)) {\n if (typeof impl === 'function') {\n (mock as any)[key].mockImplementation(impl);\n } else {\n (mock as any)[key] = impl;\n }\n }\n }\n return Object.assign(mock, {\n factory: createApiFactory({\n api: ref,\n deps: {},\n factory: () => mock,\n }),\n }) as ApiMock<TApi>;\n };\n}\n\n/**\n * Creates a fake catalog client that handles entities in memory storage. Note\n * that this client may be severely limited in functionality, and advanced\n * functions may not be available at all.\n *\n * @public\n */\nexport function catalogApiMock(options?: { entities?: Entity[] }): CatalogApi {\n return new InMemoryCatalogClient(options);\n}\n\n/**\n * A collection of mock functionality for the catalog service.\n *\n * @public\n */\nexport namespace catalogApiMock {\n /**\n * Creates a fake catalog client that handles entities in memory storage. Note\n * that this client may be severely limited in functionality, and advanced\n * functions may not be available at all.\n */\n export const factory = (options?: {\n entities?: Entity[];\n }): ApiFactory<CatalogApi, CatalogApi, {}> =>\n createApiFactory({\n api: catalogApiRef,\n deps: {},\n factory: () => new InMemoryCatalogClient(options),\n });\n /**\n * Creates a catalog client whose methods are mock functions, possibly with\n * some of them overloaded by the caller.\n */\n export const mock = simpleMock(catalogApiRef, () => ({\n getEntities: jest.fn(),\n getEntitiesByRefs: jest.fn(),\n queryEntities: jest.fn(),\n getEntityAncestors: jest.fn(),\n getEntityByRef: jest.fn(),\n removeEntityByUid: jest.fn(),\n refreshEntity: jest.fn(),\n getEntityFacets: jest.fn(),\n getLocationById: jest.fn(),\n getLocationByRef: jest.fn(),\n addLocation: jest.fn(),\n removeLocationById: jest.fn(),\n getLocationByEntity: jest.fn(),\n validateEntity: jest.fn(),\n }));\n}\n"],"names":["catalogApiMock"],"mappings":";;;;AA4BA,SAAS,UAAA,CACP,KACA,WACgD,EAAA;AAChD,EAAA,OAAO,CAAe,WAAA,KAAA;AACpB,IAAA,MAAM,OAAO,WAAY,EAAA,CAAA;AACzB,IAAA,IAAI,WAAa,EAAA;AACf,MAAA,KAAA,MAAW,CAAC,GAAK,EAAA,IAAI,KAAK,MAAO,CAAA,OAAA,CAAQ,WAAW,CAAG,EAAA;AACrD,QAAI,IAAA,OAAO,SAAS,UAAY,EAAA;AAC9B,UAAC,IAAa,CAAA,GAAG,CAAE,CAAA,kBAAA,CAAmB,IAAI,CAAA,CAAA;AAAA,SACrC,MAAA;AACL,UAAC,IAAA,CAAa,GAAG,CAAI,GAAA,IAAA,CAAA;AAAA,SACvB;AAAA,OACF;AAAA,KACF;AACA,IAAO,O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A;AAAA,GACxB,CAAA,CAAA,CAAA;AAAA,CAjCa,EAAA,cAAA,KAAA,cAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
@@ -0,0 +1,48 @@
1
+ import { ApiFactory } from '@backstage/frontend-plugin-api';
2
+ import { Entity } from '@backstage/catalog-model';
3
+ import { CatalogApi } from '@backstage/catalog-client';
4
+ import { ApiMock } from '@backstage/frontend-test-utils';
5
+ import React__default, { PropsWithChildren } from 'react';
6
+ import { DefaultEntityFilters, EntityListContextProps } from '@backstage/plugin-catalog-react';
7
+
8
+ /**
9
+ * Creates a fake catalog client that handles entities in memory storage. Note
10
+ * that this client may be severely limited in functionality, and advanced
11
+ * functions may not be available at all.
12
+ *
13
+ * @public
14
+ */
15
+ declare function catalogApiMock(options?: {
16
+ entities?: Entity[];
17
+ }): CatalogApi;
18
+ /**
19
+ * A collection of mock functionality for the catalog service.
20
+ *
21
+ * @public
22
+ */
23
+ declare namespace catalogApiMock {
24
+ /**
25
+ * Creates a fake catalog client that handles entities in memory storage. Note
26
+ * that this client may be severely limited in functionality, and advanced
27
+ * functions may not be available at all.
28
+ */
29
+ const factory: (options?: {
30
+ entities?: Entity[];
31
+ }) => ApiFactory<CatalogApi, CatalogApi, {}>;
32
+ /**
33
+ * Creates a catalog client whose methods are mock functions, possibly with
34
+ * some of them overloaded by the caller.
35
+ */
36
+ const mock: (partialImpl?: Partial<CatalogApi> | undefined) => ApiMock<CatalogApi>;
37
+ }
38
+
39
+ /**
40
+ * Simplifies testing of code that uses the entity list hooks.
41
+ *
42
+ * @public
43
+ */
44
+ declare function MockEntityListContextProvider<T extends DefaultEntityFilters = DefaultEntityFilters>(props: PropsWithChildren<{
45
+ value?: Partial<EntityListContextProps<T>>;
46
+ }>): React__default.JSX.Element;
47
+
48
+ export { MockEntityListContextProvider, catalogApiMock };
@@ -0,0 +1,3 @@
1
+ export { catalogApiMock } from './testUtils/catalogApiMock.esm.js';
2
+ export { MockEntityListContextProvider } from './testUtils/MockEntityListContextProvider.esm.js';
3
+ //# sourceMappingURL=testUtils.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testUtils.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-react",
3
- "version": "1.14.0-next.1",
3
+ "version": "1.14.0-next.2",
4
4
  "description": "A frontend library that helps other Backstage plugins interact with the catalog",
5
5
  "backstage": {
6
6
  "role": "web-library",
@@ -38,13 +38,19 @@
38
38
  "types": "./dist/alpha.d.ts",
39
39
  "default": "./dist/alpha.esm.js"
40
40
  },
41
+ "./testUtils": {
42
+ "import": "./dist/testUtils.esm.js",
43
+ "types": "./dist/testUtils.d.ts",
44
+ "default": "./dist/testUtils.esm.js"
45
+ },
41
46
  "./package.json": "./package.json"
42
47
  },
43
48
  "main": "./dist/index.esm.js",
44
49
  "types": "./dist/index.d.ts",
45
50
  "files": [
46
51
  "dist",
47
- "alpha"
52
+ "alpha",
53
+ "testUtils"
48
54
  ],
49
55
  "scripts": {
50
56
  "build": "backstage-cli package build",
@@ -56,14 +62,15 @@
56
62
  "test": "backstage-cli package test"
57
63
  },
58
64
  "dependencies": {
59
- "@backstage/catalog-client": "1.7.0",
65
+ "@backstage/catalog-client": "1.7.1-next.0",
60
66
  "@backstage/catalog-model": "1.7.0",
61
- "@backstage/core-compat-api": "0.3.1-next.1",
62
- "@backstage/core-components": "0.15.1-next.1",
67
+ "@backstage/core-compat-api": "0.3.1-next.2",
68
+ "@backstage/core-components": "0.15.1-next.2",
63
69
  "@backstage/core-plugin-api": "1.10.0-next.1",
64
70
  "@backstage/errors": "1.2.4",
65
- "@backstage/frontend-plugin-api": "0.9.0-next.1",
66
- "@backstage/integration-react": "1.2.0-next.1",
71
+ "@backstage/frontend-plugin-api": "0.9.0-next.2",
72
+ "@backstage/frontend-test-utils": "0.2.1-next.2",
73
+ "@backstage/integration-react": "1.2.0-next.2",
67
74
  "@backstage/plugin-catalog-common": "1.1.0",
68
75
  "@backstage/plugin-permission-common": "0.8.1",
69
76
  "@backstage/plugin-permission-react": "0.4.27-next.1",
@@ -82,12 +89,11 @@
82
89
  "zen-observable": "^0.10.0"
83
90
  },
84
91
  "devDependencies": {
85
- "@backstage/cli": "0.28.0-next.1",
92
+ "@backstage/cli": "0.28.0-next.2",
86
93
  "@backstage/core-app-api": "1.15.1-next.1",
87
- "@backstage/frontend-test-utils": "0.2.1-next.1",
88
94
  "@backstage/plugin-catalog-common": "1.1.0",
89
95
  "@backstage/plugin-scaffolder-common": "1.5.6",
90
- "@backstage/test-utils": "1.6.1-next.1",
96
+ "@backstage/test-utils": "1.6.1-next.2",
91
97
  "@testing-library/dom": "^10.0.0",
92
98
  "@testing-library/jest-dom": "^6.0.0",
93
99
  "@testing-library/react": "^16.0.0",
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@backstage/plugin-catalog-react__testutils",
3
+ "version": "1.14.0-next.2",
4
+ "main": "../dist/testUtils.esm.js",
5
+ "module": "../dist/testUtils.esm.js",
6
+ "types": "../dist/testUtils.d.ts"
7
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"providers.esm.js","sources":["../../src/testUtils/providers.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, {\n PropsWithChildren,\n useCallback,\n useMemo,\n useState,\n} from 'react';\nimport {\n DefaultEntityFilters,\n EntityListContext,\n EntityListContextProps,\n} from '../hooks/useEntityListProvider';\n\n/** @public */\nexport function MockEntityListContextProvider<\n T extends DefaultEntityFilters = DefaultEntityFilters,\n>(\n props: PropsWithChildren<{\n value?: Partial<EntityListContextProps<T>>;\n }>,\n) {\n const { children, value } = props;\n\n // Provides a default implementation that stores filter state, for testing components that\n // reflect filter state.\n const [filters, setFilters] = useState<T>(value?.filters ?? ({} as T));\n\n const updateFilters = useCallback(\n (update: Partial<T> | ((prevFilters: T) => Partial<T>)) => {\n setFilters(prevFilters => {\n const newFilters =\n typeof update === 'function' ? update(prevFilters) : update;\n return { ...prevFilters, ...newFilters };\n });\n },\n [],\n );\n\n // Memoize the default values since pickers have useEffect triggers on these; naively defaulting\n // below with `?? <X>` breaks referential equality on subsequent updates.\n const defaultValues = useMemo(\n () => ({\n entities: [],\n backendEntities: [],\n queryParameters: {},\n }),\n [],\n );\n\n const resolvedValue: EntityListContextProps<T> = useMemo(\n () => ({\n entities: value?.entities ?? defaultValues.entities,\n backendEntities: value?.backendEntities ?? defaultValues.backendEntities,\n updateFilters: value?.updateFilters ?? updateFilters,\n filters,\n loading: value?.loading ?? false,\n queryParameters: value?.queryParameters ?? defaultValues.queryParameters,\n error: value?.error,\n totalItems:\n value?.totalItems ?? (value?.entities ?? defaultValues.entities).length,\n limit: value?.limit ?? 20,\n offset: value?.offset,\n setLimit: value?.setLimit ?? (() => {}),\n setOffset: value?.setOffset,\n paginationMode: value?.paginationMode ?? 'none',\n }),\n [value, defaultValues, filters, updateFilters],\n );\n\n return (\n <EntityListContext.Provider value={resolvedValue}>\n {children}\n </EntityListContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;AA6BO,SAAS,8BAGd,KAGA,EAAA;AACA,EAAM,MAAA,EAAE,QAAU,EAAA,KAAA,EAAU,GAAA,KAAA,CAAA;AAI5B,EAAM,MAAA,CAAC,SAAS,UAAU,CAAA,GAAI,SAAY,KAAO,EAAA,OAAA,IAAY,EAAQ,CAAA,CAAA;AAErE,EAAA,MAAM,aAAgB,GAAA,WAAA;AAAA,IACpB,CAAC,MAA0D,KAAA;AACzD,MAAA,UAAA,CAAW,CAAe,W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