@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,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const React = tslib_1.__importStar(require("react"));
5
- const react_1 = require("@testing-library/react");
6
- require("@testing-library/jest-dom");
7
- const LinkHandler_1 = require("./LinkHandler");
8
- const TestComponent = ({ url, attributes, children }) => {
9
- return (
10
- // eslint-disable-next-line react/jsx-props-no-spreading
11
- React.createElement(LinkHandler_1.LinkHandler, Object.assign({ href: url }, attributes), children));
12
- };
13
- describe('LinkHandler', () => {
14
- const linkUrl = 'https://example.com';
15
- const linkText = 'CLICK ME';
16
- it('should render a link', async () => {
17
- var _a;
18
- const { queryByText } = react_1.render(React.createElement(TestComponent, { url: linkUrl }, linkText));
19
- expect((_a = (await queryByText(linkText))) === null || _a === void 0 ? void 0 : _a.closest('a')).toBeTruthy();
20
- });
21
- it('should render a link containing the url', async () => {
22
- var _a;
23
- const { queryByText } = react_1.render(React.createElement(TestComponent, { url: linkUrl }, linkText));
24
- expect((_a = (await queryByText(linkText))) === null || _a === void 0 ? void 0 : _a.closest('a')).toHaveAttribute('href', linkUrl);
25
- });
26
- it('should render a disabled link', async () => {
27
- var _a;
28
- const { queryByText } = react_1.render(React.createElement(TestComponent, { url: linkUrl, attributes: { disabled: true } }, linkText));
29
- expect((_a = (await queryByText(linkText))) === null || _a === void 0 ? void 0 : _a.closest('a')).toHaveAttribute('disabled');
30
- });
31
- it('should render nothing if "hidden" is true', async () => {
32
- const { queryByText } = react_1.render(React.createElement(TestComponent, { url: linkUrl, attributes: { hidden: true } }, linkText));
33
- expect(await queryByText(linkText)).toBeNull();
34
- });
35
- it('should correctly set the action handler', async () => {
36
- var _a;
37
- const spy = jest.fn();
38
- const { queryByText } = react_1.render(React.createElement(TestComponent, { url: linkUrl, attributes: { onAction: spy } }, linkText));
39
- await ((_a = queryByText(linkText)) === null || _a === void 0 ? void 0 : _a.click());
40
- expect(spy).toBeCalledTimes(1);
41
- });
42
- });
43
- //# 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,qDAA+B;AAC/B,kDAAgD;AAChD,qCAAmC;AAInC,+CAA4C;AAE5C,MAAM,aAAa,GAA4D,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC7G,OAAO;IACH,wDAAwD;IACxD,oBAAC,yBAAW,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,cAAM,CAAC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CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;;QACrD,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QACtB,MAAM,EAAE,WAAW,EAAE,GAAG,cAAM,CAC1B,oBAAC,aAAa,IAAC,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,IACrD,QAAQ,CACG,CACnB,CAAC;QAEF,aAAM,WAAW,CAAC,QAAQ,CAAC,0CAAE,KAAK,GAAE,CAAC;QAErC,MAAM,CAAC,GAAG,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IACnC,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';\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,189 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- /* eslint-disable jest/no-commented-out-tests */
5
- /* eslint-disable react/jsx-boolean-value */
6
- const React = tslib_1.__importStar(require("react"));
7
- const react_1 = require("@testing-library/react");
8
- const ModalHandler_1 = require("./ModalHandler");
9
- const onMountCallbackSpy = jest.fn();
10
- const onUnmountCallbackSpy = jest.fn();
11
- const testRenderFn = (api) => {
12
- api.onMount(onMountCallbackSpy);
13
- api.onUnmount(onUnmountCallbackSpy);
14
- };
15
- // When an attribute of the extension changes, the useExtensions hook returns a completly new descriptor object
16
- // This render function is used to replicate that behaviour.
17
- const changedTestRenderFn = (api) => {
18
- api.onMount(onMountCallbackSpy);
19
- api.onUnmount(onUnmountCallbackSpy);
20
- };
21
- const emptyRenderer = () => null;
22
- const emptyCallback = () => null;
23
- const TestComponent = ({ render: renderProp = testRenderFn, isOpen = true, onClose = emptyCallback, }) => {
24
- return React.createElement(ModalHandler_1.ModalHandler, { render: renderProp, isOpen: isOpen, onClose: onClose });
25
- };
26
- const TestComponentWithActionHandler = ({ render: renderProp = emptyRenderer, children, }) => {
27
- return React.createElement(ModalHandler_1.ModalWithActionHandler, { render: renderProp }, children);
28
- };
29
- TestComponentWithActionHandler.defaultProps = {
30
- render: testRenderFn,
31
- };
32
- describe('ModalHandler', () => {
33
- beforeEach(() => {
34
- onMountCallbackSpy.mockReset();
35
- onUnmountCallbackSpy.mockReset();
36
- });
37
- describe('ModalHandler', () => {
38
- it('should receive an isOpen prop to set the modal as open', () => {
39
- const { rerender, queryByRole } = react_1.render(React.createElement(TestComponent, { isOpen: false }));
40
- expect(queryByRole('dialog')).toBeFalsy();
41
- rerender(React.createElement(TestComponent, { isOpen: true }));
42
- expect(queryByRole('dialog')).toBeTruthy();
43
- });
44
- it('should provide a closeModal API method to extension that executes a provided onClose prop to close the modal', () => {
45
- const onCloseCallbackSpy = jest.fn();
46
- expect(onCloseCallbackSpy).toHaveBeenCalledTimes(0);
47
- react_1.render(React.createElement(TestComponent, { render: (api) => api.closeModal(), onClose: onCloseCallbackSpy }));
48
- expect(onCloseCallbackSpy).toHaveBeenCalledTimes(1);
49
- });
50
- it('should provide an onClose API method for extension to prevent the modal from closing unexpectedly (e.g: ESC key)', () => {
51
- const onCloseCallbackSpy = jest.fn();
52
- const fireEscKeyPress = () => react_1.fireEvent.keyDown(document.body, {
53
- key: 'Escape',
54
- keyCode: 27,
55
- charCode: 27,
56
- which: 27,
57
- });
58
- expect(onCloseCallbackSpy).toHaveBeenCalledTimes(0);
59
- const { rerender, container } = react_1.render(React.createElement(TestComponent, { render: (api) => api.onClose(() => false), onClose: onCloseCallbackSpy }));
60
- react_1.fireEvent.click(container);
61
- expect(onCloseCallbackSpy).toHaveBeenCalledTimes(0);
62
- rerender(React.createElement(TestComponent, { render: (api) => api.onClose(() => true), onClose: onCloseCallbackSpy }));
63
- fireEscKeyPress();
64
- expect(onCloseCallbackSpy).toHaveBeenCalledTimes(1);
65
- });
66
- it('should provide a setTitle API method that sets a title in the modal header', async () => {
67
- const TEST_TITLE = 'A modal with a test title';
68
- const { findByRole } = react_1.render(React.createElement(TestComponent, { render: (api) => api.setTitle(TEST_TITLE) }));
69
- expect((await findByRole('heading')).textContent).toBe(TEST_TITLE);
70
- });
71
- it('should provide a setActions API to specify the actions a user can perform when the modal is opened', async () => {
72
- const primaryActionSpy = jest.fn();
73
- const secondaryActionSpy = jest.fn();
74
- const actions = [
75
- {
76
- text: 'Primary action',
77
- onClick: primaryActionSpy,
78
- testId: 'primaryAction',
79
- },
80
- {
81
- text: 'Secondary action',
82
- onClick: secondaryActionSpy,
83
- testId: 'secondaryAction',
84
- },
85
- ];
86
- const { findByTestId } = react_1.render(React.createElement(TestComponent, { render: (api) => api.setActions(actions) }));
87
- const primaryBtn = await findByTestId('primaryAction');
88
- const secondaryBtn = await findByTestId('secondaryAction');
89
- expect(primaryActionSpy).toHaveBeenCalledTimes(0);
90
- expect(secondaryActionSpy).toHaveBeenCalledTimes(0);
91
- react_1.fireEvent.click(primaryBtn);
92
- expect(primaryActionSpy).toHaveBeenCalledTimes(1);
93
- expect(secondaryActionSpy).toHaveBeenCalledTimes(0);
94
- react_1.fireEvent.click(secondaryBtn);
95
- expect(primaryActionSpy).toHaveBeenCalledTimes(1);
96
- expect(secondaryActionSpy).toHaveBeenCalledTimes(1);
97
- });
98
- it('should allow modal actions to be set as disabled', async () => {
99
- const primaryActionSpy = jest.fn();
100
- const primaryAction = {
101
- text: 'Primary action',
102
- onClick: primaryActionSpy,
103
- testId: 'primaryAction',
104
- };
105
- const { findByTestId, rerender } = react_1.render(React.createElement(TestComponent, { render: (api) => api.setActions([primaryAction]) }));
106
- expect(primaryActionSpy).toHaveBeenCalledTimes(0);
107
- react_1.fireEvent.click(await findByTestId('primaryAction'));
108
- expect(primaryActionSpy).toHaveBeenCalledTimes(1);
109
- primaryAction.isDisabled = true;
110
- rerender(React.createElement(TestComponent, { render: (api) => api.setActions([primaryAction]) }));
111
- react_1.fireEvent.click(await findByTestId('primaryAction'));
112
- expect(primaryActionSpy).toHaveBeenCalledTimes(1);
113
- });
114
- // TODO: find a way with AK team to test that a button is in loading state.
115
- // it.only('should allow modal actions to be set as loading', () => {});
116
- // TODO: find a way with AK team to test the size applied to a modal without querying for the actual size of the element.
117
- // it('should provide a setWidth API method to modify the width of the modal', () => {});
118
- // TODO: find a way with AK team to test the danger/warning appearance of a modal without involving CSS.
119
- // it('should provide a setAppearance API method that changes the appearance of the modal', () => {});
120
- it('should provide an onMount API method to render custom HTML in a container', async () => {
121
- const CUSTOM_CONTENT = 'Custom content';
122
- onMountCallbackSpy.mockImplementationOnce((container) => {
123
- container.innerHTML = CUSTOM_CONTENT;
124
- });
125
- const { findByText } = react_1.render(React.createElement(TestComponent, null));
126
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
127
- expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
128
- });
129
- it('should only rerender the extension content if something in the extension descriptor changed', async () => {
130
- const CUSTOM_CONTENT = 'Custom content';
131
- const DIFFERENT_CONTENT = 'Different content';
132
- onMountCallbackSpy
133
- .mockImplementationOnce((container) => {
134
- container.innerHTML = CUSTOM_CONTENT;
135
- })
136
- .mockImplementationOnce((container) => {
137
- container.innerHTML = DIFFERENT_CONTENT;
138
- });
139
- const { findByText, rerender } = react_1.render(React.createElement(TestComponent, null));
140
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
141
- expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
142
- rerender(React.createElement(TestComponent, null));
143
- // expect nothing to change
144
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
145
- expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
146
- rerender(React.createElement(TestComponent, { render: changedTestRenderFn }));
147
- // expect the new value to be rendered
148
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(2);
149
- expect(await findByText(DIFFERENT_CONTENT)).toBeTruthy();
150
- });
151
- it('should provide an onUnmount API method to be called with the container element when destroying the extension', () => {
152
- onMountCallbackSpy.mockImplementation((container) => {
153
- expect(container).toHaveProperty('innerHTML');
154
- });
155
- const { unmount } = react_1.render(React.createElement(TestComponent, null));
156
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
157
- unmount();
158
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);
159
- });
160
- it('should only call cleanUp callback if the extension changes or the container is destroyed', () => {
161
- const { rerender, unmount } = react_1.render(React.createElement(TestComponent, null));
162
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
163
- rerender(React.createElement(TestComponent, null));
164
- // the container rerenders with the same extension render prop, so no need to call cleanup
165
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
166
- rerender(React.createElement(TestComponent, { render: changedTestRenderFn }));
167
- // the extension render prop changed, so cleanup is called
168
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);
169
- unmount();
170
- // the container is destroyed, so cleanup is called
171
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(2);
172
- });
173
- });
174
- describe('ModalWithActionHandler', () => {
175
- const modalButtonText = 'My Modal';
176
- it('should render a button to handle the modal', () => {
177
- const { queryByText } = react_1.render(React.createElement(TestComponentWithActionHandler, null, modalButtonText));
178
- expect(queryByText(modalButtonText)).toBeTruthy();
179
- });
180
- it('should receive an isOpen prop to set the modal as open', () => {
181
- var _a;
182
- const { queryByRole, queryByText } = react_1.render(React.createElement(TestComponentWithActionHandler, null, modalButtonText));
183
- expect(queryByRole('dialog')).toBeFalsy();
184
- (_a = queryByText(modalButtonText)) === null || _a === void 0 ? void 0 : _a.click();
185
- expect(queryByRole('dialog')).toBeTruthy();
186
- });
187
- });
188
- });
189
- //# 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,qDAA+B;AAC/B,kDAA2D;AAK3D,iDAAsE;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;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D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;;YAC9D,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,cAAM,CAAC,oBAAC,8BAA8B,QAAE,eAAe,CAAkC,CAAC,CAAC;YAEhI,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;YAE1C,MAAA,WAAW,CAAC,eAAe,CAAC,0CAAE,KAAK,GAAG;YAEtC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable jest/no-commented-out-tests */\n/* eslint-disable react/jsx-boolean-value */\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"]}
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const React = tslib_1.__importStar(require("react"));
5
- const react_1 = require("@testing-library/react");
6
- const PanelHandler_1 = require("./PanelHandler");
7
- const onMountCallbackSpy = jest.fn();
8
- const onUnmountCallbackSpy = jest.fn();
9
- // onAction method of an Extension
10
- const testRenderFn = (api) => {
11
- api.onMount(onMountCallbackSpy);
12
- api.onUnmount(onUnmountCallbackSpy);
13
- };
14
- // onAction method of an Extension
15
- // When an attribute of the extension changes, the useExtensions hook returns a completly new descriptor object
16
- // This function is used to replicate that behaviour.
17
- const changedTestRenderFn = (api) => {
18
- api.onMount(onMountCallbackSpy);
19
- api.onUnmount(onUnmountCallbackSpy);
20
- };
21
- // eslint-disable-next-line @typescript-eslint/no-shadow
22
- const TestComponent = ({ render, RootType }) => {
23
- return React.createElement(PanelHandler_1.PanelHandler, { render: render, RootType: RootType });
24
- };
25
- describe('PanelHandler', () => {
26
- beforeEach(() => {
27
- onMountCallbackSpy.mockReset();
28
- onUnmountCallbackSpy.mockReset();
29
- });
30
- it('should provide an onMount API method to render custom HTML in a container', async () => {
31
- const CUSTOM_CONTENT = 'Custom content';
32
- onMountCallbackSpy.mockImplementationOnce((container) => {
33
- container.innerHTML = CUSTOM_CONTENT;
34
- });
35
- const { findByText } = react_1.render(React.createElement(TestComponent, { render: testRenderFn }));
36
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
37
- expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
38
- });
39
- it('should only rerender the extension content if something in the extension descriptor changed', async () => {
40
- const CUSTOM_CONTENT = 'Custom content';
41
- const DIFFERENT_CONTENT = 'Different content';
42
- onMountCallbackSpy
43
- .mockImplementationOnce((container) => {
44
- container.innerHTML = CUSTOM_CONTENT;
45
- })
46
- .mockImplementationOnce((container) => {
47
- container.innerHTML = DIFFERENT_CONTENT;
48
- });
49
- const { findByText, rerender } = react_1.render(React.createElement(TestComponent, { render: testRenderFn }));
50
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
51
- expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
52
- // expect nothing to change
53
- rerender(React.createElement(TestComponent, { render: testRenderFn }));
54
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
55
- expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
56
- // expect the new value to be rendered when render function did changed
57
- rerender(React.createElement(TestComponent, { render: changedTestRenderFn }));
58
- expect(onMountCallbackSpy).toHaveBeenCalledTimes(2);
59
- expect(await findByText(DIFFERENT_CONTENT)).toBeTruthy();
60
- });
61
- it('should provide an onUnmount API method to be called with the container element when destroying the extension', () => {
62
- onMountCallbackSpy.mockImplementation((container) => {
63
- expect(container).toHaveProperty('innerHTML');
64
- });
65
- const { unmount } = react_1.render(React.createElement(TestComponent, { render: changedTestRenderFn }));
66
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
67
- unmount();
68
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);
69
- });
70
- it('should only call cleanUp callback if the extension changes or the container is destroyed', () => {
71
- const { rerender, unmount } = react_1.render(React.createElement(TestComponent, { render: testRenderFn }));
72
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
73
- // the container rerenders with the same extension descriptor, so no need to call cleanup
74
- rerender(React.createElement(TestComponent, { render: testRenderFn }));
75
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
76
- // the extension descriptor changed, so cleanup is called
77
- rerender(React.createElement(TestComponent, { render: changedTestRenderFn }));
78
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);
79
- // the container is destroyed, so cleanup is called
80
- unmount();
81
- expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(2);
82
- });
83
- it('should allow to specify a span element as a container', () => {
84
- const { asFragment } = react_1.render(React.createElement(TestComponent, { render: testRenderFn, RootType: "span" }));
85
- expect(asFragment().firstElementChild).toMatchInlineSnapshot(`<span />`);
86
- });
87
- });
88
- //# sourceMappingURL=PanelHandler.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PanelHandler.test.js","sourceRoot":"","sources":["../../../lib/handlers/PanelHandler.test.tsx"],"names":[],"mappings":";;;AAAA,qDAA+B;AAC/B,kDAAgD;AAIhD,iDAA8C;AAE9C,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACrC,MAAM,oBAAoB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEvC,kCAAkC;AAClC,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,kCAAkC;AAClC,+GAA+G;AAC/G,qDAAqD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ent":["import * as React from 'react';\nimport { render } from '@testing-library/react';\n\nimport type { PanelExtension } from '@atlassian/clientside-extensions';\nimport type { PanelHandlerProps } from './PanelHandler';\nimport { PanelHandler } from './PanelHandler';\n\nconst onMountCallbackSpy = jest.fn();\nconst onUnmountCallbackSpy = jest.fn();\n\n// onAction method of an Extension\nconst testRenderFn: PanelExtension.PanelRenderExtension = (api) => {\n api.onMount(onMountCallbackSpy);\n api.onUnmount(onUnmountCallbackSpy);\n};\n\n// onAction method of an Extension\n// When an attribute of the extension changes, the useExtensions hook returns a completly new descriptor object\n// This function is used to replicate that behaviour.\nconst changedTestRenderFn: PanelExtension.PanelRenderExtension = (api) => {\n api.onMount(onMountCallbackSpy);\n api.onUnmount(onUnmountCallbackSpy);\n};\n\n// eslint-disable-next-line @typescript-eslint/no-shadow\nconst TestComponent = ({ render, RootType }: PanelHandlerProps) => {\n return <PanelHandler render={render} RootType={RootType} />;\n};\n\ndescribe('PanelHandler', () => {\n beforeEach(() => {\n onMountCallbackSpy.mockReset();\n onUnmountCallbackSpy.mockReset();\n });\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 render={testRenderFn} />);\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\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 render={testRenderFn} />);\n\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);\n expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();\n\n // expect nothing to change\n rerender(<TestComponent render={testRenderFn} />);\n\n expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);\n expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();\n\n // expect the new value to be rendered when render function did changed\n rerender(<TestComponent render={changedTestRenderFn} />);\n\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 render={changedTestRenderFn} />);\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 render={testRenderFn} />);\n\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);\n\n // the container rerenders with the same extension descriptor, so no need to call cleanup\n rerender(<TestComponent render={testRenderFn} />);\n\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);\n\n // the extension descriptor changed, so cleanup is called\n rerender(<TestComponent render={changedTestRenderFn} />);\n\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);\n\n // the container is destroyed, so cleanup is called\n unmount();\n\n expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(2);\n });\n\n it('should allow to specify a span element as a container', () => {\n const { asFragment } = render(<TestComponent render={testRenderFn} RootType=\"span\" />);\n\n expect(asFragment().firstElementChild).toMatchInlineSnapshot(`<span />`);\n });\n});\n"]}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const React = tslib_1.__importStar(require("react"));
5
- const react_1 = require("@testing-library/react");
6
- const SectionHandler_1 = require("./SectionHandler");
7
- const TestComponent = ({ children }) => {
8
- return React.createElement(SectionHandler_1.SectionHandler, null, children);
9
- };
10
- describe('SectionHandler', () => {
11
- it('should render the children passed to it', async () => {
12
- const { findByText } = react_1.render(React.createElement(TestComponent, null,
13
- React.createElement("div", null, "some children")));
14
- expect(await findByText('some children')).toBeTruthy();
15
- });
16
- });
17
- //# sourceMappingURL=SectionHandler.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SectionHandler.test.js","sourceRoot":"","sources":["../../../lib/handlers/SectionHandler.test.tsx"],"names":[],"mappings":";;;AACA,qDAA+B;AAC/B,kDAAgD;AAEhD,qDAAkD;AAElD,MAAM,aAAa,GAAsB,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtD,OAAO,oBAAC,+BAAc,QAAE,QAAQ,CAAkB,CAAC;AACvD,CAAC,CAAC;AAEF,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,EAAE,UAAU,EAAE,GAAG,cAAM,CACzB,oBAAC,aAAa;YACV,iDAAwB,CACZ,CACnB,CAAC;QAEF,MAAM,CAAC,MAAM,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import type { FunctionComponent } from 'react';\nimport * as React from 'react';\nimport { render } from '@testing-library/react';\n\nimport { SectionHandler } from './SectionHandler';\n\nconst TestComponent: FunctionComponent = ({ children }) => {\n return <SectionHandler>{children}</SectionHandler>;\n};\n\ndescribe('SectionHandler', () => {\n it('should render the children passed to it', async () => {\n const { findByText } = render(\n <TestComponent>\n <div>some children</div>\n </TestComponent>,\n );\n\n expect(await findByText('some children')).toBeTruthy();\n });\n});\n"]}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- describe('force coverage', () => {
3
- it('should assert', () => {
4
- expect(true).toBe(true);
5
- });
6
- });
7
- //# sourceMappingURL=index.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../lib/index.test.ts"],"names":[],"mappings":";AAAA,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,eAAe,EAAE,GAAG,EAAE;QACrB,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["describe('force coverage', () => {\n it('should assert', () => {\n expect(true).toBe(true);\n });\n});\n"]}
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const react_1 = tslib_1.__importDefault(require("react"));
5
- const dom_1 = require("@testing-library/dom");
6
- const renderElementAsReact_1 = tslib_1.__importDefault(require("./renderElementAsReact"));
7
- /* eslint-enable react/no-unused-prop-types */
8
- describe('renderElementAsReact', () => {
9
- let testContainer;
10
- let onMountCallback;
11
- let onUnmountCallback;
12
- const testRenderAPI = {
13
- onMount: (callback) => {
14
- onMountCallback = callback;
15
- return testRenderAPI;
16
- },
17
- onUnmount: (callback) => {
18
- onUnmountCallback = callback;
19
- return testRenderAPI;
20
- },
21
- };
22
- const TestComponent = (props) => (react_1.default.createElement("div", { "data-testid": "test-component" },
23
- react_1.default.createElement("h2", null, "A test content"),
24
- react_1.default.createElement("p", { "data-testid": "test-props" }, JSON.stringify(props))));
25
- beforeEach(() => {
26
- testContainer = document.createElement('div');
27
- });
28
- it('should use the renderApi to mount and unmount the given react component', () => {
29
- const getTestComponent = () => dom_1.queryByTestId(testContainer, 'test-component');
30
- renderElementAsReact_1.default(testRenderAPI, TestComponent);
31
- // expect the component NOT to be rendered until onMount is called by the handler
32
- expect(getTestComponent()).toBeFalsy();
33
- onMountCallback(testContainer);
34
- // rendered using onMount
35
- expect(getTestComponent()).toBeTruthy();
36
- expect(getTestComponent().textContent).toMatch('A test content');
37
- onUnmountCallback(testContainer);
38
- // destroyed using onUnmount
39
- expect(getTestComponent()).toBeFalsy();
40
- });
41
- it('should receive additional props to assing to the given react component', () => {
42
- const testProps = {
43
- name: 'Meaning of life',
44
- value: 42,
45
- };
46
- renderElementAsReact_1.default(testRenderAPI, TestComponent, testProps);
47
- onMountCallback(testContainer);
48
- const testPropsElement = dom_1.queryByTestId(testContainer, 'test-props');
49
- // props applied to the component when rendering
50
- expect(testPropsElement).toBeTruthy();
51
- expect(JSON.parse(testPropsElement.textContent)).toMatchObject(testProps);
52
- });
53
- });
54
- //# sourceMappingURL=renderElementAsReact.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderElementAsReact.test.js","sourceRoot":"","sources":["../../lib/renderElementAsReact.test.tsx"],"names":[],"mappings":";;;AAAA,0DAA0B;AAC1B,8CAAqD;AAGrD,0FAA0D;AAO1D,8CAA8C;AAE9C,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAClC,IAAI,aAA0B,CAAC;IAC/B,IAAI,eAA+C,CAAC;IACpD,IAAI,iBAAiD,CAAC;IAEtD,MAAM,aAAa,GAAuB;QACtC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE;YAClB,eAAe,GAAG,QAAQ,CAAC;YAC3B,OAAO,aAAa,CAAC;QACzB,CAAC;QACD,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACpB,iBAAiB,GAAG,QAAQ,CAAC;YAC7B,OAAO,aAAa,CAAC;QACzB,CAAC;KACJ,CAAC;IAEF,MAAM,aAAa,GAAwB,CAAC,KAAK,EAAE,EAAE,CAAC,CAClD,sDAAiB,gBAAgB;QAC7B,2DAAuB;QACvB,oDAAe,YAAY,IAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAK,CACrD,CACT,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACZ,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,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-library/dom';\n\nimport type { MountableExtension } from '@atlassian/clientside-extensions';\nimport renderElementAsReact from './renderElementAsReact';\n\n/* eslint-disable react/no-unused-prop-types */\ninterface TestProps {\n name?: string;\n value?: number;\n}\n/* eslint-enable react/no-unused-prop-types */\n\ndescribe('renderElementAsReact', () => {\n let testContainer: HTMLElement;\n let onMountCallback: (element: HTMLElement) => void;\n let onUnmountCallback: (element: HTMLElement) => void;\n\n const testRenderAPI: MountableExtension = {\n onMount: (callback) => {\n onMountCallback = callback;\n return testRenderAPI;\n },\n onUnmount: (callback) => {\n onUnmountCallback = callback;\n return testRenderAPI;\n },\n };\n\n const TestComponent: React.FC<TestProps> = (props) => (\n <div data-testid=\"test-component\">\n <h2>A test content</h2>\n <p data-testid=\"test-props\">{JSON.stringify(props)}</p>\n </div>\n );\n\n beforeEach(() => {\n testContainer = document.createElement('div');\n });\n\n it('should use the renderApi to mount and unmount the given react component', () => {\n const getTestComponent = () => queryByTestId(testContainer, 'test-component') as HTMLElement;\n\n renderElementAsReact(testRenderAPI, TestComponent);\n\n // expect the component NOT to be rendered until onMount is called by the handler\n expect(getTestComponent()).toBeFalsy();\n\n onMountCallback(testContainer);\n\n // rendered using onMount\n expect(getTestComponent()).toBeTruthy();\n expect(getTestComponent().textContent).toMatch('A test content');\n\n onUnmountCallback(testContainer);\n\n // destroyed using onUnmount\n expect(getTestComponent()).toBeFalsy();\n });\n\n it('should receive additional props to assing to the given react component', () => {\n const testProps: TestProps = {\n name: 'Meaning of life',\n value: 42,\n };\n\n renderElementAsReact(testRenderAPI, TestComponent, testProps);\n onMountCallback(testContainer);\n\n const testPropsElement = queryByTestId(testContainer, 'test-props') as HTMLElement;\n\n // props applied to the component when rendering\n expect(testPropsElement).toBeTruthy();\n expect(JSON.parse(testPropsElement.textContent as string)).toMatchObject(testProps);\n });\n});\n"]}