@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 +0,0 @@
1
- {"version":3,"file":"useValidation.test.js","sourceRoot":"","sources":["../../../lib/debug/useValidation.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,mBAAmB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC3G,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;AAEpD,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAChC,UAAU,CAAC,GAAG,EAAE;QACZ,MAAM,CAAC,mBAAmB,CAAC,CAAC,SAAS,EAAE,CAAC;QACxC,MAAM,CAAC,kBAAkB,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iEAAiE,EAAE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E,qBAAqB;gBACjC,QAAQ,EAAE,QAAQ,CAAC,KAAK;aAC3B,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC;QAEnC,MAAM,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { mocked } from 'ts-jest/utils';\nimport { act, renderHook } from '@testing-library/react-hooks';\nimport { isValidationEnabled, LogLevel, observeStateChange } from '@atlassian/clientside-extensions-debug';\nimport useValidation from './useValidation';\n\njest.mock('@atlassian/clientside-extensions-debug');\n\ndescribe('useValidation hook', () => {\n beforeEach(() => {\n mocked(isValidationEnabled).mockClear();\n mocked(observeStateChange).mockClear();\n });\n\n it('should return the current state of the validation debug setting', () => {\n const INITIAL_VALUE = false;\n mocked(isValidationEnabled).mockReturnValueOnce(INITIAL_VALUE);\n mocked(observeStateChange).mockReturnValueOnce({ unsubscribe() {} });\n\n const { result } = renderHook(() => useValidation());\n const [validationValue] = result.current;\n\n expect(validationValue).toBe(INITIAL_VALUE);\n });\n\n it('should react to changes to the validation debug setting', () => {\n const INITIAL_VALUE = true;\n const CHANGED_BOOLEAN_VALUE = false;\n\n let updateCallback: Parameters<typeof observeStateChange>[0];\n mocked(isValidationEnabled).mockReturnValueOnce(INITIAL_VALUE);\n mocked(observeStateChange).mockImplementation((expectedCallback) => {\n updateCallback = expectedCallback;\n return {\n unsubscribe() {},\n };\n });\n\n const { result } = renderHook(() => useValidation());\n let [validationValue] = result.current;\n\n expect(validationValue).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.debug,\n });\n });\n\n [validationValue] = result.current;\n\n expect(validationValue).toBe(CHANGED_BOOLEAN_VALUE);\n });\n});\n"]}
@@ -1,186 +0,0 @@
1
- /* eslint-disable react/jsx-props-no-spreading */
2
- import * as React from 'react';
3
- import { render, waitForElementToBeRemoved } from '@testing-library/react';
4
- import * as debug from '@atlassian/clientside-extensions-debug';
5
- import { AsyncPanelHandler } from './AsyncPanelHandler';
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
- const onMountCallbackSpy = jest.fn();
12
- const onUnmountCallbackSpy = jest.fn();
13
- const moduleSpy = jest.fn();
14
- // onAction method of an Extension
15
- const createFakeRenderProvider = () => () =>
16
- // fake async module
17
- Promise.resolve({
18
- __esModule: true,
19
- default: moduleSpy,
20
- });
21
- const LOCATION = 'test-location';
22
- const EXTENSION_KEY = 'test-extension';
23
- const TestComponent = (props) => {
24
- return React.createElement(AsyncPanelHandler, Object.assign({}, props));
25
- };
26
- TestComponent.defaultProps = {
27
- renderProvider: createFakeRenderProvider(),
28
- fallback: React.createElement("p", { "data-testid": "loading" }, "loading"),
29
- location: LOCATION,
30
- extensionKey: EXTENSION_KEY,
31
- };
32
- const getFirstCallArguments = (onDebugSpy) => onDebugSpy.mock.calls[0][0];
33
- describe('AsyncPanelHandler', () => {
34
- const onDebugSpy = jest.fn();
35
- debug.observeLogger(onDebugSpy);
36
- beforeEach(() => {
37
- onMountCallbackSpy.mockReset();
38
- onUnmountCallbackSpy.mockReset();
39
- moduleSpy.mockReset();
40
- onDebugSpy.mockClear();
41
- moduleSpy.mockImplementation((panelAPI /* context, */ /* data */) => {
42
- panelAPI.onMount(onMountCallbackSpy);
43
- panelAPI.onUnmount(onUnmountCallbackSpy);
44
- });
45
- });
46
- it('should load and render the panel content asynchronously', async () => {
47
- const CUSTOM_CONTENT = `custom content`;
48
- onMountCallbackSpy.mockImplementationOnce((container) => {
49
- container.innerHTML = CUSTOM_CONTENT;
50
- });
51
- const { getByText, findByText, queryByTestId } = render(React.createElement(TestComponent, null));
52
- expect(queryByTestId('loading')).toBeTruthy();
53
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(0);
54
- // wait for element to be on the screen
55
- await findByText(CUSTOM_CONTENT);
56
- expect(getByText(CUSTOM_CONTENT)).toBeTruthy();
57
- expect(queryByTestId('loading')).toBeFalsy();
58
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
59
- });
60
- it('should provide an onMount and onUnmount API', async () => {
61
- const CUSTOM_CONTENT_1 = `custom content 1`;
62
- const CUSTOM_CONTENT_2 = `custom content 2`;
63
- const firstRenderProvider = createFakeRenderProvider();
64
- const secondRenderProvider = createFakeRenderProvider();
65
- onMountCallbackSpy
66
- .mockImplementationOnce((container) => {
67
- container.innerHTML = CUSTOM_CONTENT_1;
68
- })
69
- .mockImplementationOnce((container) => {
70
- container.innerHTML = CUSTOM_CONTENT_2;
71
- });
72
- const { rerender, findByText, queryByTestId, queryByText } = render(React.createElement(TestComponent, { renderProvider: firstRenderProvider }));
73
- expect(queryByTestId('loading')).toBeTruthy();
74
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(0);
75
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
76
- // wait for element to be on the screen
77
- await findByText(CUSTOM_CONTENT_1);
78
- expect(queryByText(CUSTOM_CONTENT_1)).toBeTruthy();
79
- expect(queryByTestId('loading')).toBeFalsy();
80
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
81
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
82
- rerender(React.createElement(TestComponent, { renderProvider: secondRenderProvider }));
83
- // wait for element to be on the screen
84
- await findByText(CUSTOM_CONTENT_2);
85
- expect(queryByText(CUSTOM_CONTENT_2)).toBeTruthy();
86
- expect(queryByText(CUSTOM_CONTENT_1)).toBeFalsy();
87
- expect(queryByTestId('loading')).toBeFalsy();
88
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(2);
89
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);
90
- });
91
- it('should catch the error if the async module has a wrong shape', async () => {
92
- const expectedError = {
93
- level: debug.LogLevel.error,
94
- message: `The provided dynamic import of extension "${EXTENSION_KEY}" at location "${LOCATION}" does not look like a module that can be asynchronously loaded.`,
95
- components: ['AsyncPanelHandler'],
96
- meta: {
97
- location: LOCATION,
98
- extension: EXTENSION_KEY,
99
- },
100
- };
101
- expect(onDebugSpy).toHaveBeenCalledTimes(0);
102
- // @ts-expect-error - ignoring to force assigment of an empty object as a resolved module
103
- const { getByText } = render(React.createElement(TestComponent, { renderProvider: () => Promise.resolve({}) }));
104
- await waitForElementToBeRemoved(() => getByText('loading'));
105
- expect(onDebugSpy).toHaveBeenCalledTimes(1);
106
- expect(getFirstCallArguments(onDebugSpy)).toMatchObject(expectedError);
107
- });
108
- it('should catch any error thrown by the render provider', async () => {
109
- const expectedError = {
110
- level: debug.LogLevel.error,
111
- message: `Failed trying to execute the dynamic import from extension "${EXTENSION_KEY}" for the async panel at location "${LOCATION}"`,
112
- components: ['AsyncPanelHandler'],
113
- meta: {
114
- location: LOCATION,
115
- extension: EXTENSION_KEY,
116
- error: new Error('test render error'),
117
- },
118
- };
119
- expect(onDebugSpy).toHaveBeenCalledTimes(0);
120
- const { getByText } = render(React.createElement(TestComponent, { renderProvider: () => {
121
- throw new Error('test render error');
122
- } }));
123
- await waitForElementToBeRemoved(() => getByText('loading'));
124
- expect(onDebugSpy).toHaveBeenCalledTimes(1);
125
- expect(getFirstCallArguments(onDebugSpy)).toMatchObject(expectedError);
126
- });
127
- it('should pass the context to the async module when the module was loaded', async () => {
128
- // given
129
- const contextValue = {
130
- myCounter: 1234,
131
- };
132
- const contextProvider = () => contextValue;
133
- onMountCallbackSpy.mockImplementation((container) => {
134
- const contextArgPos = 1;
135
- const lastContext = moduleSpy.mock.calls[moduleSpy.mock.calls.length - 1][contextArgPos];
136
- container.innerHTML = `<p data-testid="label">My counter is: <strong data-testid="counter">${lastContext.myCounter}</strong></p>`;
137
- });
138
- // when
139
- const { findByTestId, getByTestId } = render(React.createElement(TestComponent, { contextProvider: contextProvider }));
140
- await findByTestId('counter');
141
- // then
142
- expect(getByTestId('label').textContent).toEqual('My counter is: 1234');
143
- expect(moduleSpy).toHaveBeenLastCalledWith(expect.any(Object), contextValue);
144
- expect(onDebugSpy).toHaveBeenCalledTimes(0);
145
- });
146
- it('should propagate the latest value of the context to the async module', async () => {
147
- // given
148
- const contextValue = {
149
- myCounter: 1234,
150
- };
151
- const contextProvider = () => contextValue;
152
- // when
153
- const { getByText, rerender } = render(React.createElement(TestComponent, { contextProvider: contextProvider }));
154
- await waitForElementToBeRemoved(() => getByText('loading'));
155
- // then
156
- expect(moduleSpy).toHaveBeenLastCalledWith(expect.any(Object), contextValue);
157
- expect(onDebugSpy).toHaveBeenCalledTimes(0);
158
- // New context value
159
- const newContextValue = 9876;
160
- const newContextProvider = () => newContextValue;
161
- rerender(React.createElement(TestComponent, { contextProvider: newContextProvider }));
162
- expect(moduleSpy).toHaveBeenLastCalledWith(expect.any(Object), newContextValue);
163
- expect(onDebugSpy).toHaveBeenCalledTimes(0);
164
- });
165
- it('should log an error when failed invoking context provider', async () => {
166
- // given
167
- const contextProvider = () => {
168
- throw new SyntaxError();
169
- };
170
- // when
171
- const { getByText } = render(React.createElement(TestComponent, { contextProvider: contextProvider }));
172
- await waitForElementToBeRemoved(() => getByText('loading'));
173
- // then
174
- expect(onDebugSpy).toHaveBeenCalledTimes(1);
175
- expect(getFirstCallArguments(onDebugSpy)).toMatchObject({
176
- level: debug.LogLevel.error,
177
- message: `Failed to invoke "contextProvider" function for extension "${EXTENSION_KEY}" at location "${LOCATION}".\nError: SyntaxError`,
178
- components: ['AsyncPanelHandler'],
179
- meta: {
180
- location: LOCATION,
181
- extension: EXTENSION_KEY,
182
- },
183
- });
184
- });
185
- });
186
- //# sourceMappingURL=AsyncPanelHandler.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"As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C,mBAAmB,CAAC;YACjC,IAAI,EAAE;gBACF,QAAQ,EAAE,QAAQ;gBAClB,SAAS,EAAE,aAAa;aAC3B;SACJ,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\nimport * as React from 'react';\nimport { render, waitForElementToBeRemoved } from '@testing-library/react';\nimport * as debug from '@atlassian/clientside-extensions-debug';\n\nimport { AsyncPanelHandler } from './AsyncPanelHandler';\nimport type { AsyncPanelRenderExtension, AsyncPanelHandlerProps } from './AsyncPanelHandler';\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\nconst onMountCallbackSpy = jest.fn();\nconst onUnmountCallbackSpy = jest.fn();\nconst moduleSpy = jest.fn();\n\n// onAction method of an Extension\nconst createFakeRenderProvider: () => AsyncPanelRenderExtension = (): AsyncPanelRenderExtension => () =>\n // fake async module\n Promise.resolve({\n __esModule: true,\n default: moduleSpy,\n });\n\nconst LOCATION = 'test-location';\nconst EXTENSION_KEY = 'test-extension';\nconst TestComponent = (props: AsyncPanelHandlerProps) => {\n return <AsyncPanelHandler {...props} />;\n};\nTestComponent.defaultProps = {\n renderProvider: createFakeRenderProvider(),\n fallback: <p data-testid=\"loading\">loading</p>,\n location: LOCATION,\n extensionKey: EXTENSION_KEY,\n} as Partial<AsyncPanelHandlerProps>;\n\nconst getFirstCallArguments = (onDebugSpy: jest.Mock) => onDebugSpy.mock.calls[0][0];\n\ndescribe('AsyncPanelHandler', () => {\n const onDebugSpy = jest.fn();\n debug.observeLogger(onDebugSpy);\n\n beforeEach(() => {\n onMountCallbackSpy.mockReset();\n onUnmountCallbackSpy.mockReset();\n moduleSpy.mockReset();\n onDebugSpy.mockClear();\n\n moduleSpy.mockImplementation((panelAPI /* context, */ /* data */) => {\n panelAPI.onMount(onMountCallbackSpy);\n panelAPI.onUnmount(onUnmountCallbackSpy);\n });\n });\n\n it('should load and render the panel content asynchronously', async () => {\n const CUSTOM_CONTENT = `custom content`;\n onMountCallbackSpy.mockImplementationOnce((container: HTMLElement) => {\n container.innerHTML = CUSTOM_CONTENT;\n });\n\n const { getByText, findByText, queryByTestId } = render(<TestComponent />);\n\n expect(queryByTestId('loading')).toBeTruthy();\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(0);\n\n // wait for element to be on the screen\n await findByText(CUSTOM_CONTENT);\n\n expect(getByText(CUSTOM_CONTENT)).toBeTruthy();\n expect(queryByTestId('loading')).toBeFalsy();\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);\n });\n\n it('should provide an onMount and onUnmount API', async () => {\n const CUSTOM_CONTENT_1 = `custom content 1`;\n const CUSTOM_CONTENT_2 = `custom content 2`;\n\n const firstRenderProvider = createFakeRenderProvider();\n const secondRenderProvider = createFakeRenderProvider();\n\n onMountCallbackSpy\n .mockImplementationOnce((container: HTMLElement) => {\n container.innerHTML = CUSTOM_CONTENT_1;\n })\n .mockImplementationOnce((container: HTMLElement) => {\n container.innerHTML = CUSTOM_CONTENT_2;\n });\n\n const { rerender, findByText, queryByTestId, queryByText } = render(<TestComponent renderProvider={firstRenderProvider} />);\n\n expect(queryByTestId('loading')).toBeTruthy();\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(0);\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);\n\n // wait for element to be on the screen\n await findByText(CUSTOM_CONTENT_1);\n\n expect(queryByText(CUSTOM_CONTENT_1)).toBeTruthy();\n expect(queryByTestId('loading')).toBeFalsy();\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);\n\n rerender(<TestComponent renderProvider={secondRenderProvider} />);\n\n // wait for element to be on the screen\n await findByText(CUSTOM_CONTENT_2);\n\n expect(queryByText(CUSTOM_CONTENT_2)).toBeTruthy();\n expect(queryByText(CUSTOM_CONTENT_1)).toBeFalsy();\n expect(queryByTestId('loading')).toBeFalsy();\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(2);\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);\n });\n\n it('should catch the error if the async module has a wrong shape', async () => {\n const expectedError = {\n level: debug.LogLevel.error,\n\n message: `The provided dynamic import of extension \"${EXTENSION_KEY}\" at location \"${LOCATION}\" does not look like a module that can be asynchronously loaded.`,\n components: ['AsyncPanelHandler'],\n meta: {\n location: LOCATION,\n extension: EXTENSION_KEY,\n },\n };\n\n expect(onDebugSpy).toHaveBeenCalledTimes(0);\n\n // @ts-expect-error - ignoring to force assigment of an empty object as a resolved module\n const { getByText } = render(<TestComponent renderProvider={() => Promise.resolve({})} />);\n\n await waitForElementToBeRemoved(() => getByText('loading'));\n\n expect(onDebugSpy).toHaveBeenCalledTimes(1);\n expect(getFirstCallArguments(onDebugSpy)).toMatchObject(expectedError);\n });\n\n it('should catch any error thrown by the render provider', async () => {\n const expectedError = {\n level: debug.LogLevel.error,\n\n message: `Failed trying to execute the dynamic import from extension \"${EXTENSION_KEY}\" for the async panel at location \"${LOCATION}\"`,\n components: ['AsyncPanelHandler'],\n meta: {\n location: LOCATION,\n extension: EXTENSION_KEY,\n error: new Error('test render error'),\n },\n };\n\n expect(onDebugSpy).toHaveBeenCalledTimes(0);\n\n const { getByText } = render(\n <TestComponent\n renderProvider={() => {\n throw new Error('test render error');\n }}\n />,\n );\n\n await waitForElementToBeRemoved(() => getByText('loading'));\n\n expect(onDebugSpy).toHaveBeenCalledTimes(1);\n expect(getFirstCallArguments(onDebugSpy)).toMatchObject(expectedError);\n });\n\n it('should pass the context to the async module when the module was loaded', async () => {\n // given\n const contextValue = {\n myCounter: 1234,\n };\n\n const contextProvider = () => contextValue;\n\n onMountCallbackSpy.mockImplementation((container: HTMLElement) => {\n const contextArgPos = 1;\n const lastContext = moduleSpy.mock.calls[moduleSpy.mock.calls.length - 1][contextArgPos];\n\n container.innerHTML = `<p data-testid=\"label\">My counter is: <strong data-testid=\"counter\">${lastContext.myCounter}</strong></p>`;\n });\n\n // when\n const { findByTestId, getByTestId } = render(<TestComponent contextProvider={contextProvider} />);\n\n await findByTestId('counter');\n\n // then\n expect(getByTestId('label').textContent).toEqual('My counter is: 1234');\n expect(moduleSpy).toHaveBeenLastCalledWith(expect.any(Object), contextValue);\n expect(onDebugSpy).toHaveBeenCalledTimes(0);\n });\n\n it('should propagate the latest value of the context to the async module', async () => {\n // given\n const contextValue = {\n myCounter: 1234,\n };\n\n const contextProvider = () => contextValue;\n\n // when\n const { getByText, rerender } = render(<TestComponent contextProvider={contextProvider} />);\n\n await waitForElementToBeRemoved(() => getByText('loading'));\n\n // then\n expect(moduleSpy).toHaveBeenLastCalledWith(expect.any(Object), contextValue);\n expect(onDebugSpy).toHaveBeenCalledTimes(0);\n\n // New context value\n const newContextValue = 9876;\n const newContextProvider = () => newContextValue;\n\n rerender(<TestComponent contextProvider={newContextProvider} />);\n\n expect(moduleSpy).toHaveBeenLastCalledWith(expect.any(Object), newContextValue);\n expect(onDebugSpy).toHaveBeenCalledTimes(0);\n });\n\n it('should log an error when failed invoking context provider', async () => {\n // given\n const contextProvider = () => {\n throw new SyntaxError();\n };\n\n // when\n const { getByText } = render(<TestComponent contextProvider={contextProvider} />);\n\n await waitForElementToBeRemoved(() => getByText('loading'));\n\n // then\n expect(onDebugSpy).toHaveBeenCalledTimes(1);\n expect(getFirstCallArguments(onDebugSpy)).toMatchObject({\n level: debug.LogLevel.error,\n\n message: `Failed to invoke \"contextProvider\" function for extension \"${EXTENSION_KEY}\" at location \"${LOCATION}\".\\nError: SyntaxError`,\n components: ['AsyncPanelHandler'],\n meta: {\n location: LOCATION,\n extension: EXTENSION_KEY,\n },\n });\n });\n});\n"]}
@@ -1,37 +0,0 @@
1
- import * as React from 'react';
2
- import { render } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
4
- import { ButtonHandler } from './ButtonHandler';
5
- const TestComponent = ({ onAction, attributes, children }) => {
6
- return (
7
- // eslint-disable-next-line react/jsx-props-no-spreading
8
- React.createElement(ButtonHandler, Object.assign({ onAction: onAction }, attributes), children));
9
- };
10
- describe('ButtonHandler', () => {
11
- const buttonText = 'CLICK ME';
12
- let actionHandler;
13
- beforeEach(() => {
14
- actionHandler = jest.fn();
15
- });
16
- it('should render a button', async () => {
17
- var _a;
18
- const { queryByText } = render(React.createElement(TestComponent, { onAction: actionHandler }, buttonText));
19
- expect(await ((_a = queryByText(buttonText)) === null || _a === void 0 ? void 0 : _a.closest('button'))).toBeTruthy();
20
- });
21
- it('should render a disabled button', async () => {
22
- var _a;
23
- const { queryByText } = render(React.createElement(TestComponent, { onAction: actionHandler, attributes: { disabled: true } }, buttonText));
24
- expect((_a = (await queryByText(buttonText))) === null || _a === void 0 ? void 0 : _a.closest('button')).toBeDisabled();
25
- });
26
- it('should render nothing if "hidden" is true', async () => {
27
- const { queryByText } = render(React.createElement(TestComponent, { onAction: actionHandler, attributes: { hidden: true } }, buttonText));
28
- expect(await queryByText(buttonText)).toBeNull();
29
- });
30
- it('should correctly set the action handler', async () => {
31
- var _a;
32
- const { queryByText } = render(React.createElement(TestComponent, { onAction: actionHandler }, buttonText));
33
- await ((_a = queryByText(buttonText)) === null || _a === void 0 ? void 0 : _a.click());
34
- expect(actionHandler).toBeCalledTimes(1);
35
- });
36
- });
37
- //# sourceMappingURL=ButtonHandler.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ButtonHandler.test.js","sourceRoot":"","sources":["../../../lib/handlers/ButtonHandler.test.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,2BAA2B,CAAC;AAGnC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,MAAM,aAAa,GAAqE,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAA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nB,CAAC;QAEF,MAAM,CAAC,MAAM,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;;QACrD,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC,oBAAC,aAAa,IAAC,QAAQ,EAAE,aAAa,IAAG,UAAU,CAAiB,CAAC,CAAC;QAErG,aAAM,WAAW,CAAC,UAAU,CAAC,0CAAE,KAAK,GAAE,CAAC;QAEvC,MAAM,CAAC,aAAa,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { render } from '@testing-library/react';\nimport '@testing-library/jest-dom';\n\nimport type { FunctionComponent } from 'react';\nimport { ButtonHandler } from './ButtonHandler';\nimport Mock = jest.Mock;\n\nconst TestComponent: FunctionComponent<{ onAction: () => void; attributes?: object }> = ({ onAction, attributes, children }) => {\n return (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <ButtonHandler onAction={onAction} {...attributes}>\n {children}\n </ButtonHandler>\n );\n};\n\ndescribe('ButtonHandler', () => {\n const buttonText = 'CLICK ME';\n let actionHandler: Mock;\n\n beforeEach(() => {\n actionHandler = jest.fn();\n });\n\n it('should render a button', async () => {\n const { queryByText } = render(<TestComponent onAction={actionHandler}>{buttonText}</TestComponent>);\n\n expect(await queryByText(buttonText)?.closest('button')).toBeTruthy();\n });\n\n it('should render a disabled button', async () => {\n const { queryByText } = render(\n <TestComponent onAction={actionHandler} attributes={{ disabled: true }}>\n {buttonText}\n </TestComponent>,\n );\n\n expect((await queryByText(buttonText))?.closest('button')).toBeDisabled();\n });\n\n it('should render nothing if \"hidden\" is true', async () => {\n const { queryByText } = render(\n <TestComponent onAction={actionHandler} attributes={{ hidden: true }}>\n {buttonText}\n </TestComponent>,\n );\n\n expect(await queryByText(buttonText)).toBeNull();\n });\n\n it('should correctly set the action handler', async () => {\n const { queryByText } = render(<TestComponent onAction={actionHandler}>{buttonText}</TestComponent>);\n\n await queryByText(buttonText)?.click();\n\n expect(actionHandler).toBeCalledTimes(1);\n });\n});\n"]}
@@ -1,40 +0,0 @@
1
- import * as React from 'react';
2
- import { render } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
4
- import { LinkHandler } from './LinkHandler';
5
- const TestComponent = ({ url, attributes, children }) => {
6
- return (
7
- // eslint-disable-next-line react/jsx-props-no-spreading
8
- React.createElement(LinkHandler, Object.assign({ href: url }, attributes), children));
9
- };
10
- describe('LinkHandler', () => {
11
- const linkUrl = 'https://example.com';
12
- const linkText = 'CLICK ME';
13
- it('should render a link', async () => {
14
- var _a;
15
- const { queryByText } = render(React.createElement(TestComponent, { url: linkUrl }, linkText));
16
- expect((_a = (await queryByText(linkText))) === null || _a === void 0 ? void 0 : _a.closest('a')).toBeTruthy();
17
- });
18
- it('should render a link containing the url', async () => {
19
- var _a;
20
- const { queryByText } = render(React.createElement(TestComponent, { url: linkUrl }, linkText));
21
- expect((_a = (await queryByText(linkText))) === null || _a === void 0 ? void 0 : _a.closest('a')).toHaveAttribute('href', linkUrl);
22
- });
23
- it('should render a disabled link', async () => {
24
- var _a;
25
- const { queryByText } = render(React.createElement(TestComponent, { url: linkUrl, attributes: { disabled: true } }, linkText));
26
- expect((_a = (await queryByText(linkText))) === null || _a === void 0 ? void 0 : _a.closest('a')).toHaveAttribute('disabled');
27
- });
28
- it('should render nothing if "hidden" is true', async () => {
29
- const { queryByText } = render(React.createElement(TestComponent, { url: linkUrl, attributes: { hidden: true } }, linkText));
30
- expect(await queryByText(linkText)).toBeNull();
31
- });
32
- it('should correctly set the action handler', async () => {
33
- var _a;
34
- const spy = jest.fn();
35
- const { queryByText } = render(React.createElement(TestComponent, { url: linkUrl, attributes: { onAction: spy } }, linkText));
36
- await ((_a = queryByText(linkText)) === null || _a === void 0 ? void 0 : _a.click());
37
- expect(spy).toBeCalledTimes(1);
38
- });
39
- });
40
- //# sourceMappingURL=LinkHandler.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LinkHandler.test.js","sourceRoot":"","sources":["../../../lib/handlers/LinkHandler.test.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,2BAA2B,CAAC;AAInC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,aAAa,GAA4D,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC7G,OAAO;IACH,wDAAwD;IACxD,oBAAC,WAAW,kBAAC,IAAI,EAAE,GAAG,IAAM,UAAU,GACjC,QAAQ,CACC,CACjB,CAAC;AACN,CAAC,CAAC;AAEF,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IACzB,MAAM,OAAO,GAAG,qBAAqB,CAAC;IACtC,MAAM,QAAQ,GAAG,UAAU,CAAC;IAE5B,EAAE,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;;QAClC,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC,oBAAC,aAAa,IAAC,GAAG,EAAE,OAAO,IAAG,QAAQ,CAAiB,CAAC,CAAC;QAExF,MAAM,OAAC,CAAC,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC,0CAAE,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC;IACrE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;;QACrD,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC,oBAAC,aAAa,IAAC,GAAG,EAAE,OAAO,IAAG,QAAQ,CAAiB,CAAC,CAAC;QAExF,MAAM,OAAC,CAAC,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC,0CAAE,OAAO,C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esContent":["import * as React from 'react';\nimport { render } from '@testing-library/react';\nimport '@testing-library/jest-dom';\n\nimport type { FunctionComponent } from 'react';\n\nimport { LinkHandler } from './LinkHandler';\n\nconst TestComponent: FunctionComponent<{ url: string; attributes?: object }> = ({ url, attributes, children }) => {\n return (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <LinkHandler href={url} {...attributes}>\n {children}\n </LinkHandler>\n );\n};\n\ndescribe('LinkHandler', () => {\n const linkUrl = 'https://example.com';\n const linkText = 'CLICK ME';\n\n it('should render a link', async () => {\n const { queryByText } = render(<TestComponent url={linkUrl}>{linkText}</TestComponent>);\n\n expect((await queryByText(linkText))?.closest('a')).toBeTruthy();\n });\n\n it('should render a link containing the url', async () => {\n const { queryByText } = render(<TestComponent url={linkUrl}>{linkText}</TestComponent>);\n\n expect((await queryByText(linkText))?.closest('a')).toHaveAttribute('href', linkUrl);\n });\n\n it('should render a disabled link', async () => {\n const { queryByText } = render(\n <TestComponent url={linkUrl} attributes={{ disabled: true }}>\n {linkText}\n </TestComponent>,\n );\n\n expect((await queryByText(linkText))?.closest('a')).toHaveAttribute('disabled');\n });\n\n it('should render nothing if \"hidden\" is true', async () => {\n const { queryByText } = render(\n <TestComponent url={linkUrl} attributes={{ hidden: true }}>\n {linkText}\n </TestComponent>,\n );\n\n expect(await queryByText(linkText)).toBeNull();\n });\n\n it('should correctly set the action handler', async () => {\n const spy = jest.fn();\n const { queryByText } = render(\n <TestComponent url={linkUrl} attributes={{ onAction: spy }}>\n {linkText}\n </TestComponent>,\n );\n\n await queryByText(linkText)?.click();\n\n expect(spy).toBeCalledTimes(1);\n });\n});\n"]}
@@ -1,186 +0,0 @@
1
- /* eslint-disable jest/no-commented-out-tests */
2
- /* eslint-disable react/jsx-boolean-value */
3
- import * as React from 'react';
4
- import { render, fireEvent } from '@testing-library/react';
5
- import { ModalHandler, ModalWithActionHandler } from './ModalHandler';
6
- const onMountCallbackSpy = jest.fn();
7
- const onUnmountCallbackSpy = jest.fn();
8
- const testRenderFn = (api) => {
9
- api.onMount(onMountCallbackSpy);
10
- api.onUnmount(onUnmountCallbackSpy);
11
- };
12
- // When an attribute of the extension changes, the useExtensions hook returns a completly new descriptor object
13
- // This render function is used to replicate that behaviour.
14
- const changedTestRenderFn = (api) => {
15
- api.onMount(onMountCallbackSpy);
16
- api.onUnmount(onUnmountCallbackSpy);
17
- };
18
- const emptyRenderer = () => null;
19
- const emptyCallback = () => null;
20
- const TestComponent = ({ render: renderProp = testRenderFn, isOpen = true, onClose = emptyCallback, }) => {
21
- return React.createElement(ModalHandler, { render: renderProp, isOpen: isOpen, onClose: onClose });
22
- };
23
- const TestComponentWithActionHandler = ({ render: renderProp = emptyRenderer, children, }) => {
24
- return React.createElement(ModalWithActionHandler, { render: renderProp }, children);
25
- };
26
- TestComponentWithActionHandler.defaultProps = {
27
- render: testRenderFn,
28
- };
29
- describe('ModalHandler', () => {
30
- beforeEach(() => {
31
- onMountCallbackSpy.mockReset();
32
- onUnmountCallbackSpy.mockReset();
33
- });
34
- describe('ModalHandler', () => {
35
- it('should receive an isOpen prop to set the modal as open', () => {
36
- const { rerender, queryByRole } = render(React.createElement(TestComponent, { isOpen: false }));
37
- expect(queryByRole('dialog')).toBeFalsy();
38
- rerender(React.createElement(TestComponent, { isOpen: true }));
39
- expect(queryByRole('dialog')).toBeTruthy();
40
- });
41
- it('should provide a closeModal API method to extension that executes a provided onClose prop to close the modal', () => {
42
- const onCloseCallbackSpy = jest.fn();
43
- expect(onCloseCallbackSpy).toHaveBeenCalledTimes(0);
44
- render(React.createElement(TestComponent, { render: (api) => api.closeModal(), onClose: onCloseCallbackSpy }));
45
- expect(onCloseCallbackSpy).toHaveBeenCalledTimes(1);
46
- });
47
- it('should provide an onClose API method for extension to prevent the modal from closing unexpectedly (e.g: ESC key)', () => {
48
- const onCloseCallbackSpy = jest.fn();
49
- const fireEscKeyPress = () => fireEvent.keyDown(document.body, {
50
- key: 'Escape',
51
- keyCode: 27,
52
- charCode: 27,
53
- which: 27,
54
- });
55
- expect(onCloseCallbackSpy).toHaveBeenCalledTimes(0);
56
- const { rerender, container } = render(React.createElement(TestComponent, { render: (api) => api.onClose(() => false), onClose: onCloseCallbackSpy }));
57
- fireEvent.click(container);
58
- expect(onCloseCallbackSpy).toHaveBeenCalledTimes(0);
59
- rerender(React.createElement(TestComponent, { render: (api) => api.onClose(() => true), onClose: onCloseCallbackSpy }));
60
- fireEscKeyPress();
61
- expect(onCloseCallbackSpy).toHaveBeenCalledTimes(1);
62
- });
63
- it('should provide a setTitle API method that sets a title in the modal header', async () => {
64
- const TEST_TITLE = 'A modal with a test title';
65
- const { findByRole } = render(React.createElement(TestComponent, { render: (api) => api.setTitle(TEST_TITLE) }));
66
- expect((await findByRole('heading')).textContent).toBe(TEST_TITLE);
67
- });
68
- it('should provide a setActions API to specify the actions a user can perform when the modal is opened', async () => {
69
- const primaryActionSpy = jest.fn();
70
- const secondaryActionSpy = jest.fn();
71
- const actions = [
72
- {
73
- text: 'Primary action',
74
- onClick: primaryActionSpy,
75
- testId: 'primaryAction',
76
- },
77
- {
78
- text: 'Secondary action',
79
- onClick: secondaryActionSpy,
80
- testId: 'secondaryAction',
81
- },
82
- ];
83
- const { findByTestId } = render(React.createElement(TestComponent, { render: (api) => api.setActions(actions) }));
84
- const primaryBtn = await findByTestId('primaryAction');
85
- const secondaryBtn = await findByTestId('secondaryAction');
86
- expect(primaryActionSpy).toHaveBeenCalledTimes(0);
87
- expect(secondaryActionSpy).toHaveBeenCalledTimes(0);
88
- fireEvent.click(primaryBtn);
89
- expect(primaryActionSpy).toHaveBeenCalledTimes(1);
90
- expect(secondaryActionSpy).toHaveBeenCalledTimes(0);
91
- fireEvent.click(secondaryBtn);
92
- expect(primaryActionSpy).toHaveBeenCalledTimes(1);
93
- expect(secondaryActionSpy).toHaveBeenCalledTimes(1);
94
- });
95
- it('should allow modal actions to be set as disabled', async () => {
96
- const primaryActionSpy = jest.fn();
97
- const primaryAction = {
98
- text: 'Primary action',
99
- onClick: primaryActionSpy,
100
- testId: 'primaryAction',
101
- };
102
- const { findByTestId, rerender } = render(React.createElement(TestComponent, { render: (api) => api.setActions([primaryAction]) }));
103
- expect(primaryActionSpy).toHaveBeenCalledTimes(0);
104
- fireEvent.click(await findByTestId('primaryAction'));
105
- expect(primaryActionSpy).toHaveBeenCalledTimes(1);
106
- primaryAction.isDisabled = true;
107
- rerender(React.createElement(TestComponent, { render: (api) => api.setActions([primaryAction]) }));
108
- fireEvent.click(await findByTestId('primaryAction'));
109
- expect(primaryActionSpy).toHaveBeenCalledTimes(1);
110
- });
111
- // TODO: find a way with AK team to test that a button is in loading state.
112
- // it.only('should allow modal actions to be set as loading', () => {});
113
- // TODO: find a way with AK team to test the size applied to a modal without querying for the actual size of the element.
114
- // it('should provide a setWidth API method to modify the width of the modal', () => {});
115
- // TODO: find a way with AK team to test the danger/warning appearance of a modal without involving CSS.
116
- // it('should provide a setAppearance API method that changes the appearance of the modal', () => {});
117
- it('should provide an onMount API method to render custom HTML in a container', async () => {
118
- const CUSTOM_CONTENT = 'Custom content';
119
- onMountCallbackSpy.mockImplementationOnce((container) => {
120
- container.innerHTML = CUSTOM_CONTENT;
121
- });
122
- const { findByText } = render(React.createElement(TestComponent, null));
123
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
124
- expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
125
- });
126
- it('should only rerender the extension content if something in the extension descriptor changed', async () => {
127
- const CUSTOM_CONTENT = 'Custom content';
128
- const DIFFERENT_CONTENT = 'Different content';
129
- onMountCallbackSpy
130
- .mockImplementationOnce((container) => {
131
- container.innerHTML = CUSTOM_CONTENT;
132
- })
133
- .mockImplementationOnce((container) => {
134
- container.innerHTML = DIFFERENT_CONTENT;
135
- });
136
- const { findByText, rerender } = render(React.createElement(TestComponent, null));
137
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
138
- expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
139
- rerender(React.createElement(TestComponent, null));
140
- // expect nothing to change
141
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
142
- expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
143
- rerender(React.createElement(TestComponent, { render: changedTestRenderFn }));
144
- // expect the new value to be rendered
145
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(2);
146
- expect(await findByText(DIFFERENT_CONTENT)).toBeTruthy();
147
- });
148
- it('should provide an onUnmount API method to be called with the container element when destroying the extension', () => {
149
- onMountCallbackSpy.mockImplementation((container) => {
150
- expect(container).toHaveProperty('innerHTML');
151
- });
152
- const { unmount } = render(React.createElement(TestComponent, null));
153
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
154
- unmount();
155
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);
156
- });
157
- it('should only call cleanUp callback if the extension changes or the container is destroyed', () => {
158
- const { rerender, unmount } = render(React.createElement(TestComponent, null));
159
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
160
- rerender(React.createElement(TestComponent, null));
161
- // the container rerenders with the same extension render prop, so no need to call cleanup
162
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
163
- rerender(React.createElement(TestComponent, { render: changedTestRenderFn }));
164
- // the extension render prop changed, so cleanup is called
165
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);
166
- unmount();
167
- // the container is destroyed, so cleanup is called
168
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(2);
169
- });
170
- });
171
- describe('ModalWithActionHandler', () => {
172
- const modalButtonText = 'My Modal';
173
- it('should render a button to handle the modal', () => {
174
- const { queryByText } = render(React.createElement(TestComponentWithActionHandler, null, modalButtonText));
175
- expect(queryByText(modalButtonText)).toBeTruthy();
176
- });
177
- it('should receive an isOpen prop to set the modal as open', () => {
178
- var _a;
179
- const { queryByRole, queryByText } = render(React.createElement(TestComponentWithActionHandler, null, modalButtonText));
180
- expect(queryByRole('dialog')).toBeFalsy();
181
- (_a = queryByText(modalButtonText)) === null || _a === void 0 ? void 0 : _a.click();
182
- expect(queryByRole('dialog')).toBeTruthy();
183
- });
184
- });
185
- });
186
- //# sourceMappingURL=ModalHandler.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ModalHandler.test.js","sourceRoot":"","sources":["../../../lib/handlers/ModalHandler.test.tsx"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,4CAA4C;AAC5C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAK3D,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAGtE,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACrC,MAAM,oBAAoB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEvC,MAAM,YAAY,GAAwC,CAAC,GAAG,EAAE,EAAE;IAC9D,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAChC,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,+GAA+G;AAC/G,4DAA4D;AAC5D,MAAM,mBAAmB,GAAwC,CAAC,GAAG,EAAE,EAAE;IACrE,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAChC,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,GAAS,EAAE,CAAC,IAAI,CAAC;AACvC,MAAM,aAAa,GAAG,GAAS,EAAE,CAAC,IAAI,CAAC;AAEvC,MAAM,aAAa,GAAkD,CAAC,EAClE,MAAM,EAAE,UAAU,GAAG,YAAY,EACjC,MAAM,GAAG,IAAI,EACb,OAAO,GAAG,aAAa,GAC1B,EAAE,EAAE;IACD,OAAO,oBAAC,YAAY,IAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE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\nimport * as React from 'react';\nimport { render, fireEvent } from '@testing-library/react';\n\nimport type { ModalExtension } from '@atlassian/clientside-extensions';\nimport type { FunctionComponent } from 'react';\n\nimport { ModalHandler, ModalWithActionHandler } from './ModalHandler';\nimport type { ModalHandlerProps, ModalWithActionHandlerProps } from './ModalHandler';\n\nconst onMountCallbackSpy = jest.fn();\nconst onUnmountCallbackSpy = jest.fn();\n\nconst testRenderFn: ModalExtension.ModalRenderExtension = (api) => {\n api.onMount(onMountCallbackSpy);\n api.onUnmount(onUnmountCallbackSpy);\n};\n\n// When an attribute of the extension changes, the useExtensions hook returns a completly new descriptor object\n// This render function is used to replicate that behaviour.\nconst changedTestRenderFn: ModalExtension.ModalRenderExtension = (api) => {\n api.onMount(onMountCallbackSpy);\n api.onUnmount(onUnmountCallbackSpy);\n};\n\nconst emptyRenderer = (): null => null;\nconst emptyCallback = (): null => null;\n\nconst TestComponent: FunctionComponent<Partial<ModalHandlerProps>> = ({\n render: renderProp = testRenderFn,\n isOpen = true,\n onClose = emptyCallback,\n}) => {\n return <ModalHandler render={renderProp} isOpen={isOpen} onClose={onClose} />;\n};\n\nconst TestComponentWithActionHandler: FunctionComponent<Partial<ModalWithActionHandlerProps>> = ({\n render: renderProp = emptyRenderer,\n children,\n}) => {\n return <ModalWithActionHandler render={renderProp}>{children}</ModalWithActionHandler>;\n};\n\nTestComponentWithActionHandler.defaultProps = {\n render: testRenderFn,\n} as Partial<ModalHandlerProps>;\n\ndescribe('ModalHandler', () => {\n beforeEach(() => {\n onMountCallbackSpy.mockReset();\n onUnmountCallbackSpy.mockReset();\n });\n\n describe('ModalHandler', () => {\n it('should receive an isOpen prop to set the modal as open', () => {\n const { rerender, queryByRole } = render(<TestComponent isOpen={false} />);\n\n expect(queryByRole('dialog')).toBeFalsy();\n\n rerender(<TestComponent isOpen={true} />);\n\n expect(queryByRole('dialog')).toBeTruthy();\n });\n\n it('should provide a closeModal API method to extension that executes a provided onClose prop to close the modal', () => {\n const onCloseCallbackSpy = jest.fn();\n\n expect(onCloseCallbackSpy).toHaveBeenCalledTimes(0);\n\n render(<TestComponent render={(api) => api.closeModal()} onClose={onCloseCallbackSpy} />);\n\n expect(onCloseCallbackSpy).toHaveBeenCalledTimes(1);\n });\n\n it('should provide an onClose API method for extension to prevent the modal from closing unexpectedly (e.g: ESC key)', () => {\n const onCloseCallbackSpy = jest.fn();\n const fireEscKeyPress = () =>\n fireEvent.keyDown(document.body, {\n key: 'Escape',\n keyCode: 27,\n charCode: 27,\n which: 27,\n });\n\n expect(onCloseCallbackSpy).toHaveBeenCalledTimes(0);\n\n const { rerender, container } = render(\n <TestComponent render={(api) => api.onClose(() => false)} onClose={onCloseCallbackSpy} />,\n );\n\n fireEvent.click(container);\n\n expect(onCloseCallbackSpy).toHaveBeenCalledTimes(0);\n\n rerender(<TestComponent render={(api) => api.onClose(() => true)} onClose={onCloseCallbackSpy} />);\n\n fireEscKeyPress();\n\n expect(onCloseCallbackSpy).toHaveBeenCalledTimes(1);\n });\n\n it('should provide a setTitle API method that sets a title in the modal header', async () => {\n const TEST_TITLE = 'A modal with a test title';\n\n const { findByRole } = render(<TestComponent render={(api) => api.setTitle(TEST_TITLE)} />);\n\n expect((await findByRole('heading')).textContent).toBe(TEST_TITLE);\n });\n\n it('should provide a setActions API to specify the actions a user can perform when the modal is opened', async () => {\n const primaryActionSpy = jest.fn();\n const secondaryActionSpy = jest.fn();\n\n const actions: ModalExtension.ModalAction[] = [\n {\n text: 'Primary action',\n onClick: primaryActionSpy,\n testId: 'primaryAction',\n },\n {\n text: 'Secondary action',\n onClick: secondaryActionSpy,\n testId: 'secondaryAction',\n },\n ];\n\n const { findByTestId } = render(<TestComponent render={(api) => api.setActions(actions)} />);\n\n const primaryBtn = await findByTestId('primaryAction');\n const secondaryBtn = await findByTestId('secondaryAction');\n\n expect(primaryActionSpy).toHaveBeenCalledTimes(0);\n expect(secondaryActionSpy).toHaveBeenCalledTimes(0);\n\n fireEvent.click(primaryBtn);\n\n expect(primaryActionSpy).toHaveBeenCalledTimes(1);\n expect(secondaryActionSpy).toHaveBeenCalledTimes(0);\n\n fireEvent.click(secondaryBtn);\n\n expect(primaryActionSpy).toHaveBeenCalledTimes(1);\n expect(secondaryActionSpy).toHaveBeenCalledTimes(1);\n });\n\n it('should allow modal actions to be set as disabled', async () => {\n const primaryActionSpy = jest.fn();\n\n const primaryAction: ModalExtension.ModalAction = {\n text: 'Primary action',\n onClick: primaryActionSpy,\n testId: 'primaryAction',\n };\n const { findByTestId, rerender } = render(<TestComponent render={(api) => api.setActions([primaryAction])} />);\n\n expect(primaryActionSpy).toHaveBeenCalledTimes(0);\n\n fireEvent.click(await findByTestId('primaryAction'));\n\n expect(primaryActionSpy).toHaveBeenCalledTimes(1);\n\n primaryAction.isDisabled = true;\n rerender(<TestComponent render={(api) => api.setActions([primaryAction])} />);\n fireEvent.click(await findByTestId('primaryAction'));\n\n expect(primaryActionSpy).toHaveBeenCalledTimes(1);\n });\n\n // TODO: find a way with AK team to test that a button is in loading state.\n // it.only('should allow modal actions to be set as loading', () => {});\n\n // TODO: find a way with AK team to test the size applied to a modal without querying for the actual size of the element.\n // it('should provide a setWidth API method to modify the width of the modal', () => {});\n\n // TODO: find a way with AK team to test the danger/warning appearance of a modal without involving CSS.\n // it('should provide a setAppearance API method that changes the appearance of the modal', () => {});\n\n it('should provide an onMount API method to render custom HTML in a container', async () => {\n const CUSTOM_CONTENT = 'Custom content';\n onMountCallbackSpy.mockImplementationOnce((container: HTMLElement) => {\n container.innerHTML = CUSTOM_CONTENT;\n });\n\n const { findByText } = render(<TestComponent />);\n\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);\n expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();\n });\n\n it('should only rerender the extension content if something in the extension descriptor changed', async () => {\n const CUSTOM_CONTENT = 'Custom content';\n const DIFFERENT_CONTENT = 'Different content';\n onMountCallbackSpy\n .mockImplementationOnce((container: HTMLElement) => {\n container.innerHTML = CUSTOM_CONTENT;\n })\n .mockImplementationOnce((container: HTMLElement) => {\n container.innerHTML = DIFFERENT_CONTENT;\n });\n\n const { findByText, rerender } = render(<TestComponent />);\n\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);\n expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();\n\n rerender(<TestComponent />);\n\n // expect nothing to change\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);\n expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();\n\n rerender(<TestComponent render={changedTestRenderFn} />);\n\n // expect the new value to be rendered\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(2);\n expect(await findByText(DIFFERENT_CONTENT)).toBeTruthy();\n });\n\n it('should provide an onUnmount API method to be called with the container element when destroying the extension', () => {\n onMountCallbackSpy.mockImplementation((container: HTMLElement) => {\n expect(container).toHaveProperty('innerHTML');\n });\n\n const { unmount } = render(<TestComponent />);\n\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);\n\n unmount();\n\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);\n });\n\n it('should only call cleanUp callback if the extension changes or the container is destroyed', () => {\n const { rerender, unmount } = render(<TestComponent />);\n\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);\n\n rerender(<TestComponent />);\n\n // the container rerenders with the same extension render prop, so no need to call cleanup\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);\n\n rerender(<TestComponent render={changedTestRenderFn} />);\n\n // the extension render prop changed, so cleanup is called\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);\n\n unmount();\n\n // the container is destroyed, so cleanup is called\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(2);\n });\n });\n\n describe('ModalWithActionHandler', () => {\n const modalButtonText = 'My Modal';\n\n it('should render a button to handle the modal', () => {\n const { queryByText } = render(<TestComponentWithActionHandler>{modalButtonText}</TestComponentWithActionHandler>);\n\n expect(queryByText(modalButtonText)).toBeTruthy();\n });\n\n it('should receive an isOpen prop to set the modal as open', () => {\n const { queryByRole, queryByText } = render(<TestComponentWithActionHandler>{modalButtonText}</TestComponentWithActionHandler>);\n\n expect(queryByRole('dialog')).toBeFalsy();\n\n queryByText(modalButtonText)?.click();\n\n expect(queryByRole('dialog')).toBeTruthy();\n });\n });\n});\n"]}