@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.
Files changed (147) hide show
  1. package/dist/cjs/ExtensionPoint.js +4 -4
  2. package/dist/cjs/ExtensionPoint.js.map +1 -1
  3. package/dist/cjs/ExtensionPointInfo.js +8 -8
  4. package/dist/cjs/ExtensionPointInfo.js.map +1 -1
  5. package/dist/cjs/ExtensionsObservable.js +14 -12
  6. package/dist/cjs/ExtensionsObservable.js.map +1 -1
  7. package/dist/cjs/debug/useDebug.js +3 -3
  8. package/dist/cjs/debug/useDebug.js.map +1 -1
  9. package/dist/cjs/debug/useDiscovery.js +3 -3
  10. package/dist/cjs/debug/useDiscovery.js.map +1 -1
  11. package/dist/cjs/debug/useLogging.js +3 -3
  12. package/dist/cjs/debug/useLogging.js.map +1 -1
  13. package/dist/cjs/debug/useValidation.js +3 -3
  14. package/dist/cjs/debug/useValidation.js.map +1 -1
  15. package/dist/cjs/handlers/AsyncPanelHandler.js +10 -9
  16. package/dist/cjs/handlers/AsyncPanelHandler.js.map +1 -1
  17. package/dist/cjs/handlers/ButtonHandler.js +4 -3
  18. package/dist/cjs/handlers/ButtonHandler.js.map +1 -1
  19. package/dist/cjs/handlers/LinkHandler.js +4 -3
  20. package/dist/cjs/handlers/LinkHandler.js.map +1 -1
  21. package/dist/cjs/handlers/ModalHandler.js +16 -14
  22. package/dist/cjs/handlers/ModalHandler.js.map +1 -1
  23. package/dist/cjs/handlers/PanelHandler.js +6 -5
  24. package/dist/cjs/handlers/PanelHandler.js.map +1 -1
  25. package/dist/cjs/handlers/SectionHandler.js +3 -2
  26. package/dist/cjs/handlers/SectionHandler.js.map +1 -1
  27. package/dist/cjs/handlers/index.js +1 -0
  28. package/dist/cjs/handlers/index.js.map +1 -1
  29. package/dist/cjs/index.js +11 -10
  30. package/dist/cjs/index.js.map +1 -1
  31. package/dist/cjs/renderElementAsReact.js +3 -3
  32. package/dist/cjs/renderElementAsReact.js.map +1 -1
  33. package/dist/cjs/styled.js +13 -13
  34. package/dist/cjs/styled.js.map +1 -1
  35. package/dist/cjs/useExtensions.js +18 -14
  36. package/dist/cjs/useExtensions.js.map +1 -1
  37. package/dist/cjs/useWebPanelRenderer.js +4 -4
  38. package/dist/cjs/useWebPanelRenderer.js.map +1 -1
  39. package/dist/esm/ExtensionPointInfo.js.map +1 -1
  40. package/dist/esm/ExtensionsObservable.js.map +1 -1
  41. package/dist/esm/debug/types.js +1 -0
  42. package/dist/esm/handlers/types.js +1 -0
  43. package/dist/esm/renderElementAsReact.js +1 -1
  44. package/dist/esm/renderElementAsReact.js.map +1 -1
  45. package/dist/esm/useWebPanelRenderer.js.map +1 -1
  46. package/dist/types/ExtensionPointInfo.d.ts.map +1 -1
  47. package/dist/types/styled.d.ts +7 -7
  48. package/dist/types/styled.d.ts.map +1 -1
  49. package/lib/ExtensionPointInfo.tsx +1 -0
  50. package/lib/ExtensionsObservable.test.ts +2 -2
  51. package/package.json +12 -11
  52. package/dist/cjs/ExtensionPoint.test.js +0 -96
  53. package/dist/cjs/ExtensionPoint.test.js.map +0 -1
  54. package/dist/cjs/ExtensionPointInfo.test.js +0 -189
  55. package/dist/cjs/ExtensionPointInfo.test.js.map +0 -1
  56. package/dist/cjs/ExtensionsObservable.test.js +0 -349
  57. package/dist/cjs/ExtensionsObservable.test.js.map +0 -1
  58. package/dist/cjs/debug/useDebug.test.js +0 -49
  59. package/dist/cjs/debug/useDebug.test.js.map +0 -1
  60. package/dist/cjs/debug/useDiscovery.test.js +0 -49
  61. package/dist/cjs/debug/useDiscovery.test.js.map +0 -1
  62. package/dist/cjs/debug/useLogging.test.js +0 -49
  63. package/dist/cjs/debug/useLogging.test.js.map +0 -1
  64. package/dist/cjs/debug/useValidation.test.js +0 -49
  65. package/dist/cjs/debug/useValidation.test.js.map +0 -1
  66. package/dist/cjs/handlers/AsyncPanelHandler.test.js +0 -189
  67. package/dist/cjs/handlers/AsyncPanelHandler.test.js.map +0 -1
  68. package/dist/cjs/handlers/ButtonHandler.test.js +0 -40
  69. package/dist/cjs/handlers/ButtonHandler.test.js.map +0 -1
  70. package/dist/cjs/handlers/LinkHandler.test.js +0 -43
  71. package/dist/cjs/handlers/LinkHandler.test.js.map +0 -1
  72. package/dist/cjs/handlers/ModalHandler.test.js +0 -189
  73. package/dist/cjs/handlers/ModalHandler.test.js.map +0 -1
  74. package/dist/cjs/handlers/PanelHandler.test.js +0 -88
  75. package/dist/cjs/handlers/PanelHandler.test.js.map +0 -1
  76. package/dist/cjs/handlers/SectionHandler.test.js +0 -17
  77. package/dist/cjs/handlers/SectionHandler.test.js.map +0 -1
  78. package/dist/cjs/index.test.js +0 -7
  79. package/dist/cjs/index.test.js.map +0 -1
  80. package/dist/cjs/renderElementAsReact.test.js +0 -54
  81. package/dist/cjs/renderElementAsReact.test.js.map +0 -1
  82. package/dist/cjs/useExtensions.test.js +0 -647
  83. package/dist/cjs/useExtensions.test.js.map +0 -1
  84. package/dist/esm/ExtensionPoint.test.js +0 -93
  85. package/dist/esm/ExtensionPoint.test.js.map +0 -1
  86. package/dist/esm/ExtensionPointInfo.test.js +0 -186
  87. package/dist/esm/ExtensionPointInfo.test.js.map +0 -1
  88. package/dist/esm/ExtensionsObservable.test.js +0 -346
  89. package/dist/esm/ExtensionsObservable.test.js.map +0 -1
  90. package/dist/esm/debug/useDebug.test.js +0 -46
  91. package/dist/esm/debug/useDebug.test.js.map +0 -1
  92. package/dist/esm/debug/useDiscovery.test.js +0 -46
  93. package/dist/esm/debug/useDiscovery.test.js.map +0 -1
  94. package/dist/esm/debug/useLogging.test.js +0 -46
  95. package/dist/esm/debug/useLogging.test.js.map +0 -1
  96. package/dist/esm/debug/useValidation.test.js +0 -46
  97. package/dist/esm/debug/useValidation.test.js.map +0 -1
  98. package/dist/esm/handlers/AsyncPanelHandler.test.js +0 -186
  99. package/dist/esm/handlers/AsyncPanelHandler.test.js.map +0 -1
  100. package/dist/esm/handlers/ButtonHandler.test.js +0 -37
  101. package/dist/esm/handlers/ButtonHandler.test.js.map +0 -1
  102. package/dist/esm/handlers/LinkHandler.test.js +0 -40
  103. package/dist/esm/handlers/LinkHandler.test.js.map +0 -1
  104. package/dist/esm/handlers/ModalHandler.test.js +0 -186
  105. package/dist/esm/handlers/ModalHandler.test.js.map +0 -1
  106. package/dist/esm/handlers/PanelHandler.test.js +0 -85
  107. package/dist/esm/handlers/PanelHandler.test.js.map +0 -1
  108. package/dist/esm/handlers/SectionHandler.test.js +0 -14
  109. package/dist/esm/handlers/SectionHandler.test.js.map +0 -1
  110. package/dist/esm/index.test.js +0 -7
  111. package/dist/esm/index.test.js.map +0 -1
  112. package/dist/esm/renderElementAsReact.test.js +0 -51
  113. package/dist/esm/renderElementAsReact.test.js.map +0 -1
  114. package/dist/esm/useExtensions.test.js +0 -644
  115. package/dist/esm/useExtensions.test.js.map +0 -1
  116. package/dist/types/ExtensionPoint.test.d.ts +0 -2
  117. package/dist/types/ExtensionPoint.test.d.ts.map +0 -1
  118. package/dist/types/ExtensionPointInfo.test.d.ts +0 -2
  119. package/dist/types/ExtensionPointInfo.test.d.ts.map +0 -1
  120. package/dist/types/ExtensionsObservable.test.d.ts +0 -2
  121. package/dist/types/ExtensionsObservable.test.d.ts.map +0 -1
  122. package/dist/types/debug/useDebug.test.d.ts +0 -2
  123. package/dist/types/debug/useDebug.test.d.ts.map +0 -1
  124. package/dist/types/debug/useDiscovery.test.d.ts +0 -2
  125. package/dist/types/debug/useDiscovery.test.d.ts.map +0 -1
  126. package/dist/types/debug/useLogging.test.d.ts +0 -2
  127. package/dist/types/debug/useLogging.test.d.ts.map +0 -1
  128. package/dist/types/debug/useValidation.test.d.ts +0 -2
  129. package/dist/types/debug/useValidation.test.d.ts.map +0 -1
  130. package/dist/types/handlers/AsyncPanelHandler.test.d.ts +0 -2
  131. package/dist/types/handlers/AsyncPanelHandler.test.d.ts.map +0 -1
  132. package/dist/types/handlers/ButtonHandler.test.d.ts +0 -2
  133. package/dist/types/handlers/ButtonHandler.test.d.ts.map +0 -1
  134. package/dist/types/handlers/LinkHandler.test.d.ts +0 -2
  135. package/dist/types/handlers/LinkHandler.test.d.ts.map +0 -1
  136. package/dist/types/handlers/ModalHandler.test.d.ts +0 -2
  137. package/dist/types/handlers/ModalHandler.test.d.ts.map +0 -1
  138. package/dist/types/handlers/PanelHandler.test.d.ts +0 -2
  139. package/dist/types/handlers/PanelHandler.test.d.ts.map +0 -1
  140. package/dist/types/handlers/SectionHandler.test.d.ts +0 -2
  141. package/dist/types/handlers/SectionHandler.test.d.ts.map +0 -1
  142. package/dist/types/index.test.d.ts +0 -1
  143. package/dist/types/index.test.d.ts.map +0 -1
  144. package/dist/types/renderElementAsReact.test.d.ts +0 -2
  145. package/dist/types/renderElementAsReact.test.d.ts.map +0 -1
  146. package/dist/types/useExtensions.test.d.ts +0 -2
  147. package/dist/types/useExtensions.test.d.ts.map +0 -1
