@atlassian/clientside-extensions-components 2.4.1 → 2.5.0-84fa90d-kwd5ix2w
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/dist/cjs/ExtensionPoint.js +4 -4
- package/dist/cjs/ExtensionPoint.js.map +1 -1
- package/dist/cjs/ExtensionPointInfo.js +8 -8
- package/dist/cjs/ExtensionPointInfo.js.map +1 -1
- package/dist/cjs/ExtensionsObservable.js +14 -12
- package/dist/cjs/ExtensionsObservable.js.map +1 -1
- package/dist/cjs/debug/useDebug.js +3 -3
- package/dist/cjs/debug/useDebug.js.map +1 -1
- package/dist/cjs/debug/useDiscovery.js +3 -3
- package/dist/cjs/debug/useDiscovery.js.map +1 -1
- package/dist/cjs/debug/useLogging.js +3 -3
- package/dist/cjs/debug/useLogging.js.map +1 -1
- package/dist/cjs/debug/useValidation.js +3 -3
- package/dist/cjs/debug/useValidation.js.map +1 -1
- package/dist/cjs/handlers/AsyncPanelHandler.js +10 -9
- package/dist/cjs/handlers/AsyncPanelHandler.js.map +1 -1
- package/dist/cjs/handlers/ButtonHandler.js +4 -3
- package/dist/cjs/handlers/ButtonHandler.js.map +1 -1
- package/dist/cjs/handlers/LinkHandler.js +4 -3
- package/dist/cjs/handlers/LinkHandler.js.map +1 -1
- package/dist/cjs/handlers/ModalHandler.js +16 -14
- package/dist/cjs/handlers/ModalHandler.js.map +1 -1
- package/dist/cjs/handlers/PanelHandler.js +6 -5
- package/dist/cjs/handlers/PanelHandler.js.map +1 -1
- package/dist/cjs/handlers/SectionHandler.js +3 -2
- package/dist/cjs/handlers/SectionHandler.js.map +1 -1
- package/dist/cjs/handlers/index.js +1 -0
- package/dist/cjs/handlers/index.js.map +1 -1
- package/dist/cjs/index.js +11 -10
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/renderElementAsReact.js +3 -3
- package/dist/cjs/renderElementAsReact.js.map +1 -1
- package/dist/cjs/styled.js +13 -13
- package/dist/cjs/styled.js.map +1 -1
- package/dist/cjs/useExtensions.js +18 -14
- package/dist/cjs/useExtensions.js.map +1 -1
- package/dist/cjs/useWebPanelRenderer.js +4 -4
- package/dist/cjs/useWebPanelRenderer.js.map +1 -1
- package/dist/esm/ExtensionPointInfo.js.map +1 -1
- package/dist/esm/ExtensionsObservable.js.map +1 -1
- package/dist/esm/debug/types.js +1 -0
- package/dist/esm/handlers/types.js +1 -0
- package/dist/esm/renderElementAsReact.js +1 -1
- package/dist/esm/renderElementAsReact.js.map +1 -1
- package/dist/esm/useWebPanelRenderer.js.map +1 -1
- package/dist/types/ExtensionPointInfo.d.ts.map +1 -1
- package/dist/types/styled.d.ts +7 -7
- package/dist/types/styled.d.ts.map +1 -1
- package/lib/ExtensionPointInfo.tsx +1 -0
- package/lib/ExtensionsObservable.test.ts +2 -2
- package/package.json +12 -11
- package/dist/cjs/ExtensionPoint.test.js +0 -96
- package/dist/cjs/ExtensionPoint.test.js.map +0 -1
- package/dist/cjs/ExtensionPointInfo.test.js +0 -189
- package/dist/cjs/ExtensionPointInfo.test.js.map +0 -1
- package/dist/cjs/ExtensionsObservable.test.js +0 -349
- package/dist/cjs/ExtensionsObservable.test.js.map +0 -1
- package/dist/cjs/debug/useDebug.test.js +0 -49
- package/dist/cjs/debug/useDebug.test.js.map +0 -1
- package/dist/cjs/debug/useDiscovery.test.js +0 -49
- package/dist/cjs/debug/useDiscovery.test.js.map +0 -1
- package/dist/cjs/debug/useLogging.test.js +0 -49
- package/dist/cjs/debug/useLogging.test.js.map +0 -1
- package/dist/cjs/debug/useValidation.test.js +0 -49
- package/dist/cjs/debug/useValidation.test.js.map +0 -1
- package/dist/cjs/handlers/AsyncPanelHandler.test.js +0 -189
- package/dist/cjs/handlers/AsyncPanelHandler.test.js.map +0 -1
- package/dist/cjs/handlers/ButtonHandler.test.js +0 -40
- package/dist/cjs/handlers/ButtonHandler.test.js.map +0 -1
- package/dist/cjs/handlers/LinkHandler.test.js +0 -43
- package/dist/cjs/handlers/LinkHandler.test.js.map +0 -1
- package/dist/cjs/handlers/ModalHandler.test.js +0 -189
- package/dist/cjs/handlers/ModalHandler.test.js.map +0 -1
- package/dist/cjs/handlers/PanelHandler.test.js +0 -88
- package/dist/cjs/handlers/PanelHandler.test.js.map +0 -1
- package/dist/cjs/handlers/SectionHandler.test.js +0 -17
- package/dist/cjs/handlers/SectionHandler.test.js.map +0 -1
- package/dist/cjs/index.test.js +0 -7
- package/dist/cjs/index.test.js.map +0 -1
- package/dist/cjs/renderElementAsReact.test.js +0 -54
- package/dist/cjs/renderElementAsReact.test.js.map +0 -1
- package/dist/cjs/useExtensions.test.js +0 -647
- package/dist/cjs/useExtensions.test.js.map +0 -1
- package/dist/esm/ExtensionPoint.test.js +0 -93
- package/dist/esm/ExtensionPoint.test.js.map +0 -1
- package/dist/esm/ExtensionPointInfo.test.js +0 -186
- package/dist/esm/ExtensionPointInfo.test.js.map +0 -1
- package/dist/esm/ExtensionsObservable.test.js +0 -346
- package/dist/esm/ExtensionsObservable.test.js.map +0 -1
- package/dist/esm/debug/useDebug.test.js +0 -46
- package/dist/esm/debug/useDebug.test.js.map +0 -1
- package/dist/esm/debug/useDiscovery.test.js +0 -46
- package/dist/esm/debug/useDiscovery.test.js.map +0 -1
- package/dist/esm/debug/useLogging.test.js +0 -46
- package/dist/esm/debug/useLogging.test.js.map +0 -1
- package/dist/esm/debug/useValidation.test.js +0 -46
- package/dist/esm/debug/useValidation.test.js.map +0 -1
- package/dist/esm/handlers/AsyncPanelHandler.test.js +0 -186
- package/dist/esm/handlers/AsyncPanelHandler.test.js.map +0 -1
- package/dist/esm/handlers/ButtonHandler.test.js +0 -37
- package/dist/esm/handlers/ButtonHandler.test.js.map +0 -1
- package/dist/esm/handlers/LinkHandler.test.js +0 -40
- package/dist/esm/handlers/LinkHandler.test.js.map +0 -1
- package/dist/esm/handlers/ModalHandler.test.js +0 -186
- package/dist/esm/handlers/ModalHandler.test.js.map +0 -1
- package/dist/esm/handlers/PanelHandler.test.js +0 -85
- package/dist/esm/handlers/PanelHandler.test.js.map +0 -1
- package/dist/esm/handlers/SectionHandler.test.js +0 -14
- package/dist/esm/handlers/SectionHandler.test.js.map +0 -1
- package/dist/esm/index.test.js +0 -7
- package/dist/esm/index.test.js.map +0 -1
- package/dist/esm/renderElementAsReact.test.js +0 -51
- package/dist/esm/renderElementAsReact.test.js.map +0 -1
- package/dist/esm/useExtensions.test.js +0 -644
- package/dist/esm/useExtensions.test.js.map +0 -1
- package/dist/types/ExtensionPoint.test.d.ts +0 -2
- package/dist/types/ExtensionPoint.test.d.ts.map +0 -1
- package/dist/types/ExtensionPointInfo.test.d.ts +0 -2
- package/dist/types/ExtensionPointInfo.test.d.ts.map +0 -1
- package/dist/types/ExtensionsObservable.test.d.ts +0 -2
- package/dist/types/ExtensionsObservable.test.d.ts.map +0 -1
- package/dist/types/debug/useDebug.test.d.ts +0 -2
- package/dist/types/debug/useDebug.test.d.ts.map +0 -1
- package/dist/types/debug/useDiscovery.test.d.ts +0 -2
- package/dist/types/debug/useDiscovery.test.d.ts.map +0 -1
- package/dist/types/debug/useLogging.test.d.ts +0 -2
- package/dist/types/debug/useLogging.test.d.ts.map +0 -1
- package/dist/types/debug/useValidation.test.d.ts +0 -2
- package/dist/types/debug/useValidation.test.d.ts.map +0 -1
- package/dist/types/handlers/AsyncPanelHandler.test.d.ts +0 -2
- package/dist/types/handlers/AsyncPanelHandler.test.d.ts.map +0 -1
- package/dist/types/handlers/ButtonHandler.test.d.ts +0 -2
- package/dist/types/handlers/ButtonHandler.test.d.ts.map +0 -1
- package/dist/types/handlers/LinkHandler.test.d.ts +0 -2
- package/dist/types/handlers/LinkHandler.test.d.ts.map +0 -1
- package/dist/types/handlers/ModalHandler.test.d.ts +0 -2
- package/dist/types/handlers/ModalHandler.test.d.ts.map +0 -1
- package/dist/types/handlers/PanelHandler.test.d.ts +0 -2
- package/dist/types/handlers/PanelHandler.test.d.ts.map +0 -1
- package/dist/types/handlers/SectionHandler.test.d.ts +0 -2
- package/dist/types/handlers/SectionHandler.test.d.ts.map +0 -1
- package/dist/types/index.test.d.ts +0 -1
- package/dist/types/index.test.d.ts.map +0 -1
- package/dist/types/renderElementAsReact.test.d.ts +0 -2
- package/dist/types/renderElementAsReact.test.d.ts.map +0 -1
- package/dist/types/useExtensions.test.d.ts +0 -2
- package/dist/types/useExtensions.test.d.ts.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionPoint.test.js","sourceRoot":"","sources":["../../lib/ExtensionPoint.test.tsx"],"names":[],"mappings":";;;AAAA,qDAA+B;AAC/B,yCAAuC;AACvC,kDAAqD;AAErD,uHAAiE;AACjE,0FAAsE;AAGtE,sFAAgE;AAEhE,8EAA8C;AAE9C,IAAI,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;AAEvD,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAC9B,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AAC5B,sDAAsD;AACtD,gDAAgD;AAChD,KAAK,CAAC,wBAAwB,EAAE,CAAC;AASjC,MAAM,kBAAkB,GAAwB;IAC5C,GAAG,EAAE,QAAQ;IACb,QAAQ,EAAE,eAAe;IACzB,MAAM,EAAE,EAAE;IACV,UAAU,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE;CACxD,CAAC;AACF,MAAM,oBAAoB,GAAwB;IAC9C,GAAG,EAAE,QAAQ;IACb,QAAQ,EAAE,eAAe;IACzB,MAAM,EAAE,EAAE;IACV,UAAU,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE;CACxC,CAAC;AAEF,MAAM,QAAQ,GAAc,CAAC,KAAK,EAAE,EAAE;IAClC,MAAM,EAAE,IAAI,EAAE,GAAG,KAAyB,CAAC;IAE3C,OAAO,IAAI;QACP,CAAC,CAAC;YACI,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,EAAE;SACf;QACH,CAAC,CAAC;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ing-library/react';\nimport type { ExtensionDescriptor } from '@atlassian/clientside-extensions-registry';\nimport registry from '@atlassian/clientside-extensions-registry';\nimport { ErrorLevels } from '@atlassian/clientside-extensions-schema';\nimport type { Validator } from '@atlassian/clientside-extensions-schema';\n\nimport * as debug from '@atlassian/clientside-extensions-debug';\n\nimport ExtensionPoint from './ExtensionPoint';\n\njest.mock('@atlassian/clientside-extensions-registry');\n\ndebug.setLoggingEnabled(true);\ndebug.setDebugEnabled(true);\n// avoid spamming the console with error/warn messages\n// eslint-disable-next-line no-underscore-dangle\ndebug._deregisterDefaultLogger();\n\ntype MockSubjectPayload = {\n descriptors: ExtensionDescriptor[];\n loadingState: boolean;\n};\n\ntype MockLocationObserver = (payload: MockSubjectPayload) => void;\n\nconst supportedExtension: ExtensionDescriptor = {\n key: 'fake-1',\n location: 'fake-location',\n weight: 10,\n attributes: { label: 'a fake label', type: 'button' },\n};\nconst unsupportedExtension: ExtensionDescriptor = {\n key: 'fake-2',\n location: 'fake-location',\n weight: 10,\n attributes: { label: 'a fake label' },\n};\n\nconst validate: Validator = (input) => {\n const { type } = input as { type: string };\n\n return type\n ? {\n errors: [],\n warnings: [],\n }\n : {\n errors: [\n {\n error: 'error',\n severity: ErrorLevels.ERROR,\n },\n ],\n warnings: [],\n };\n};\n\n/**\n * Only testing the runtime error of a wrong child provided and that the component is using the right hook.\n * The rest of the tests are in useExtensions.tests.\n */\ndescribe('ExtensionPoint component', () => {\n it('should not render if the child provided is not a callback', async () => {\n const onDebugSpy = jest.fn();\n debug.observeLogger(onDebugSpy);\n\n mocked(registry.getLocation).mockImplementation(() => ({\n subscribe: () => {\n return {\n unsubscribe: () => {},\n };\n },\n }));\n\n const TestComponent = () => {\n return (\n // @ts-expect-error - forcing ts to ignore assigning a wrong child type to execute JS runtime validation\n <ExtensionPoint name=\"fake-extension\" context={null} options={{ attributeValidator: validate }}>\n <p data-testid=\"test-text\">Wrong child</p>;\n </ExtensionPoint>\n );\n };\n\n const { container } = render(<TestComponent />);\n\n expect(container.firstChild).toBe(null); // nothing rendered by the component\n expect(onDebugSpy).toHaveBeenCalledTimes(1);\n });\n\n it('should provide all the extensions information to the child callback', () => {\n let locationObserver: MockLocationObserver;\n mocked(registry.getLocation).mockImplementation(() => ({\n subscribe: (observer) => {\n locationObserver = observer;\n return {\n unsubscribe: () => {},\n };\n },\n }));\n\n const TestComponent = () => {\n return (\n <ExtensionPoint name=\"fake-extension\" context={null} options={{ attributeValidator: validate }}>\n {(supportedExtensions, unsupportedExtensions, isLoading) => (\n <>\n <p data-testid=\"isLoading\">{JSON.stringify(isLoading)}</p>\n <p data-testid=\"supportedExtensions\">{JSON.stringify(supportedExtensions)}</p>\n <p data-testid=\"unsupportedExtensions\">{JSON.stringify(unsupportedExtensions)}</p>\n </>\n )}\n </ExtensionPoint>\n );\n };\n\n const { asFragment } = render(<TestComponent />);\n\n expect(asFragment()).toMatchSnapshot('loading state');\n\n act(() => {\n locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });\n });\n\n expect(asFragment()).toMatchSnapshot('with extensions state');\n });\n});\n"]}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
|
-
const utils_1 = require("ts-jest/utils");
|
|
6
|
-
const react_2 = require("@testing-library/react");
|
|
7
|
-
const useDiscovery_1 = tslib_1.__importDefault(require("./debug/useDiscovery"));
|
|
8
|
-
const ExtensionPointInfo_1 = tslib_1.__importDefault(require("./ExtensionPointInfo"));
|
|
9
|
-
jest.mock('./debug/useDiscovery');
|
|
10
|
-
const mockSchemaDocument = {
|
|
11
|
-
objectTypes: {
|
|
12
|
-
Schema: {
|
|
13
|
-
name: 'Schema',
|
|
14
|
-
description: '',
|
|
15
|
-
descriptors: [
|
|
16
|
-
{
|
|
17
|
-
description: 'Extension type',
|
|
18
|
-
name: 'type',
|
|
19
|
-
required: true,
|
|
20
|
-
type: 'AvailableTypes!',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
description: '',
|
|
24
|
-
name: 'label',
|
|
25
|
-
required: true,
|
|
26
|
-
type: 'String!',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
description: 'Glyph name',
|
|
30
|
-
name: 'glyph',
|
|
31
|
-
required: false,
|
|
32
|
-
type: 'GlyphType',
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
description: 'Hidden flag to hide web-item',
|
|
36
|
-
name: 'hidden',
|
|
37
|
-
required: false,
|
|
38
|
-
type: 'Boolean',
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
description: 'Callback triggered on user interaction with the Web-item. Signature depends on web-item type.',
|
|
42
|
-
name: 'onAction',
|
|
43
|
-
required: false,
|
|
44
|
-
type: 'Function',
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
FooInput: {
|
|
49
|
-
name: 'FooInput',
|
|
50
|
-
description: '',
|
|
51
|
-
descriptors: [
|
|
52
|
-
{
|
|
53
|
-
description: '',
|
|
54
|
-
name: 'foo',
|
|
55
|
-
required: true,
|
|
56
|
-
type: 'String!',
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
enumTypes: {
|
|
62
|
-
GlyphType: {
|
|
63
|
-
name: 'GlyphType',
|
|
64
|
-
description: '',
|
|
65
|
-
values: ['cross', 'tick'],
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
unionTypes: {
|
|
69
|
-
AvailableTypes: {
|
|
70
|
-
name: 'AvailableTypes',
|
|
71
|
-
description: '',
|
|
72
|
-
types: ['ModalType', 'LinkType', 'ButtonType', 'PanelType'],
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
scalars: {
|
|
76
|
-
ModalType: {
|
|
77
|
-
name: 'ModalType',
|
|
78
|
-
description: 'The value must be the constant "modal".',
|
|
79
|
-
},
|
|
80
|
-
LinkType: {
|
|
81
|
-
name: 'LinkType',
|
|
82
|
-
description: 'The value must be the constant "link".',
|
|
83
|
-
},
|
|
84
|
-
ButtonType: {
|
|
85
|
-
name: 'ButtonType',
|
|
86
|
-
description: 'The value must be the constant "button".',
|
|
87
|
-
},
|
|
88
|
-
PanelType: {
|
|
89
|
-
name: 'PanelType',
|
|
90
|
-
description: 'The value must be the constant "panel".',
|
|
91
|
-
},
|
|
92
|
-
String: {
|
|
93
|
-
name: 'String',
|
|
94
|
-
description: 'The `String` type represents textual data.',
|
|
95
|
-
},
|
|
96
|
-
Boolean: {
|
|
97
|
-
name: 'Boolean',
|
|
98
|
-
description: 'The `Boolean` type represents `true` or `false`.',
|
|
99
|
-
},
|
|
100
|
-
Function: {
|
|
101
|
-
name: 'Function',
|
|
102
|
-
description: 'The `Function` type represents any javascript function.',
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
const mockContextSchemaDocument = {
|
|
107
|
-
objectTypes: {
|
|
108
|
-
ContextSchema: {
|
|
109
|
-
name: 'ContextSchema',
|
|
110
|
-
description: '',
|
|
111
|
-
descriptors: [
|
|
112
|
-
{
|
|
113
|
-
description: '',
|
|
114
|
-
name: 'value',
|
|
115
|
-
required: false,
|
|
116
|
-
type: 'Number',
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
enumTypes: {},
|
|
122
|
-
unionTypes: {},
|
|
123
|
-
scalars: {
|
|
124
|
-
Number: {
|
|
125
|
-
name: 'Number',
|
|
126
|
-
description: 'The value should be a number.',
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
const findModalElement = () => react_2.screen.findByRole('dialog');
|
|
131
|
-
const findModalContentElement = async () => {
|
|
132
|
-
const infoModalElm = await findModalElement();
|
|
133
|
-
return infoModalElm.querySelector('header + div');
|
|
134
|
-
};
|
|
135
|
-
const openModal = async (container) => {
|
|
136
|
-
const modalTriggerBtn = await react_2.findByRole(container, 'button');
|
|
137
|
-
react_2.fireEvent.click(modalTriggerBtn);
|
|
138
|
-
};
|
|
139
|
-
const TestComponent = ({ name, schemaDocuments }) => {
|
|
140
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
141
|
-
react_1.default.createElement("p", null, "Test extension point"),
|
|
142
|
-
react_1.default.createElement(ExtensionPointInfo_1.default, { name: name, schemaDocuments: schemaDocuments })));
|
|
143
|
-
};
|
|
144
|
-
TestComponent.defaultProps = {
|
|
145
|
-
name: 'test-extension-point',
|
|
146
|
-
schemaDocuments: { schema: mockSchemaDocument, contextSchema: mockContextSchemaDocument },
|
|
147
|
-
};
|
|
148
|
-
describe('ExtensionPointInfo', () => {
|
|
149
|
-
beforeEach(() => {
|
|
150
|
-
utils_1.mocked(useDiscovery_1.default).mockReturnValue([true, () => { }]);
|
|
151
|
-
});
|
|
152
|
-
it('should only show the the extension point icon if dicovery is enabled', () => {
|
|
153
|
-
// discovery disabled
|
|
154
|
-
utils_1.mocked(useDiscovery_1.default).mockReturnValue([false, () => { }]);
|
|
155
|
-
const { asFragment, rerender } = react_2.render(react_1.default.createElement(TestComponent, null));
|
|
156
|
-
expect(asFragment()).toMatchSnapshot('discovery disabled, icon is hidden');
|
|
157
|
-
// discovery enabled
|
|
158
|
-
utils_1.mocked(useDiscovery_1.default).mockReturnValue([true, () => { }]);
|
|
159
|
-
rerender(react_1.default.createElement(TestComponent, null));
|
|
160
|
-
expect(asFragment()).toMatchSnapshot('discovery enabled, icon is shown');
|
|
161
|
-
});
|
|
162
|
-
it('should show the extension info in a modal when the icon is clicked', async () => {
|
|
163
|
-
const { container } = react_2.render(react_1.default.createElement(TestComponent, null));
|
|
164
|
-
await openModal(container);
|
|
165
|
-
expect(await findModalContentElement()).toMatchSnapshot('extension info modal opened');
|
|
166
|
-
});
|
|
167
|
-
it('should close the extension info modal when clicking the close button', async () => {
|
|
168
|
-
const { container } = react_2.render(react_1.default.createElement(TestComponent, null));
|
|
169
|
-
await openModal(container);
|
|
170
|
-
const infoModalElm = await findModalElement();
|
|
171
|
-
const closeModalBtn = await react_2.findByRole(infoModalElm, 'button');
|
|
172
|
-
react_2.fireEvent.click(closeModalBtn);
|
|
173
|
-
expect(react_2.screen.queryByRole('dialog')).toBeNull();
|
|
174
|
-
});
|
|
175
|
-
it('should render a message if no schema is provided', async () => {
|
|
176
|
-
const { container, findByText } = react_2.render(
|
|
177
|
-
// @ts-expect-errors We pass a null value to test the runtime
|
|
178
|
-
react_1.default.createElement(TestComponent, { schemaDocuments: { schema: null, contextSchema: mockContextSchemaDocument } }));
|
|
179
|
-
await openModal(container);
|
|
180
|
-
expect(await findByText('No attributes information provided for this extension point.')).toBeTruthy();
|
|
181
|
-
});
|
|
182
|
-
it('should render a message if no schemas are provided', async () => {
|
|
183
|
-
// @ts-expect-errors We pass a null value to test the runtime
|
|
184
|
-
const { container, findByText } = react_2.render(react_1.default.createElement(TestComponent, { schemaDocuments: { schema: mockSchemaDocument, contextSchema: null } }));
|
|
185
|
-
await openModal(container);
|
|
186
|
-
expect(await findByText('No context information provided for this extension point.')).toBeTruthy();
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
//# sourceMappingURL=ExtensionPointInfo.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionPointInfo.test.js","sourceRoot":"","sources":["../../lib/ExtensionPointInfo.test.tsx"],"names":[],"mappings":";;;AAAA,0DAA0B;AAC1B,yCAAuC;AACvC,kDAAwG;AAGxG,gFAAgD;AAEhD,sFAAsD;AAEtD,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;AAElC,MAAM,kBAAkB,GAAuB;IAC3C,WAAW,EAAE;QACT,MAAM,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,EAAE;YACf,WAAW,EAAE;gBACT;oBACI,WAAW,EAAE,gBAAgB;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CAAC,8BAAC,aAAa,IAAC,eAAe,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,IAAI,EAAE,GAAI,CAAC,CAAC;QAElI,MAAM,SAAS,CAAC,SAAS,CAAC,CAAC;QAE3B,MAAM,CAAC,MAAM,UAAU,CAAC,2DAA2D,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;IACvG,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import React from 'react';\nimport { mocked } from 'ts-jest/utils';\nimport { render, fireEvent, screen, findByRole as findByRoleInContainer } from '@testing-library/react';\n\nimport type { SerializedDocument } from '@atlassian/clientside-extensions-schema';\nimport useDiscovery from './debug/useDiscovery';\nimport type { ExtensionPointInfoProps } from './ExtensionPointInfo';\nimport ExtensionPointInfo from './ExtensionPointInfo';\n\njest.mock('./debug/useDiscovery');\n\nconst mockSchemaDocument: SerializedDocument = {\n objectTypes: {\n Schema: {\n name: 'Schema',\n description: '',\n descriptors: [\n {\n description: 'Extension type',\n name: 'type',\n required: true,\n type: 'AvailableTypes!',\n },\n {\n description: '',\n name: 'label',\n required: true,\n type: 'String!',\n },\n {\n description: 'Glyph name',\n name: 'glyph',\n required: false,\n type: 'GlyphType',\n },\n {\n description: 'Hidden flag to hide web-item',\n name: 'hidden',\n required: false,\n type: 'Boolean',\n },\n {\n description: 'Callback triggered on user interaction with the Web-item. Signature depends on web-item type.',\n name: 'onAction',\n required: false,\n type: 'Function',\n },\n ],\n },\n FooInput: {\n name: 'FooInput',\n description: '',\n descriptors: [\n {\n description: '',\n name: 'foo',\n required: true,\n type: 'String!',\n },\n ],\n },\n },\n enumTypes: {\n GlyphType: {\n name: 'GlyphType',\n description: '',\n values: ['cross', 'tick'],\n },\n },\n unionTypes: {\n AvailableTypes: {\n name: 'AvailableTypes',\n description: '',\n types: ['ModalType', 'LinkType', 'ButtonType', 'PanelType'],\n },\n },\n scalars: {\n ModalType: {\n name: 'ModalType',\n description: 'The value must be the constant \"modal\".',\n },\n LinkType: {\n name: 'LinkType',\n description: 'The value must be the constant \"link\".',\n },\n ButtonType: {\n name: 'ButtonType',\n description: 'The value must be the constant \"button\".',\n },\n PanelType: {\n name: 'PanelType',\n description: 'The value must be the constant \"panel\".',\n },\n String: {\n name: 'String',\n description: 'The `String` type represents textual data.',\n },\n Boolean: {\n name: 'Boolean',\n description: 'The `Boolean` type represents `true` or `false`.',\n },\n Function: {\n name: 'Function',\n description: 'The `Function` type represents any javascript function.',\n },\n },\n};\n\nconst mockContextSchemaDocument: SerializedDocument = {\n objectTypes: {\n ContextSchema: {\n name: 'ContextSchema',\n description: '',\n descriptors: [\n {\n description: '',\n name: 'value',\n required: false,\n type: 'Number',\n },\n ],\n },\n },\n enumTypes: {},\n unionTypes: {},\n scalars: {\n Number: {\n name: 'Number',\n description: 'The value should be a number.',\n },\n },\n};\n\nconst findModalElement = () => screen.findByRole('dialog');\n\nconst findModalContentElement = async () => {\n const infoModalElm = await findModalElement();\n\n return infoModalElm.querySelector('header + div');\n};\n\nconst openModal = async (container: HTMLElement) => {\n const modalTriggerBtn = await findByRoleInContainer(container, 'button');\n fireEvent.click(modalTriggerBtn);\n};\n\nconst TestComponent = ({ name, schemaDocuments }: ExtensionPointInfoProps) => {\n return (\n <>\n <p>Test extension point</p>\n <ExtensionPointInfo name={name} schemaDocuments={schemaDocuments} />\n </>\n );\n};\n\nTestComponent.defaultProps = {\n name: 'test-extension-point',\n schemaDocuments: { schema: mockSchemaDocument, contextSchema: mockContextSchemaDocument },\n} as Partial<ExtensionPointInfoProps>;\n\ndescribe('ExtensionPointInfo', () => {\n beforeEach(() => {\n mocked(useDiscovery).mockReturnValue([true, () => {}]);\n });\n\n it('should only show the the extension point icon if dicovery is enabled', () => {\n // discovery disabled\n mocked(useDiscovery).mockReturnValue([false, () => {}]);\n\n const { asFragment, rerender } = render(<TestComponent />);\n\n expect(asFragment()).toMatchSnapshot('discovery disabled, icon is hidden');\n\n // discovery enabled\n mocked(useDiscovery).mockReturnValue([true, () => {}]);\n\n rerender(<TestComponent />);\n\n expect(asFragment()).toMatchSnapshot('discovery enabled, icon is shown');\n });\n\n it('should show the extension info in a modal when the icon is clicked', async () => {\n const { container } = render(<TestComponent />);\n\n await openModal(container);\n\n expect(await findModalContentElement()).toMatchSnapshot('extension info modal opened');\n });\n\n it('should close the extension info modal when clicking the close button', async () => {\n const { container } = render(<TestComponent />);\n\n await openModal(container);\n\n const infoModalElm = await findModalElement();\n const closeModalBtn = await findByRoleInContainer(infoModalElm, 'button');\n fireEvent.click(closeModalBtn);\n\n expect(screen.queryByRole('dialog')).toBeNull();\n });\n\n it('should render a message if no schema is provided', async () => {\n const { container, findByText } = render(\n // @ts-expect-errors We pass a null value to test the runtime\n <TestComponent schemaDocuments={{ schema: null, contextSchema: mockContextSchemaDocument }} />,\n );\n\n await openModal(container);\n\n expect(await findByText('No attributes information provided for this extension point.')).toBeTruthy();\n });\n\n it('should render a message if no schemas are provided', async () => {\n // @ts-expect-errors We pass a null value to test the runtime\n const { container, findByText } = render(<TestComponent schemaDocuments={{ schema: mockSchemaDocument, contextSchema: null }} />);\n\n await openModal(container);\n\n expect(await findByText('No context information provided for this extension point.')).toBeTruthy();\n });\n});\n"]}
|
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const utils_1 = require("ts-jest/utils");
|
|
5
|
-
const clientside_extensions_registry_1 = tslib_1.__importDefault(require("@atlassian/clientside-extensions-registry"));
|
|
6
|
-
const debug = tslib_1.__importStar(require("@atlassian/clientside-extensions-debug"));
|
|
7
|
-
const ExtensionsObservable_1 = require("./ExtensionsObservable");
|
|
8
|
-
jest.mock('@atlassian/clientside-extensions-registry');
|
|
9
|
-
debug.setLoggingEnabled(true);
|
|
10
|
-
debug.setDebugEnabled(true);
|
|
11
|
-
// avoid spamming the console with error/warn messages
|
|
12
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
13
|
-
debug._deregisterDefaultLogger();
|
|
14
|
-
function createMockLocationObserver() {
|
|
15
|
-
let locationObserver;
|
|
16
|
-
utils_1.mocked(clientside_extensions_registry_1.default.getLocation).mockClear();
|
|
17
|
-
utils_1.mocked(clientside_extensions_registry_1.default.getLocation).mockImplementation(() => ({
|
|
18
|
-
subscribe: (observer) => {
|
|
19
|
-
locationObserver = observer;
|
|
20
|
-
return {
|
|
21
|
-
unsubscribe: () => { },
|
|
22
|
-
};
|
|
23
|
-
},
|
|
24
|
-
}));
|
|
25
|
-
return (payload) => locationObserver(payload);
|
|
26
|
-
}
|
|
27
|
-
const supportedExtension = {
|
|
28
|
-
key: 'fake-1',
|
|
29
|
-
location: 'fake-location',
|
|
30
|
-
weight: 10,
|
|
31
|
-
attributes: { label: 'a fake label' },
|
|
32
|
-
attributesProvider: () => ({ type: 'button' }),
|
|
33
|
-
};
|
|
34
|
-
const unsupportedExtension = {
|
|
35
|
-
key: 'fake-2',
|
|
36
|
-
location: 'fake-location',
|
|
37
|
-
weight: 10,
|
|
38
|
-
attributes: { label: 'a fake label' },
|
|
39
|
-
};
|
|
40
|
-
const LOCATION = 'fake-location';
|
|
41
|
-
describe('getExtensionPointSubscription', () => {
|
|
42
|
-
const onDebugSpy = jest.fn();
|
|
43
|
-
debug.observeLogger(onDebugSpy);
|
|
44
|
-
let locationObserver;
|
|
45
|
-
beforeEach(() => {
|
|
46
|
-
onDebugSpy.mockClear();
|
|
47
|
-
locationObserver = createMockLocationObserver();
|
|
48
|
-
});
|
|
49
|
-
it('should return an observable', () => {
|
|
50
|
-
const observable = ExtensionsObservable_1.getExtensionPointSubscription(LOCATION, null);
|
|
51
|
-
expect(observable.subscribe).toBeInstanceOf(Function);
|
|
52
|
-
});
|
|
53
|
-
it('should allow to subscribe to updates', () => {
|
|
54
|
-
const observerSpy = jest.fn();
|
|
55
|
-
ExtensionsObservable_1.getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
|
|
56
|
-
locationObserver({ descriptors: [], loadingState: true });
|
|
57
|
-
expect(observerSpy).toBeCalled();
|
|
58
|
-
});
|
|
59
|
-
it('should allow to unsubscribe from updates again', () => {
|
|
60
|
-
const observerSpy = jest.fn();
|
|
61
|
-
const { unsubscribe } = ExtensionsObservable_1.getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
|
|
62
|
-
locationObserver({ descriptors: [], loadingState: true });
|
|
63
|
-
unsubscribe();
|
|
64
|
-
locationObserver({ descriptors: [], loadingState: false });
|
|
65
|
-
expect(observerSpy).toBeCalledTimes(1);
|
|
66
|
-
});
|
|
67
|
-
it('should notify the observer of registered extensions', () => {
|
|
68
|
-
const observerSpy = jest.fn();
|
|
69
|
-
ExtensionsObservable_1.getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
|
|
70
|
-
locationObserver({ descriptors: [supportedExtension], loadingState: false });
|
|
71
|
-
expect(observerSpy).toBeCalled();
|
|
72
|
-
expect(observerSpy.mock.calls[0][0]).toBeTruthy();
|
|
73
|
-
const { descriptors, loadingState } = observerSpy.mock.calls[0][0].state;
|
|
74
|
-
expect(descriptors.length).toBe(1);
|
|
75
|
-
expect(loadingState).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
it('should only provide descriptors to observer once loading is over', () => {
|
|
78
|
-
const observerSpy = jest.fn();
|
|
79
|
-
ExtensionsObservable_1.getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
|
|
80
|
-
locationObserver({ descriptors: [], loadingState: true });
|
|
81
|
-
locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: true });
|
|
82
|
-
locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });
|
|
83
|
-
expect(observerSpy).toBeCalledTimes(3);
|
|
84
|
-
// first call
|
|
85
|
-
const argFirst = observerSpy.mock.calls[0][0];
|
|
86
|
-
const { descriptors: descriptorsFirst, loadingState: loadingFirst } = argFirst.state;
|
|
87
|
-
expect(descriptorsFirst.length).toBe(0);
|
|
88
|
-
expect(loadingFirst).toBe(true);
|
|
89
|
-
// second call
|
|
90
|
-
const argSecond = observerSpy.mock.calls[1][0];
|
|
91
|
-
const { descriptors: descriptorsSecond, loadingState: loadingSecond } = argSecond.state;
|
|
92
|
-
expect(descriptorsSecond.length).toBe(0);
|
|
93
|
-
expect(loadingSecond).toBe(true);
|
|
94
|
-
// third call
|
|
95
|
-
const argThird = observerSpy.mock.calls[2][0];
|
|
96
|
-
const { descriptors: descriptorsThird, loadingState: loadingThird } = argThird.state;
|
|
97
|
-
expect(descriptorsThird.length).toBe(2);
|
|
98
|
-
expect(loadingThird).toBe(false);
|
|
99
|
-
expect(descriptorsThird[0].key).toBe(supportedExtension.key);
|
|
100
|
-
expect(descriptorsThird[1].key).toBe(unsupportedExtension.key);
|
|
101
|
-
});
|
|
102
|
-
it('should provide registered extensions with the provided context', () => {
|
|
103
|
-
const someContext = { foo: 'bar' };
|
|
104
|
-
const attributeProviderSpy = jest.fn();
|
|
105
|
-
ExtensionsObservable_1.getExtensionPointSubscription(LOCATION, someContext);
|
|
106
|
-
locationObserver({
|
|
107
|
-
descriptors: [
|
|
108
|
-
{
|
|
109
|
-
key: 'fake-1',
|
|
110
|
-
location: LOCATION,
|
|
111
|
-
weight: 10,
|
|
112
|
-
attributes: { label: 'a fake label' },
|
|
113
|
-
attributesProvider: attributeProviderSpy,
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
loadingState: false,
|
|
117
|
-
});
|
|
118
|
-
expect(attributeProviderSpy).toBeCalledTimes(1);
|
|
119
|
-
expect(attributeProviderSpy.mock.calls[0][1]).toBe(someContext);
|
|
120
|
-
});
|
|
121
|
-
it('should update if a new extension is registered', () => {
|
|
122
|
-
const observerSpy = jest.fn();
|
|
123
|
-
ExtensionsObservable_1.getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
|
|
124
|
-
locationObserver({ descriptors: [], loadingState: false });
|
|
125
|
-
locationObserver({ descriptors: [supportedExtension], loadingState: false });
|
|
126
|
-
locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });
|
|
127
|
-
expect(observerSpy).toBeCalledTimes(3);
|
|
128
|
-
// first call
|
|
129
|
-
const argFirst = observerSpy.mock.calls[0][0];
|
|
130
|
-
const { descriptors: descriptorsFirst } = argFirst.state;
|
|
131
|
-
expect(descriptorsFirst.length).toBe(0);
|
|
132
|
-
// second call
|
|
133
|
-
const argSecond = observerSpy.mock.calls[1][0];
|
|
134
|
-
const { descriptors: descriptorsSecond } = argSecond.state;
|
|
135
|
-
expect(descriptorsSecond.length).toBe(1);
|
|
136
|
-
// third call
|
|
137
|
-
const argThird = observerSpy.mock.calls[2][0];
|
|
138
|
-
const { descriptors: descriptorsThird } = argThird.state;
|
|
139
|
-
expect(descriptorsThird.length).toBe(2);
|
|
140
|
-
});
|
|
141
|
-
it('should update if an extension updates its attributes', async () => {
|
|
142
|
-
expect.assertions(5);
|
|
143
|
-
const observerSpy = jest.fn();
|
|
144
|
-
ExtensionsObservable_1.getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
|
|
145
|
-
let apiReference;
|
|
146
|
-
const selfUpdatingExtension = {
|
|
147
|
-
key: 'updating-extension',
|
|
148
|
-
location: LOCATION,
|
|
149
|
-
weight: 230,
|
|
150
|
-
attributes: { label: 'a fake label', type: 'button' },
|
|
151
|
-
attributesProvider: (api) => {
|
|
152
|
-
apiReference = api;
|
|
153
|
-
return {};
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
locationObserver({ descriptors: [supportedExtension, unsupportedExtension, selfUpdatingExtension], loadingState: false });
|
|
157
|
-
expect(observerSpy).toBeCalled();
|
|
158
|
-
observerSpy.mockClear();
|
|
159
|
-
apiReference.updateAttributes({ foo: 'bar' });
|
|
160
|
-
// wait for the update to go through which is a tick away
|
|
161
|
-
await new Promise((resolve) => {
|
|
162
|
-
setTimeout(() => {
|
|
163
|
-
expect(observerSpy).toBeCalled();
|
|
164
|
-
const { update } = observerSpy.mock.calls[0][0];
|
|
165
|
-
expect(update.length).toBe(1);
|
|
166
|
-
expect(update[0].key).toBe('updating-extension');
|
|
167
|
-
expect(update[0].attributes.foo).toBe('bar');
|
|
168
|
-
resolve();
|
|
169
|
-
}, 50);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
it('should batch updates together', async () => {
|
|
173
|
-
expect.assertions(8);
|
|
174
|
-
const observerSpy = jest.fn();
|
|
175
|
-
ExtensionsObservable_1.getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
|
|
176
|
-
let apiReference1;
|
|
177
|
-
const selfUpdatingExtension1 = {
|
|
178
|
-
key: 'updating-extension-1',
|
|
179
|
-
location: LOCATION,
|
|
180
|
-
weight: 230,
|
|
181
|
-
attributes: { label: 'a fake label', type: 'button' },
|
|
182
|
-
attributesProvider: (api) => {
|
|
183
|
-
apiReference1 = api;
|
|
184
|
-
return {};
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
let apiReference2;
|
|
188
|
-
const selfUpdatingExtension2 = {
|
|
189
|
-
key: 'updating-extension-2',
|
|
190
|
-
location: LOCATION,
|
|
191
|
-
weight: 230,
|
|
192
|
-
attributes: { label: 'a fake label', type: 'button' },
|
|
193
|
-
attributesProvider: (api) => {
|
|
194
|
-
apiReference2 = api;
|
|
195
|
-
return {};
|
|
196
|
-
},
|
|
197
|
-
};
|
|
198
|
-
locationObserver({ descriptors: [selfUpdatingExtension1, selfUpdatingExtension2], loadingState: false });
|
|
199
|
-
observerSpy.mockClear();
|
|
200
|
-
apiReference1.updateAttributes({ foo: 'bar' });
|
|
201
|
-
apiReference2.updateAttributes({ foo: 'bar' });
|
|
202
|
-
apiReference1.updateAttributes({ foo: 'foo of 1' });
|
|
203
|
-
apiReference2.updateAttributes({ foo: 'foo of 2' });
|
|
204
|
-
// wait for the update to go through which is a tick away
|
|
205
|
-
await new Promise((resolve) => {
|
|
206
|
-
setTimeout(() => {
|
|
207
|
-
expect(observerSpy).toBeCalledTimes(1);
|
|
208
|
-
const { update } = observerSpy.mock.calls[0][0];
|
|
209
|
-
expect(update.length).toBe(2);
|
|
210
|
-
expect(update[0].key).toBe('updating-extension-1');
|
|
211
|
-
expect(update[0].attributes.foo).toBe('foo of 1');
|
|
212
|
-
expect(update[0].attributes.foo).toBe('foo of 1');
|
|
213
|
-
expect(update[1].key).toBe('updating-extension-2');
|
|
214
|
-
expect(update[1].attributes.foo).toBe('foo of 2');
|
|
215
|
-
expect(update[1].attributes.foo).toBe('foo of 2');
|
|
216
|
-
resolve();
|
|
217
|
-
}, 50);
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
describe('getValidatedExtensions', () => {
|
|
222
|
-
const onDebugSpy = jest.fn();
|
|
223
|
-
const context = { foo: 'bar' };
|
|
224
|
-
debug.observeLogger(onDebugSpy);
|
|
225
|
-
let locationObserver;
|
|
226
|
-
let contextValidatorSpy;
|
|
227
|
-
let attributeValidatorSpy;
|
|
228
|
-
beforeEach(() => {
|
|
229
|
-
onDebugSpy.mockClear();
|
|
230
|
-
locationObserver = createMockLocationObserver();
|
|
231
|
-
contextValidatorSpy = jest.fn().mockReturnValue({ errors: [], warnings: [] });
|
|
232
|
-
attributeValidatorSpy = jest.fn().mockReturnValue({ errors: [], warnings: [] });
|
|
233
|
-
});
|
|
234
|
-
it('should not validate the context if no context is specified', () => {
|
|
235
|
-
ExtensionsObservable_1.getValidatedExtensions(LOCATION, null, {
|
|
236
|
-
contextValidator: contextValidatorSpy,
|
|
237
|
-
attributeValidator: attributeValidatorSpy,
|
|
238
|
-
});
|
|
239
|
-
expect(contextValidatorSpy).not.toBeCalled();
|
|
240
|
-
});
|
|
241
|
-
it('should validate the context if a context is specified', () => {
|
|
242
|
-
ExtensionsObservable_1.getValidatedExtensions(LOCATION, context, {
|
|
243
|
-
contextValidator: contextValidatorSpy,
|
|
244
|
-
attributeValidator: attributeValidatorSpy,
|
|
245
|
-
});
|
|
246
|
-
expect(contextValidatorSpy).toBeCalled();
|
|
247
|
-
expect(contextValidatorSpy.mock.calls[0][0]).toBe(context);
|
|
248
|
-
});
|
|
249
|
-
it('should throw an error if the context validation fails', () => {
|
|
250
|
-
expect(() => ExtensionsObservable_1.getValidatedExtensions(LOCATION, context, {
|
|
251
|
-
contextValidator: contextValidatorSpy.mockReturnValue({
|
|
252
|
-
errors: ['some error'],
|
|
253
|
-
warnings: [],
|
|
254
|
-
}),
|
|
255
|
-
attributeValidator: attributeValidatorSpy,
|
|
256
|
-
})).toThrow(`The context provided for extension-location "fake-location" does not match the schema`);
|
|
257
|
-
});
|
|
258
|
-
it('should not throw an error if the context validation has warnings', () => {
|
|
259
|
-
expect(() => ExtensionsObservable_1.getValidatedExtensions(LOCATION, context, {
|
|
260
|
-
contextValidator: contextValidatorSpy.mockReturnValue({
|
|
261
|
-
errors: [],
|
|
262
|
-
warnings: ['some warning'],
|
|
263
|
-
}),
|
|
264
|
-
attributeValidator: attributeValidatorSpy,
|
|
265
|
-
})).not.toThrow();
|
|
266
|
-
});
|
|
267
|
-
it('should return an observable', () => {
|
|
268
|
-
const observable = ExtensionsObservable_1.getValidatedExtensions(LOCATION, context, {
|
|
269
|
-
contextValidator: contextValidatorSpy,
|
|
270
|
-
attributeValidator: attributeValidatorSpy,
|
|
271
|
-
});
|
|
272
|
-
expect(observable.subscribe).toBeInstanceOf(Function);
|
|
273
|
-
});
|
|
274
|
-
it('should allow to subscribe to updates', () => {
|
|
275
|
-
const observerSpy = jest.fn();
|
|
276
|
-
ExtensionsObservable_1.getValidatedExtensions(LOCATION, context, {
|
|
277
|
-
contextValidator: contextValidatorSpy,
|
|
278
|
-
attributeValidator: attributeValidatorSpy,
|
|
279
|
-
}).subscribe(observerSpy);
|
|
280
|
-
locationObserver({ descriptors: [], loadingState: true });
|
|
281
|
-
expect(observerSpy).toBeCalled();
|
|
282
|
-
});
|
|
283
|
-
it('should allow to unsubscribe from updates again', () => {
|
|
284
|
-
const observerSpy = jest.fn();
|
|
285
|
-
const { unsubscribe } = ExtensionsObservable_1.getValidatedExtensions(LOCATION, context, {
|
|
286
|
-
contextValidator: contextValidatorSpy,
|
|
287
|
-
attributeValidator: attributeValidatorSpy,
|
|
288
|
-
}).subscribe(observerSpy);
|
|
289
|
-
locationObserver({ descriptors: [], loadingState: true });
|
|
290
|
-
locationObserver({ descriptors: [], loadingState: false });
|
|
291
|
-
unsubscribe();
|
|
292
|
-
locationObserver({ descriptors: [supportedExtension], loadingState: false });
|
|
293
|
-
expect(observerSpy).toBeCalledTimes(2);
|
|
294
|
-
});
|
|
295
|
-
it('should call attributeValidatorSpy with extension attributes', () => {
|
|
296
|
-
const observerSpy = jest.fn();
|
|
297
|
-
ExtensionsObservable_1.getValidatedExtensions(LOCATION, context, {
|
|
298
|
-
contextValidator: contextValidatorSpy,
|
|
299
|
-
attributeValidator: attributeValidatorSpy,
|
|
300
|
-
}).subscribe(observerSpy);
|
|
301
|
-
locationObserver({ descriptors: [supportedExtension], loadingState: false });
|
|
302
|
-
expect(attributeValidatorSpy).toBeCalledTimes(1);
|
|
303
|
-
expect(attributeValidatorSpy.mock.calls[0][0]).toStrictEqual({
|
|
304
|
-
...supportedExtension.attributes,
|
|
305
|
-
...supportedExtension.attributesProvider({}, null),
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
it('should declare all extensions as valid if validator always return "ok"', () => {
|
|
309
|
-
const observerSpy = jest.fn();
|
|
310
|
-
ExtensionsObservable_1.getValidatedExtensions(LOCATION, context, {
|
|
311
|
-
contextValidator: contextValidatorSpy,
|
|
312
|
-
attributeValidator: attributeValidatorSpy.mockReturnValue({ errors: [], warnings: [] }),
|
|
313
|
-
}).subscribe(observerSpy);
|
|
314
|
-
locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });
|
|
315
|
-
expect(observerSpy).toBeCalledTimes(1);
|
|
316
|
-
const [supported, unsupported] = observerSpy.mock.calls[0][0];
|
|
317
|
-
expect(supported.length).toBe(2);
|
|
318
|
-
expect(unsupported.length).toBe(0);
|
|
319
|
-
});
|
|
320
|
-
it('should move extensions into "unsupported" if validation fails', () => {
|
|
321
|
-
const observerSpy = jest.fn();
|
|
322
|
-
ExtensionsObservable_1.getValidatedExtensions(LOCATION, context, {
|
|
323
|
-
contextValidator: contextValidatorSpy,
|
|
324
|
-
attributeValidator: attributeValidatorSpy
|
|
325
|
-
.mockReturnValueOnce({ errors: [], warnings: [] })
|
|
326
|
-
.mockReturnValueOnce({ errors: ['some error'], warnings: [] }),
|
|
327
|
-
}).subscribe(observerSpy);
|
|
328
|
-
locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });
|
|
329
|
-
expect(observerSpy).toBeCalledTimes(1);
|
|
330
|
-
const [supported, unsupported] = observerSpy.mock.calls[0][0];
|
|
331
|
-
expect(supported.length).toBe(1);
|
|
332
|
-
expect(supported[0].key).toBe(supportedExtension.key);
|
|
333
|
-
expect(unsupported.length).toBe(1);
|
|
334
|
-
expect(unsupported[0].key).toBe(unsupportedExtension.key);
|
|
335
|
-
});
|
|
336
|
-
it('should declare all extensions as valid if validator has any warnings', () => {
|
|
337
|
-
const observerSpy = jest.fn();
|
|
338
|
-
ExtensionsObservable_1.getValidatedExtensions(LOCATION, context, {
|
|
339
|
-
contextValidator: contextValidatorSpy,
|
|
340
|
-
attributeValidator: attributeValidatorSpy.mockReturnValue({ errors: [], warnings: ['some warning'] }),
|
|
341
|
-
}).subscribe(observerSpy);
|
|
342
|
-
locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });
|
|
343
|
-
expect(observerSpy).toBeCalledTimes(1);
|
|
344
|
-
const [supported, unsupported] = observerSpy.mock.calls[0][0];
|
|
345
|
-
expect(supported.length).toBe(2);
|
|
346
|
-
expect(unsupported.length).toBe(0);
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
//# sourceMappingURL=ExtensionsObservable.test.js.map
|