@@ -1,346 +0,0 @@
1
- import { mocked } from 'ts-jest/utils';
2
- import registry from '@atlassian/clientside-extensions-registry';
3
- import * as debug from '@atlassian/clientside-extensions-debug';
4
- import { getExtensionPointSubscription, getValidatedExtensions } from './ExtensionsObservable';
5
- jest.mock('@atlassian/clientside-extensions-registry');
6
- debug.setLoggingEnabled(true);
7
- debug.setDebugEnabled(true);
8
- // avoid spamming the console with error/warn messages
9
- // eslint-disable-next-line no-underscore-dangle
10
- debug._deregisterDefaultLogger();
11
- function createMockLocationObserver() {
12
- let locationObserver;
13
- mocked(registry.getLocation).mockClear();
14
- mocked(registry.getLocation).mockImplementation(() => ({
15
- subscribe: (observer) => {
16
- locationObserver = observer;
17
- return {
18
- unsubscribe: () => { },
19
- };
20
- },
21
- }));
22
- return (payload) => locationObserver(payload);
23
- }
24
- const supportedExtension = {
25
- key: 'fake-1',
26
- location: 'fake-location',
27
- weight: 10,
28
- attributes: { label: 'a fake label' },
29
- attributesProvider: () => ({ type: 'button' }),
30
- };
31
- const unsupportedExtension = {
32
- key: 'fake-2',
33
- location: 'fake-location',
34
- weight: 10,
35
- attributes: { label: 'a fake label' },
36
- };
37
- const LOCATION = 'fake-location';
38
- describe('getExtensionPointSubscription', () => {
39
- const onDebugSpy = jest.fn();
40
- debug.observeLogger(onDebugSpy);
41
- let locationObserver;
42
- beforeEach(() => {
43
- onDebugSpy.mockClear();
44
- locationObserver = createMockLocationObserver();
45
- });
46
- it('should return an observable', () => {
47
- const observable = getExtensionPointSubscription(LOCATION, null);
48
- expect(observable.subscribe).toBeInstanceOf(Function);
49
- });
50
- it('should allow to subscribe to updates', () => {
51
- const observerSpy = jest.fn();
52
- getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
53
- locationObserver({ descriptors: [], loadingState: true });
54
- expect(observerSpy).toBeCalled();
55
- });
56
- it('should allow to unsubscribe from updates again', () => {
57
- const observerSpy = jest.fn();
58
- const { unsubscribe } = getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
59
- locationObserver({ descriptors: [], loadingState: true });
60
- unsubscribe();
61
- locationObserver({ descriptors: [], loadingState: false });
62
- expect(observerSpy).toBeCalledTimes(1);
63
- });
64
- it('should notify the observer of registered extensions', () => {
65
- const observerSpy = jest.fn();
66
- getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
67
- locationObserver({ descriptors: [supportedExtension], loadingState: false });
68
- expect(observerSpy).toBeCalled();
69
- expect(observerSpy.mock.calls[0][0]).toBeTruthy();
70
- const { descriptors, loadingState } = observerSpy.mock.calls[0][0].state;
71
- expect(descriptors.length).toBe(1);
72
- expect(loadingState).toBe(false);
73
- });
74
- it('should only provide descriptors to observer once loading is over', () => {
75
- const observerSpy = jest.fn();
76
- getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
77
- locationObserver({ descriptors: [], loadingState: true });
78
- locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: true });
79
- locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });
80
- expect(observerSpy).toBeCalledTimes(3);
81
- // first call
82
- const argFirst = observerSpy.mock.calls[0][0];
83
- const { descriptors: descriptorsFirst, loadingState: loadingFirst } = argFirst.state;
84
- expect(descriptorsFirst.length).toBe(0);
85
- expect(loadingFirst).toBe(true);
86
- // second call
87
- const argSecond = observerSpy.mock.calls[1][0];
88
- const { descriptors: descriptorsSecond, loadingState: loadingSecond } = argSecond.state;
89
- expect(descriptorsSecond.length).toBe(0);
90
- expect(loadingSecond).toBe(true);
91
- // third call
92
- const argThird = observerSpy.mock.calls[2][0];
93
- const { descriptors: descriptorsThird, loadingState: loadingThird } = argThird.state;
94
- expect(descriptorsThird.length).toBe(2);
95
- expect(loadingThird).toBe(false);
96
- expect(descriptorsThird[0].key).toBe(supportedExtension.key);
97
- expect(descriptorsThird[1].key).toBe(unsupportedExtension.key);
98
- });
99
- it('should provide registered extensions with the provided context', () => {
100
- const someContext = { foo: 'bar' };
101
- const attributeProviderSpy = jest.fn();
102
- getExtensionPointSubscription(LOCATION, someContext);
103
- locationObserver({
104
- descriptors: [
105
- {
106
- key: 'fake-1',
107
- location: LOCATION,
108
- weight: 10,
109
- attributes: { label: 'a fake label' },
110
- attributesProvider: attributeProviderSpy,
111
- },
112
- ],
113
- loadingState: false,
114
- });
115
- expect(attributeProviderSpy).toBeCalledTimes(1);
116
- expect(attributeProviderSpy.mock.calls[0][1]).toBe(someContext);
117
- });
118
- it('should update if a new extension is registered', () => {
119
- const observerSpy = jest.fn();
120
- getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
121
- locationObserver({ descriptors: [], loadingState: false });
122
- locationObserver({ descriptors: [supportedExtension], loadingState: false });
123
- locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });
124
- expect(observerSpy).toBeCalledTimes(3);
125
- // first call
126
- const argFirst = observerSpy.mock.calls[0][0];
127
- const { descriptors: descriptorsFirst } = argFirst.state;
128
- expect(descriptorsFirst.length).toBe(0);
129
- // second call
130
- const argSecond = observerSpy.mock.calls[1][0];
131
- const { descriptors: descriptorsSecond } = argSecond.state;
132
- expect(descriptorsSecond.length).toBe(1);
133
- // third call
134
- const argThird = observerSpy.mock.calls[2][0];
135
- const { descriptors: descriptorsThird } = argThird.state;
136
- expect(descriptorsThird.length).toBe(2);
137
- });
138
- it('should update if an extension updates its attributes', async () => {
139
- expect.assertions(5);
140
- const observerSpy = jest.fn();
141
- getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
142
- let apiReference;
143
- const selfUpdatingExtension = {
144
- key: 'updating-extension',
145
- location: LOCATION,
146
- weight: 230,
147
- attributes: { label: 'a fake label', type: 'button' },
148
- attributesProvider: (api) => {
149
- apiReference = api;
150
- return {};
151
- },
152
- };
153
- locationObserver({ descriptors: [supportedExtension, unsupportedExtension, selfUpdatingExtension], loadingState: false });
154
- expect(observerSpy).toBeCalled();
155
- observerSpy.mockClear();
156
- apiReference.updateAttributes({ foo: 'bar' });
157
- // wait for the update to go through which is a tick away
158
- await new Promise((resolve) => {
159
- setTimeout(() => {
160
- expect(observerSpy).toBeCalled();
161
- const { update } = observerSpy.mock.calls[0][0];
162
- expect(update.length).toBe(1);
163
- expect(update[0].key).toBe('updating-extension');
164
- expect(update[0].attributes.foo).toBe('bar');
165
- resolve();
166
- }, 50);
167
- });
168
- });
169
- it('should batch updates together', async () => {
170
- expect.assertions(8);
171
- const observerSpy = jest.fn();
172
- getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);
173
- let apiReference1;
174
- const selfUpdatingExtension1 = {
175
- key: 'updating-extension-1',
176
- location: LOCATION,
177
- weight: 230,
178
- attributes: { label: 'a fake label', type: 'button' },
179
- attributesProvider: (api) => {
180
- apiReference1 = api;
181
- return {};
182
- },
183
- };
184
- let apiReference2;
185
- const selfUpdatingExtension2 = {
186
- key: 'updating-extension-2',
187
- location: LOCATION,
188
- weight: 230,
189
- attributes: { label: 'a fake label', type: 'button' },
190
- attributesProvider: (api) => {
191
- apiReference2 = api;
192
- return {};
193
- },
194
- };
195
- locationObserver({ descriptors: [selfUpdatingExtension1, selfUpdatingExtension2], loadingState: false });
196
- observerSpy.mockClear();
197
- apiReference1.updateAttributes({ foo: 'bar' });
198
- apiReference2.updateAttributes({ foo: 'bar' });
199
- apiReference1.updateAttributes({ foo: 'foo of 1' });
200
- apiReference2.updateAttributes({ foo: 'foo of 2' });
201
- // wait for the update to go through which is a tick away
202
- await new Promise((resolve) => {
203
- setTimeout(() => {
204
- expect(observerSpy).toBeCalledTimes(1);
205
- const { update } = observerSpy.mock.calls[0][0];
206
- expect(update.length).toBe(2);
207
- expect(update[0].key).toBe('updating-extension-1');
208
- expect(update[0].attributes.foo).toBe('foo of 1');
209
- expect(update[0].attributes.foo).toBe('foo of 1');
210
- expect(update[1].key).toBe('updating-extension-2');
211
- expect(update[1].attributes.foo).toBe('foo of 2');
212
- expect(update[1].attributes.foo).toBe('foo of 2');
213
- resolve();
214
- }, 50);
215
- });
216
- });
217
- });
218
- describe('getValidatedExtensions', () => {
219
- const onDebugSpy = jest.fn();
220
- const context = { foo: 'bar' };
221
- debug.observeLogger(onDebugSpy);
222
- let locationObserver;
223
- let contextValidatorSpy;
224
- let attributeValidatorSpy;
225
- beforeEach(() => {
226
- onDebugSpy.mockClear();
227
- locationObserver = createMockLocationObserver();
228
- contextValidatorSpy = jest.fn().mockReturnValue({ errors: [], warnings: [] });
229
- attributeValidatorSpy = jest.fn().mockReturnValue({ errors: [], warnings: [] });
230
- });
231
- it('should not validate the context if no context is specified', () => {
232
- getValidatedExtensions(LOCATION, null, {
233
- contextValidator: contextValidatorSpy,
234
- attributeValidator: attributeValidatorSpy,
235
- });
236
- expect(contextValidatorSpy).not.toBeCalled();
237
- });
238
- it('should validate the context if a context is specified', () => {
239
- getValidatedExtensions(LOCATION, context, {
240
- contextValidator: contextValidatorSpy,
241
- attributeValidator: attributeValidatorSpy,
242
- });
243
- expect(contextValidatorSpy).toBeCalled();
244
- expect(contextValidatorSpy.mock.calls[0][0]).toBe(context);
245
- });
246
- it('should throw an error if the context validation fails', () => {
247
- expect(() => getValidatedExtensions(LOCATION, context, {
248
- contextValidator: contextValidatorSpy.mockReturnValue({
249
- errors: ['some error'],
250
- warnings: [],
251
- }),
252
- attributeValidator: attributeValidatorSpy,
253
- })).toThrow(`The context provided for extension-location "fake-location" does not match the schema`);
254
- });
255
- it('should not throw an error if the context validation has warnings', () => {
256
- expect(() => getValidatedExtensions(LOCATION, context, {
257
- contextValidator: contextValidatorSpy.mockReturnValue({
258
- errors: [],
259
- warnings: ['some warning'],
260
- }),
261
- attributeValidator: attributeValidatorSpy,
262
- })).not.toThrow();
263
- });
264
- it('should return an observable', () => {
265
- const observable = getValidatedExtensions(LOCATION, context, {
266
- contextValidator: contextValidatorSpy,
267
- attributeValidator: attributeValidatorSpy,
268
- });
269
- expect(observable.subscribe).toBeInstanceOf(Function);
270
- });
271
- it('should allow to subscribe to updates', () => {
272
- const observerSpy = jest.fn();
273
- getValidatedExtensions(LOCATION, context, {
274
- contextValidator: contextValidatorSpy,
275
- attributeValidator: attributeValidatorSpy,
276
- }).subscribe(observerSpy);
277
- locationObserver({ descriptors: [], loadingState: true });
278
- expect(observerSpy).toBeCalled();
279
- });
280
- it('should allow to unsubscribe from updates again', () => {
281
- const observerSpy = jest.fn();
282
- const { unsubscribe } = getValidatedExtensions(LOCATION, context, {
283
- contextValidator: contextValidatorSpy,
284
- attributeValidator: attributeValidatorSpy,
285
- }).subscribe(observerSpy);
286
- locationObserver({ descriptors: [], loadingState: true });
287
- locationObserver({ descriptors: [], loadingState: false });
288
- unsubscribe();
289
- locationObserver({ descriptors: [supportedExtension], loadingState: false });
290
- expect(observerSpy).toBeCalledTimes(2);
291
- });
292
- it('should call attributeValidatorSpy with extension attributes', () => {
293
- const observerSpy = jest.fn();
294
- getValidatedExtensions(LOCATION, context, {
295
- contextValidator: contextValidatorSpy,
296
- attributeValidator: attributeValidatorSpy,
297
- }).subscribe(observerSpy);
298
- locationObserver({ descriptors: [supportedExtension], loadingState: false });
299
- expect(attributeValidatorSpy).toBeCalledTimes(1);
300
- expect(attributeValidatorSpy.mock.calls[0][0]).toStrictEqual({
301
- ...supportedExtension.attributes,
302
- ...supportedExtension.attributesProvider({}, null),
303
- });
304
- });
305
- it('should declare all extensions as valid if validator always return "ok"', () => {
306
- const observerSpy = jest.fn();
307
- getValidatedExtensions(LOCATION, context, {
308
- contextValidator: contextValidatorSpy,
309
- attributeValidator: attributeValidatorSpy.mockReturnValue({ errors: [], warnings: [] }),
310
- }).subscribe(observerSpy);
311
- locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });
312
- expect(observerSpy).toBeCalledTimes(1);
313
- const [supported, unsupported] = observerSpy.mock.calls[0][0];
314
- expect(supported.length).toBe(2);
315
- expect(unsupported.length).toBe(0);
316
- });
317
- it('should move extensions into "unsupported" if validation fails', () => {
318
- const observerSpy = jest.fn();
319
- getValidatedExtensions(LOCATION, context, {
320
- contextValidator: contextValidatorSpy,
321
- attributeValidator: attributeValidatorSpy
322
- .mockReturnValueOnce({ errors: [], warnings: [] })
323
- .mockReturnValueOnce({ errors: ['some error'], warnings: [] }),
324
- }).subscribe(observerSpy);
325
- locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });
326
- expect(observerSpy).toBeCalledTimes(1);
327
- const [supported, unsupported] = observerSpy.mock.calls[0][0];
328
- expect(supported.length).toBe(1);
329
- expect(supported[0].key).toBe(supportedExtension.key);
330
- expect(unsupported.length).toBe(1);
331
- expect(unsupported[0].key).toBe(unsupportedExtension.key);
332
- });
333
- it('should declare all extensions as valid if validator has any warnings', () => {
334
- const observerSpy = jest.fn();
335
- getValidatedExtensions(LOCATION, context, {
336
- contextValidator: contextValidatorSpy,
337
- attributeValidator: attributeValidatorSpy.mockReturnValue({ errors: [], warnings: ['some warning'] }),
338
- }).subscribe(observerSpy);
339
- locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });
340
- expect(observerSpy).toBeCalledTimes(1);
341
- const [supported, unsupported] = observerSpy.mock.calls[0][0];
342
- expect(supported.length).toBe(2);
343
- expect(unsupported.length).toBe(0);
344
- });
345
- });
346
- //# sourceMappingURL=ExtensionsObservable.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExtensionsObservable.test.js","sourceRoot":"","sources":["../../lib/ExtensionsObservable.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,QAAQ,MAAM,2CAA2C,CAAC;AACjE,OAAO,KAAK,KAAK,MAAM,wCAAwC,CAAC;AAIhE,OAAO,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAG/F,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,SAAS,0BAA0B;IAC/B,IAAI,gBAAsC,CAAC;IAC3C,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,SAAS,EAAE,CAAC;IACzC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAC;QACnD,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACpB,gBAAgB,GAAG,QAAQ,CAAC;YAC5B,OAAO;gBACH,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;aACxB,CAAC;QACN,CAAC;KACJ,CAAC,CAAC,CAAC;IAEJ,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,kBAAkB,GAAwB;IAC5C,GAAG,EAAE,QAAQ;IACb,QAAQ,EAAE,eAAe;IACzB,MAAM,EAAE,EAAE;IACV,UAAU,EAAE,EAAE,KAAK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CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { mocked } from 'ts-jest/utils';\nimport registry from '@atlassian/clientside-extensions-registry';\nimport * as debug from '@atlassian/clientside-extensions-debug';\nimport type { ExtensionAPI, ExtensionDescriptor } from '@atlassian/clientside-extensions-registry';\n\nimport type { ExtensionPointUpdate, Options } from './types';\nimport { getExtensionPointSubscription, getValidatedExtensions } from './ExtensionsObservable';\nimport Mock = jest.Mock;\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\nfunction createMockLocationObserver(): MockLocationObserver {\n let locationObserver: MockLocationObserver;\n mocked(registry.getLocation).mockClear();\n mocked(registry.getLocation).mockImplementation(() => ({\n subscribe: (observer) => {\n locationObserver = observer;\n return {\n unsubscribe: () => {},\n };\n },\n }));\n\n return (payload) => locationObserver(payload);\n}\n\nconst supportedExtension: ExtensionDescriptor = {\n key: 'fake-1',\n location: 'fake-location',\n weight: 10,\n attributes: { label: 'a fake label' },\n attributesProvider: () => ({ 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 LOCATION = 'fake-location';\n\ndescribe('getExtensionPointSubscription', () => {\n const onDebugSpy = jest.fn();\n debug.observeLogger(onDebugSpy);\n let locationObserver: MockLocationObserver;\n\n beforeEach(() => {\n onDebugSpy.mockClear();\n locationObserver = createMockLocationObserver();\n });\n\n it('should return an observable', () => {\n const observable = getExtensionPointSubscription(LOCATION, null);\n\n expect(observable.subscribe).toBeInstanceOf(Function);\n });\n\n it('should allow to subscribe to updates', () => {\n const observerSpy = jest.fn();\n getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);\n locationObserver({ descriptors: [], loadingState: true });\n\n expect(observerSpy).toBeCalled();\n });\n\n it('should allow to unsubscribe from updates again', () => {\n const observerSpy = jest.fn();\n const { unsubscribe } = getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);\n locationObserver({ descriptors: [], loadingState: true });\n unsubscribe();\n locationObserver({ descriptors: [], loadingState: false });\n\n expect(observerSpy).toBeCalledTimes(1);\n });\n\n it('should notify the observer of registered extensions', () => {\n const observerSpy = jest.fn();\n getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);\n locationObserver({ descriptors: [supportedExtension], loadingState: false });\n\n expect(observerSpy).toBeCalled();\n expect(observerSpy.mock.calls[0][0]).toBeTruthy();\n const { descriptors, loadingState } = observerSpy.mock.calls[0][0].state;\n expect(descriptors.length).toBe(1);\n expect(loadingState).toBe(false);\n });\n\n it('should only provide descriptors to observer once loading is over', () => {\n const observerSpy = jest.fn();\n getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);\n\n locationObserver({ descriptors: [], loadingState: true });\n locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: true });\n locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });\n\n expect(observerSpy).toBeCalledTimes(3);\n\n // first call\n const argFirst = observerSpy.mock.calls[0][0] as ExtensionPointUpdate;\n const { descriptors: descriptorsFirst, loadingState: loadingFirst } = argFirst.state;\n expect(descriptorsFirst.length).toBe(0);\n expect(loadingFirst).toBe(true);\n\n // second call\n const argSecond = observerSpy.mock.calls[1][0] as ExtensionPointUpdate;\n const { descriptors: descriptorsSecond, loadingState: loadingSecond } = argSecond.state;\n expect(descriptorsSecond.length).toBe(0);\n expect(loadingSecond).toBe(true);\n\n // third call\n const argThird = observerSpy.mock.calls[2][0] as ExtensionPointUpdate;\n const { descriptors: descriptorsThird, loadingState: loadingThird } = argThird.state;\n expect(descriptorsThird.length).toBe(2);\n expect(loadingThird).toBe(false);\n expect(descriptorsThird[0].key).toBe(supportedExtension.key);\n expect(descriptorsThird[1].key).toBe(unsupportedExtension.key);\n });\n\n it('should provide registered extensions with the provided context', () => {\n const someContext = { foo: 'bar' };\n const attributeProviderSpy = jest.fn();\n getExtensionPointSubscription(LOCATION, someContext);\n\n locationObserver({\n descriptors: [\n {\n key: 'fake-1',\n location: LOCATION,\n weight: 10,\n attributes: { label: 'a fake label' },\n attributesProvider: attributeProviderSpy,\n },\n ],\n loadingState: false,\n });\n\n expect(attributeProviderSpy).toBeCalledTimes(1);\n expect(attributeProviderSpy.mock.calls[0][1]).toBe(someContext);\n });\n\n it('should update if a new extension is registered', () => {\n const observerSpy = jest.fn();\n getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);\n\n locationObserver({ descriptors: [], loadingState: false });\n locationObserver({ descriptors: [supportedExtension], loadingState: false });\n locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });\n\n expect(observerSpy).toBeCalledTimes(3);\n\n // first call\n const argFirst = observerSpy.mock.calls[0][0] as ExtensionPointUpdate;\n const { descriptors: descriptorsFirst } = argFirst.state;\n expect(descriptorsFirst.length).toBe(0);\n\n // second call\n const argSecond = observerSpy.mock.calls[1][0] as ExtensionPointUpdate;\n const { descriptors: descriptorsSecond } = argSecond.state;\n expect(descriptorsSecond.length).toBe(1);\n\n // third call\n const argThird = observerSpy.mock.calls[2][0] as ExtensionPointUpdate;\n const { descriptors: descriptorsThird } = argThird.state;\n expect(descriptorsThird.length).toBe(2);\n });\n\n it('should update if an extension updates its attributes', async () => {\n expect.assertions(5);\n const observerSpy = jest.fn();\n getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);\n\n let apiReference: ExtensionAPI | undefined;\n\n const selfUpdatingExtension = {\n key: 'updating-extension',\n location: LOCATION,\n weight: 230,\n attributes: { label: 'a fake label', type: 'button' },\n attributesProvider: (api: ExtensionAPI) => {\n apiReference = api;\n return {};\n },\n };\n\n locationObserver({ descriptors: [supportedExtension, unsupportedExtension, selfUpdatingExtension], loadingState: false });\n\n expect(observerSpy).toBeCalled();\n observerSpy.mockClear();\n\n (apiReference as ExtensionAPI).updateAttributes({ foo: 'bar' });\n\n // wait for the update to go through which is a tick away\n await new Promise((resolve) => {\n setTimeout(() => {\n expect(observerSpy).toBeCalled();\n const { update } = observerSpy.mock.calls[0][0];\n expect(update.length).toBe(1);\n expect(update[0].key).toBe('updating-extension');\n expect(update[0].attributes.foo).toBe('bar');\n resolve();\n }, 50);\n });\n });\n\n it('should batch updates together', async () => {\n expect.assertions(8);\n const observerSpy = jest.fn();\n getExtensionPointSubscription(LOCATION, null).subscribe(observerSpy);\n\n let apiReference1: ExtensionAPI | undefined;\n const selfUpdatingExtension1 = {\n key: 'updating-extension-1',\n location: LOCATION,\n weight: 230,\n attributes: { label: 'a fake label', type: 'button' },\n attributesProvider: (api: ExtensionAPI) => {\n apiReference1 = api;\n return {};\n },\n };\n\n let apiReference2: ExtensionAPI | undefined;\n const selfUpdatingExtension2 = {\n key: 'updating-extension-2',\n location: LOCATION,\n weight: 230,\n attributes: { label: 'a fake label', type: 'button' },\n attributesProvider: (api: ExtensionAPI) => {\n apiReference2 = api;\n return {};\n },\n };\n\n locationObserver({ descriptors: [selfUpdatingExtension1, selfUpdatingExtension2], loadingState: false });\n\n observerSpy.mockClear();\n\n (apiReference1 as ExtensionAPI).updateAttributes({ foo: 'bar' });\n (apiReference2 as ExtensionAPI).updateAttributes({ foo: 'bar' });\n\n (apiReference1 as ExtensionAPI).updateAttributes({ foo: 'foo of 1' });\n (apiReference2 as ExtensionAPI).updateAttributes({ foo: 'foo of 2' });\n\n // wait for the update to go through which is a tick away\n await new Promise((resolve) => {\n setTimeout(() => {\n expect(observerSpy).toBeCalledTimes(1);\n const { update } = observerSpy.mock.calls[0][0];\n expect(update.length).toBe(2);\n\n expect(update[0].key).toBe('updating-extension-1');\n expect(update[0].attributes.foo).toBe('foo of 1');\n expect(update[0].attributes.foo).toBe('foo of 1');\n\n expect(update[1].key).toBe('updating-extension-2');\n expect(update[1].attributes.foo).toBe('foo of 2');\n expect(update[1].attributes.foo).toBe('foo of 2');\n resolve();\n }, 50);\n });\n });\n});\n\ndescribe('getValidatedExtensions', () => {\n const onDebugSpy = jest.fn();\n const context = { foo: 'bar' };\n\n debug.observeLogger(onDebugSpy);\n\n let locationObserver: MockLocationObserver;\n let contextValidatorSpy: Mock;\n let attributeValidatorSpy: Mock;\n\n beforeEach(() => {\n onDebugSpy.mockClear();\n locationObserver = createMockLocationObserver();\n contextValidatorSpy = jest.fn().mockReturnValue({ errors: [], warnings: [] });\n attributeValidatorSpy = jest.fn().mockReturnValue({ errors: [], warnings: [] });\n });\n\n it('should not validate the context if no context is specified', () => {\n getValidatedExtensions(LOCATION, null, {\n contextValidator: contextValidatorSpy,\n attributeValidator: attributeValidatorSpy,\n } as Options);\n\n expect(contextValidatorSpy).not.toBeCalled();\n });\n\n it('should validate the context if a context is specified', () => {\n getValidatedExtensions(LOCATION, context, {\n contextValidator: contextValidatorSpy,\n attributeValidator: attributeValidatorSpy,\n });\n\n expect(contextValidatorSpy).toBeCalled();\n expect(contextValidatorSpy.mock.calls[0][0]).toBe(context);\n });\n\n it('should throw an error if the context validation fails', () => {\n expect(() =>\n getValidatedExtensions(LOCATION, context, {\n contextValidator: contextValidatorSpy.mockReturnValue({\n errors: ['some error'],\n warnings: [],\n }),\n attributeValidator: attributeValidatorSpy,\n }),\n ).toThrow(`The context provided for extension-location \"fake-location\" does not match the schema`);\n });\n\n it('should not throw an error if the context validation has warnings', () => {\n expect(() =>\n getValidatedExtensions(LOCATION, context, {\n contextValidator: contextValidatorSpy.mockReturnValue({\n errors: [],\n warnings: ['some warning'],\n }),\n attributeValidator: attributeValidatorSpy,\n }),\n ).not.toThrow();\n });\n\n it('should return an observable', () => {\n const observable = getValidatedExtensions(LOCATION, context, {\n contextValidator: contextValidatorSpy,\n attributeValidator: attributeValidatorSpy,\n });\n\n expect(observable.subscribe).toBeInstanceOf(Function);\n });\n\n it('should allow to subscribe to updates', () => {\n const observerSpy = jest.fn();\n getValidatedExtensions(LOCATION, context, {\n contextValidator: contextValidatorSpy,\n attributeValidator: attributeValidatorSpy,\n }).subscribe(observerSpy);\n locationObserver({ descriptors: [], loadingState: true });\n\n expect(observerSpy).toBeCalled();\n });\n\n it('should allow to unsubscribe from updates again', () => {\n const observerSpy = jest.fn();\n const { unsubscribe } = getValidatedExtensions(LOCATION, context, {\n contextValidator: contextValidatorSpy,\n attributeValidator: attributeValidatorSpy,\n }).subscribe(observerSpy);\n locationObserver({ descriptors: [], loadingState: true });\n locationObserver({ descriptors: [], loadingState: false });\n unsubscribe();\n locationObserver({ descriptors: [supportedExtension], loadingState: false });\n\n expect(observerSpy).toBeCalledTimes(2);\n });\n\n it('should call attributeValidatorSpy with extension attributes', () => {\n const observerSpy = jest.fn();\n getValidatedExtensions(LOCATION, context, {\n contextValidator: contextValidatorSpy,\n attributeValidator: attributeValidatorSpy,\n }).subscribe(observerSpy);\n locationObserver({ descriptors: [supportedExtension], loadingState: false });\n\n expect(attributeValidatorSpy).toBeCalledTimes(1);\n expect(attributeValidatorSpy.mock.calls[0][0]).toStrictEqual({\n ...supportedExtension.attributes,\n ...supportedExtension.attributesProvider!({} as ExtensionAPI, null),\n });\n });\n\n it('should declare all extensions as valid if validator always return \"ok\"', () => {\n const observerSpy = jest.fn();\n getValidatedExtensions(LOCATION, context, {\n contextValidator: contextValidatorSpy,\n attributeValidator: attributeValidatorSpy.mockReturnValue({ errors: [], warnings: [] }),\n }).subscribe(observerSpy);\n locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });\n\n expect(observerSpy).toBeCalledTimes(1);\n const [supported, unsupported] = observerSpy.mock.calls[0][0];\n expect(supported.length).toBe(2);\n expect(unsupported.length).toBe(0);\n });\n\n it('should move extensions into \"unsupported\" if validation fails', () => {\n const observerSpy = jest.fn();\n getValidatedExtensions(LOCATION, context, {\n contextValidator: contextValidatorSpy,\n attributeValidator: attributeValidatorSpy\n .mockReturnValueOnce({ errors: [], warnings: [] })\n .mockReturnValueOnce({ errors: ['some error'], warnings: [] }),\n }).subscribe(observerSpy);\n locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });\n\n expect(observerSpy).toBeCalledTimes(1);\n\n const [supported, unsupported] = observerSpy.mock.calls[0][0];\n expect(supported.length).toBe(1);\n expect(supported[0].key).toBe(supportedExtension.key);\n\n expect(unsupported.length).toBe(1);\n expect(unsupported[0].key).toBe(unsupportedExtension.key);\n });\n\n it('should declare all extensions as valid if validator has any warnings', () => {\n const observerSpy = jest.fn();\n getValidatedExtensions(LOCATION, context, {\n contextValidator: contextValidatorSpy,\n attributeValidator: attributeValidatorSpy.mockReturnValue({ errors: [], warnings: ['some warning'] }),\n }).subscribe(observerSpy);\n locationObserver({ descriptors: [supportedExtension, unsupportedExtension], loadingState: false });\n\n expect(observerSpy).toBeCalledTimes(1);\n const [supported, unsupported] = observerSpy.mock.calls[0][0];\n expect(supported.length).toBe(2);\n expect(unsupported.length).toBe(0);\n });\n});\n"]}
@@ -1,46 +0,0 @@
1
- import { mocked } from 'ts-jest/utils';
2
- import { act, renderHook } from '@testing-library/react-hooks';
3
- import { isDebugEnabled, LogLevel, observeStateChange } from '@atlassian/clientside-extensions-debug';
4
- import useDebug from './useDebug';
5
- jest.mock('@atlassian/clientside-extensions-debug');
6
- describe('useDebug hook', () => {
7
- beforeEach(() => {
8
- mocked(isDebugEnabled).mockClear();
9
- mocked(observeStateChange).mockClear();
10
- });
11
- it('should return the current state of the debug state', () => {
12
- const INITIAL_VALUE = false;
13
- mocked(isDebugEnabled).mockReturnValueOnce(INITIAL_VALUE);
14
- mocked(observeStateChange).mockReturnValueOnce({ unsubscribe() { } });
15
- const { result } = renderHook(() => useDebug());
16
- const [debugValue] = result.current;
17
- expect(debugValue).toBe(INITIAL_VALUE);
18
- });
19
- it('should react to changes to the discover debug setting', () => {
20
- const INITIAL_VALUE = true;
21
- const CHANGED_BOOLEAN_VALUE = false;
22
- let updateCallback;
23
- mocked(isDebugEnabled).mockReturnValueOnce(INITIAL_VALUE);
24
- mocked(observeStateChange).mockImplementation((expectedCallback) => {
25
- updateCallback = expectedCallback;
26
- return {
27
- unsubscribe() { },
28
- };
29
- });
30
- const { result } = renderHook(() => useDebug());
31
- let [debugValue] = result.current;
32
- expect(debugValue).toBe(INITIAL_VALUE);
33
- act(() => {
34
- updateCallback({
35
- discovery: CHANGED_BOOLEAN_VALUE,
36
- debug: CHANGED_BOOLEAN_VALUE,
37
- logging: CHANGED_BOOLEAN_VALUE,
38
- validation: CHANGED_BOOLEAN_VALUE,
39
- logLevel: LogLevel.warn,
40
- });
41
- });
42
- [debugValue] = result.current;
43
- expect(debugValue).toBe(CHANGED_BOOLEAN_VALUE);
44
- });
45
- });
46
- //# sourceMappingURL=useDebug.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDebug.test.js","sourceRoot":"","sources":["../../../lib/debug/useDebug.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AACtG,OAAO,QAAQ,MAAM,YAAY,CAAC;AAElC,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;AAEpD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC3B,UAAU,CAAC,GAAG,EAAE;QACZ,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,EAAE,CAAC;QACnC,MAAM,CAAC,kBAAkB,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC1D,MAAM,aAAa,GAAG,KAAK,CAAC;QAC5B,MAAM,CAAC,cAAc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AAC,CAAC,CAAC;QAEH,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC;QAE9B,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { mocked } from 'ts-jest/utils';\nimport { act, renderHook } from '@testing-library/react-hooks';\nimport { isDebugEnabled, LogLevel, observeStateChange } from '@atlassian/clientside-extensions-debug';\nimport useDebug from './useDebug';\n\njest.mock('@atlassian/clientside-extensions-debug');\n\ndescribe('useDebug hook', () => {\n beforeEach(() => {\n mocked(isDebugEnabled).mockClear();\n mocked(observeStateChange).mockClear();\n });\n\n it('should return the current state of the debug state', () => {\n const INITIAL_VALUE = false;\n mocked(isDebugEnabled).mockReturnValueOnce(INITIAL_VALUE);\n mocked(observeStateChange).mockReturnValueOnce({ unsubscribe() {} });\n\n const { result } = renderHook(() => useDebug());\n const [debugValue] = result.current;\n\n expect(debugValue).toBe(INITIAL_VALUE);\n });\n\n it('should react to changes to the discover debug setting', () => {\n const INITIAL_VALUE = true;\n const CHANGED_BOOLEAN_VALUE = false;\n\n let updateCallback: Parameters<typeof observeStateChange>[0];\n mocked(isDebugEnabled).mockReturnValueOnce(INITIAL_VALUE);\n mocked(observeStateChange).mockImplementation((expectedCallback) => {\n updateCallback = expectedCallback;\n return {\n unsubscribe() {},\n };\n });\n\n const { result } = renderHook(() => useDebug());\n let [debugValue] = result.current;\n\n expect(debugValue).toBe(INITIAL_VALUE);\n\n act(() => {\n updateCallback({\n discovery: CHANGED_BOOLEAN_VALUE,\n debug: CHANGED_BOOLEAN_VALUE,\n logging: CHANGED_BOOLEAN_VALUE,\n validation: CHANGED_BOOLEAN_VALUE,\n logLevel: LogLevel.warn,\n });\n });\n\n [debugValue] = result.current;\n\n expect(debugValue).toBe(CHANGED_BOOLEAN_VALUE);\n });\n});\n"]}
@@ -1,46 +0,0 @@
1
- import { mocked } from 'ts-jest/utils';
2
- import { act, renderHook } from '@testing-library/react-hooks';
3
- import { isDiscoveryEnabled, LogLevel, observeStateChange } from '@atlassian/clientside-extensions-debug';
4
- import useDiscovery from './useDiscovery';
5
- jest.mock('@atlassian/clientside-extensions-debug');
6
- describe('useDiscovery hook', () => {
7
- beforeEach(() => {
8
- mocked(isDiscoveryEnabled).mockClear();
9
- mocked(observeStateChange).mockClear();
10
- });
11
- it('should return the current state of the discover debug setting', () => {
12
- const INITIAL_VALUE = false;
13
- mocked(isDiscoveryEnabled).mockReturnValueOnce(INITIAL_VALUE);
14
- mocked(observeStateChange).mockReturnValueOnce({ unsubscribe() { } });
15
- const { result } = renderHook(() => useDiscovery());
16
- const [discoveryValue] = result.current;
17
- expect(discoveryValue).toBe(INITIAL_VALUE);
18
- });
19
- it('should react to changes to the discover debug setting', () => {
20
- const INITIAL_VALUE = true;
21
- const CHANGED_BOOLEAN_VALUE = false;
22
- let updateCallback;
23
- mocked(isDiscoveryEnabled).mockReturnValueOnce(INITIAL_VALUE);
24
- mocked(observeStateChange).mockImplementation((expectedCallback) => {
25
- updateCallback = expectedCallback;
26
- return {
27
- unsubscribe() { },
28
- };
29
- });
30
- const { result } = renderHook(() => useDiscovery());
31
- let [discoveryValue] = result.current;
32
- expect(discoveryValue).toBe(INITIAL_VALUE);
33
- act(() => {
34
- updateCallback({
35
- discovery: CHANGED_BOOLEAN_VALUE,
36
- debug: CHANGED_BOOLEAN_VALUE,
37
- logging: CHANGED_BOOLEAN_VALUE,
38
- validation: CHANGED_BOOLEAN_VALUE,
39
- logLevel: LogLevel.warn,
40
- });
41
- });
42
- [discoveryValue] = result.current;
43
- expect(discoveryValue).toBe(CHANGED_BOOLEAN_VALUE);
44
- });
45
- });
46
- //# sourceMappingURL=useDiscovery.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDiscovery.test.js","sourceRoot":"","sources":["../../../lib/debug/useDiscovery.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EA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,CAAC,CAAC,gBAAgB,EAAE,EAAE;YAC/D,cAAc,GAAG,gBAAgB,CAAC;YAClC,OAAO;gBACH,WAAW,KAAI,CAAC;aACnB,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC;QAEtC,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAE3C,GAAG,CAAC,GAAG,EAAE;YACL,cAAc,CAAC;gBACX,SAAS,EAAE,qBAAqB;gBAChC,KAAK,EAAE,qBAAqB;gBAC5B,OAAO,EAAE,qBAAqB;gBAC9B,UAAU,EAAE,qBAAqB;gBACjC,QAAQ,EAAE,QAAQ,CAAC,IAAI;aAC1B,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC;QAElC,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { mocked } from 'ts-jest/utils';\nimport { act, renderHook } from '@testing-library/react-hooks';\nimport { isDiscoveryEnabled, LogLevel, observeStateChange } from '@atlassian/clientside-extensions-debug';\nimport useDiscovery from './useDiscovery';\n\njest.mock('@atlassian/clientside-extensions-debug');\n\ndescribe('useDiscovery hook', () => {\n beforeEach(() => {\n mocked(isDiscoveryEnabled).mockClear();\n mocked(observeStateChange).mockClear();\n });\n\n it('should return the current state of the discover debug setting', () => {\n const INITIAL_VALUE = false;\n mocked(isDiscoveryEnabled).mockReturnValueOnce(INITIAL_VALUE);\n mocked(observeStateChange).mockReturnValueOnce({ unsubscribe() {} });\n\n const { result } = renderHook(() => useDiscovery());\n const [discoveryValue] = result.current;\n\n expect(discoveryValue).toBe(INITIAL_VALUE);\n });\n\n it('should react to changes to the discover debug setting', () => {\n const INITIAL_VALUE = true;\n const CHANGED_BOOLEAN_VALUE = false;\n\n let updateCallback: Parameters<typeof observeStateChange>[0];\n mocked(isDiscoveryEnabled).mockReturnValueOnce(INITIAL_VALUE);\n mocked(observeStateChange).mockImplementation((expectedCallback) => {\n updateCallback = expectedCallback;\n return {\n unsubscribe() {},\n };\n });\n\n const { result } = renderHook(() => useDiscovery());\n let [discoveryValue] = result.current;\n\n expect(discoveryValue).toBe(INITIAL_VALUE);\n\n act(() => {\n updateCallback({\n discovery: CHANGED_BOOLEAN_VALUE,\n debug: CHANGED_BOOLEAN_VALUE,\n logging: CHANGED_BOOLEAN_VALUE,\n validation: CHANGED_BOOLEAN_VALUE,\n logLevel: LogLevel.warn,\n });\n });\n\n [discoveryValue] = result.current;\n\n expect(discoveryValue).toBe(CHANGED_BOOLEAN_VALUE);\n });\n});\n"]}
@@ -1,46 +0,0 @@
1
- import { mocked } from 'ts-jest/utils';
2
- import { act, renderHook } from '@testing-library/react-hooks';
3
- import { isLoggingEnabled, LogLevel, observeStateChange } from '@atlassian/clientside-extensions-debug';
4
- import useLogging from './useLogging';
5
- jest.mock('@atlassian/clientside-extensions-debug');
6
- describe('useLogging hook', () => {
7
- beforeEach(() => {
8
- mocked(isLoggingEnabled).mockClear();
9
- mocked(observeStateChange).mockClear();
10
- });
11
- it('should return the current state of the logging debug setting', () => {
12
- const INITIAL_VALUE = false;
13
- mocked(isLoggingEnabled).mockReturnValueOnce(INITIAL_VALUE);
14
- mocked(observeStateChange).mockReturnValueOnce({ unsubscribe() { } });
15
- const { result } = renderHook(() => useLogging());
16
- const [loggingValue] = result.current;
17
- expect(loggingValue).toBe(INITIAL_VALUE);
18
- });
19
- it('should react to changes to the logging debug setting', () => {
20
- const INITIAL_VALUE = true;
21
- const CHANGED_BOOLEAN_VALUE = false;
22
- let updateCallback;
23
- mocked(isLoggingEnabled).mockReturnValueOnce(INITIAL_VALUE);
24
- mocked(observeStateChange).mockImplementation((expectedCallback) => {
25
- updateCallback = expectedCallback;
26
- return {
27
- unsubscribe() { },
28
- };
29
- });
30
- const { result } = renderHook(() => useLogging());
31
- let [loggingValue] = result.current;
32
- expect(loggingValue).toBe(INITIAL_VALUE);
33
- act(() => {
34
- updateCallback({
35
- discovery: CHANGED_BOOLEAN_VALUE,
36
- debug: CHANGED_BOOLEAN_VALUE,
37
- logging: CHANGED_BOOLEAN_VALUE,
38
- validation: CHANGED_BOOLEAN_VALUE,
39
- logLevel: LogLevel.warn,
40
- });
41
- });
42
- [loggingValue] = result.current;
43
- expect(loggingValue).toBe(CHANGED_BOOLEAN_VALUE);
44
- });
45
- });
46
- //# sourceMappingURL=useLogging.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLogging.test.js","sourceRoot":"","sources":["../../../lib/debug/useLogging.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AACxG,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;AAEpD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,UAAU,CAAC,GAAG,EAAE;QACZ,MAAM,CAAC,gBAAgB,CAAC,CAAC,SAAS,EAAE,CAAC;QACrC,MAAM,CAAC,kBAAkB,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;QACpE,MAAM,aAAa,GAAG,KAAK,CAAC;QAC5B,MAAM,CAAC,gBAAgB,CAAC,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;QAC5D,MAAM,CAAC,k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CAAC;QAEhC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { mocked } from 'ts-jest/utils';\nimport { act, renderHook } from '@testing-library/react-hooks';\nimport { isLoggingEnabled, LogLevel, observeStateChange } from '@atlassian/clientside-extensions-debug';\nimport useLogging from './useLogging';\n\njest.mock('@atlassian/clientside-extensions-debug');\n\ndescribe('useLogging hook', () => {\n beforeEach(() => {\n mocked(isLoggingEnabled).mockClear();\n mocked(observeStateChange).mockClear();\n });\n\n it('should return the current state of the logging debug setting', () => {\n const INITIAL_VALUE = false;\n mocked(isLoggingEnabled).mockReturnValueOnce(INITIAL_VALUE);\n mocked(observeStateChange).mockReturnValueOnce({ unsubscribe() {} });\n\n const { result } = renderHook(() => useLogging());\n const [loggingValue] = result.current;\n\n expect(loggingValue).toBe(INITIAL_VALUE);\n });\n\n it('should react to changes to the logging debug setting', () => {\n const INITIAL_VALUE = true;\n const CHANGED_BOOLEAN_VALUE = false;\n\n let updateCallback: Parameters<typeof observeStateChange>[0];\n mocked(isLoggingEnabled).mockReturnValueOnce(INITIAL_VALUE);\n mocked(observeStateChange).mockImplementation((expectedCallback) => {\n updateCallback = expectedCallback;\n return {\n unsubscribe() {},\n };\n });\n\n const { result } = renderHook(() => useLogging());\n let [loggingValue] = result.current;\n\n expect(loggingValue).toBe(INITIAL_VALUE);\n\n act(() => {\n updateCallback({\n discovery: CHANGED_BOOLEAN_VALUE,\n debug: CHANGED_BOOLEAN_VALUE,\n logging: CHANGED_BOOLEAN_VALUE,\n validation: CHANGED_BOOLEAN_VALUE,\n logLevel: LogLevel.warn,\n });\n });\n\n [loggingValue] = result.current;\n\n expect(loggingValue).toBe(CHANGED_BOOLEAN_VALUE);\n });\n});\n"]}
@@ -1,46 +0,0 @@
1
- import { mocked } from 'ts-jest/utils';
2
- import { act, renderHook } from '@testing-library/react-hooks';
3
- import { isValidationEnabled, LogLevel, observeStateChange } from '@atlassian/clientside-extensions-debug';
4
- import useValidation from './useValidation';
5
- jest.mock('@atlassian/clientside-extensions-debug');
6
- describe('useValidation hook', () => {
7
- beforeEach(() => {
8
- mocked(isValidationEnabled).mockClear();
9
- mocked(observeStateChange).mockClear();
10
- });
11
- it('should return the current state of the validation debug setting', () => {
12
- const INITIAL_VALUE = false;
13
- mocked(isValidationEnabled).mockReturnValueOnce(INITIAL_VALUE);
14
- mocked(observeStateChange).mockReturnValueOnce({ unsubscribe() { } });
15
- const { result } = renderHook(() => useValidation());
16
- const [validationValue] = result.current;
17
- expect(validationValue).toBe(INITIAL_VALUE);
18
- });
19
- it('should react to changes to the validation debug setting', () => {
20
- const INITIAL_VALUE = true;
21
- const CHANGED_BOOLEAN_VALUE = false;
22
- let updateCallback;
23
- mocked(isValidationEnabled).mockReturnValueOnce(INITIAL_VALUE);
24
- mocked(observeStateChange).mockImplementation((expectedCallback) => {
25
- updateCallback = expectedCallback;
26
- return {
27
- unsubscribe() { },
28
- };
29
- });
30
- const { result } = renderHook(() => useValidation());
31
- let [validationValue] = result.current;
32
- expect(validationValue).toBe(INITIAL_VALUE);
33
- act(() => {
34
- updateCallback({
35
- discovery: CHANGED_BOOLEAN_VALUE,
36
- debug: CHANGED_BOOLEAN_VALUE,
37
- logging: CHANGED_BOOLEAN_VALUE,
38
- validation: CHANGED_BOOLEAN_VALUE,
39
- logLevel: LogLevel.debug,
40
- });
41
- });
42
- [validationValue] = result.current;
43
- expect(validationValue).toBe(CHANGED_BOOLEAN_VALUE);
44
- });
45
- });
46
- //# sourceMappingURL=useValidation.test.js.map