@atlassian/clientside-extensions-components 2.4.1 → 2.5.0-84fa90d-kwd5ix2w
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ExtensionPoint.js +4 -4
- package/dist/cjs/ExtensionPoint.js.map +1 -1
- package/dist/cjs/ExtensionPointInfo.js +8 -8
- package/dist/cjs/ExtensionPointInfo.js.map +1 -1
- package/dist/cjs/ExtensionsObservable.js +14 -12
- package/dist/cjs/ExtensionsObservable.js.map +1 -1
- package/dist/cjs/debug/useDebug.js +3 -3
- package/dist/cjs/debug/useDebug.js.map +1 -1
- package/dist/cjs/debug/useDiscovery.js +3 -3
- package/dist/cjs/debug/useDiscovery.js.map +1 -1
- package/dist/cjs/debug/useLogging.js +3 -3
- package/dist/cjs/debug/useLogging.js.map +1 -1
- package/dist/cjs/debug/useValidation.js +3 -3
- package/dist/cjs/debug/useValidation.js.map +1 -1
- package/dist/cjs/handlers/AsyncPanelHandler.js +10 -9
- package/dist/cjs/handlers/AsyncPanelHandler.js.map +1 -1
- package/dist/cjs/handlers/ButtonHandler.js +4 -3
- package/dist/cjs/handlers/ButtonHandler.js.map +1 -1
- package/dist/cjs/handlers/LinkHandler.js +4 -3
- package/dist/cjs/handlers/LinkHandler.js.map +1 -1
- package/dist/cjs/handlers/ModalHandler.js +16 -14
- package/dist/cjs/handlers/ModalHandler.js.map +1 -1
- package/dist/cjs/handlers/PanelHandler.js +6 -5
- package/dist/cjs/handlers/PanelHandler.js.map +1 -1
- package/dist/cjs/handlers/SectionHandler.js +3 -2
- package/dist/cjs/handlers/SectionHandler.js.map +1 -1
- package/dist/cjs/handlers/index.js +1 -0
- package/dist/cjs/handlers/index.js.map +1 -1
- package/dist/cjs/index.js +11 -10
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/renderElementAsReact.js +3 -3
- package/dist/cjs/renderElementAsReact.js.map +1 -1
- package/dist/cjs/styled.js +13 -13
- package/dist/cjs/styled.js.map +1 -1
- package/dist/cjs/useExtensions.js +18 -14
- package/dist/cjs/useExtensions.js.map +1 -1
- package/dist/cjs/useWebPanelRenderer.js +4 -4
- package/dist/cjs/useWebPanelRenderer.js.map +1 -1
- package/dist/esm/ExtensionPointInfo.js.map +1 -1
- package/dist/esm/ExtensionsObservable.js.map +1 -1
- package/dist/esm/debug/types.js +1 -0
- package/dist/esm/handlers/types.js +1 -0
- package/dist/esm/renderElementAsReact.js +1 -1
- package/dist/esm/renderElementAsReact.js.map +1 -1
- package/dist/esm/useWebPanelRenderer.js.map +1 -1
- package/dist/types/ExtensionPointInfo.d.ts.map +1 -1
- package/dist/types/styled.d.ts +7 -7
- package/dist/types/styled.d.ts.map +1 -1
- package/lib/ExtensionPointInfo.tsx +1 -0
- package/lib/ExtensionsObservable.test.ts +2 -2
- package/package.json +12 -11
- package/dist/cjs/ExtensionPoint.test.js +0 -96
- package/dist/cjs/ExtensionPoint.test.js.map +0 -1
- package/dist/cjs/ExtensionPointInfo.test.js +0 -189
- package/dist/cjs/ExtensionPointInfo.test.js.map +0 -1
- package/dist/cjs/ExtensionsObservable.test.js +0 -349
- package/dist/cjs/ExtensionsObservable.test.js.map +0 -1
- package/dist/cjs/debug/useDebug.test.js +0 -49
- package/dist/cjs/debug/useDebug.test.js.map +0 -1
- package/dist/cjs/debug/useDiscovery.test.js +0 -49
- package/dist/cjs/debug/useDiscovery.test.js.map +0 -1
- package/dist/cjs/debug/useLogging.test.js +0 -49
- package/dist/cjs/debug/useLogging.test.js.map +0 -1
- package/dist/cjs/debug/useValidation.test.js +0 -49
- package/dist/cjs/debug/useValidation.test.js.map +0 -1
- package/dist/cjs/handlers/AsyncPanelHandler.test.js +0 -189
- package/dist/cjs/handlers/AsyncPanelHandler.test.js.map +0 -1
- package/dist/cjs/handlers/ButtonHandler.test.js +0 -40
- package/dist/cjs/handlers/ButtonHandler.test.js.map +0 -1
- package/dist/cjs/handlers/LinkHandler.test.js +0 -43
- package/dist/cjs/handlers/LinkHandler.test.js.map +0 -1
- package/dist/cjs/handlers/ModalHandler.test.js +0 -189
- package/dist/cjs/handlers/ModalHandler.test.js.map +0 -1
- package/dist/cjs/handlers/PanelHandler.test.js +0 -88
- package/dist/cjs/handlers/PanelHandler.test.js.map +0 -1
- package/dist/cjs/handlers/SectionHandler.test.js +0 -17
- package/dist/cjs/handlers/SectionHandler.test.js.map +0 -1
- package/dist/cjs/index.test.js +0 -7
- package/dist/cjs/index.test.js.map +0 -1
- package/dist/cjs/renderElementAsReact.test.js +0 -54
- package/dist/cjs/renderElementAsReact.test.js.map +0 -1
- package/dist/cjs/useExtensions.test.js +0 -647
- package/dist/cjs/useExtensions.test.js.map +0 -1
- package/dist/esm/ExtensionPoint.test.js +0 -93
- package/dist/esm/ExtensionPoint.test.js.map +0 -1
- package/dist/esm/ExtensionPointInfo.test.js +0 -186
- package/dist/esm/ExtensionPointInfo.test.js.map +0 -1
- package/dist/esm/ExtensionsObservable.test.js +0 -346
- package/dist/esm/ExtensionsObservable.test.js.map +0 -1
- package/dist/esm/debug/useDebug.test.js +0 -46
- package/dist/esm/debug/useDebug.test.js.map +0 -1
- package/dist/esm/debug/useDiscovery.test.js +0 -46
- package/dist/esm/debug/useDiscovery.test.js.map +0 -1
- package/dist/esm/debug/useLogging.test.js +0 -46
- package/dist/esm/debug/useLogging.test.js.map +0 -1
- package/dist/esm/debug/useValidation.test.js +0 -46
- package/dist/esm/debug/useValidation.test.js.map +0 -1
- package/dist/esm/handlers/AsyncPanelHandler.test.js +0 -186
- package/dist/esm/handlers/AsyncPanelHandler.test.js.map +0 -1
- package/dist/esm/handlers/ButtonHandler.test.js +0 -37
- package/dist/esm/handlers/ButtonHandler.test.js.map +0 -1
- package/dist/esm/handlers/LinkHandler.test.js +0 -40
- package/dist/esm/handlers/LinkHandler.test.js.map +0 -1
- package/dist/esm/handlers/ModalHandler.test.js +0 -186
- package/dist/esm/handlers/ModalHandler.test.js.map +0 -1
- package/dist/esm/handlers/PanelHandler.test.js +0 -85
- package/dist/esm/handlers/PanelHandler.test.js.map +0 -1
- package/dist/esm/handlers/SectionHandler.test.js +0 -14
- package/dist/esm/handlers/SectionHandler.test.js.map +0 -1
- package/dist/esm/index.test.js +0 -7
- package/dist/esm/index.test.js.map +0 -1
- package/dist/esm/renderElementAsReact.test.js +0 -51
- package/dist/esm/renderElementAsReact.test.js.map +0 -1
- package/dist/esm/useExtensions.test.js +0 -644
- package/dist/esm/useExtensions.test.js.map +0 -1
- package/dist/types/ExtensionPoint.test.d.ts +0 -2
- package/dist/types/ExtensionPoint.test.d.ts.map +0 -1
- package/dist/types/ExtensionPointInfo.test.d.ts +0 -2
- package/dist/types/ExtensionPointInfo.test.d.ts.map +0 -1
- package/dist/types/ExtensionsObservable.test.d.ts +0 -2
- package/dist/types/ExtensionsObservable.test.d.ts.map +0 -1
- package/dist/types/debug/useDebug.test.d.ts +0 -2
- package/dist/types/debug/useDebug.test.d.ts.map +0 -1
- package/dist/types/debug/useDiscovery.test.d.ts +0 -2
- package/dist/types/debug/useDiscovery.test.d.ts.map +0 -1
- package/dist/types/debug/useLogging.test.d.ts +0 -2
- package/dist/types/debug/useLogging.test.d.ts.map +0 -1
- package/dist/types/debug/useValidation.test.d.ts +0 -2
- package/dist/types/debug/useValidation.test.d.ts.map +0 -1
- package/dist/types/handlers/AsyncPanelHandler.test.d.ts +0 -2
- package/dist/types/handlers/AsyncPanelHandler.test.d.ts.map +0 -1
- package/dist/types/handlers/ButtonHandler.test.d.ts +0 -2
- package/dist/types/handlers/ButtonHandler.test.d.ts.map +0 -1
- package/dist/types/handlers/LinkHandler.test.d.ts +0 -2
- package/dist/types/handlers/LinkHandler.test.d.ts.map +0 -1
- package/dist/types/handlers/ModalHandler.test.d.ts +0 -2
- package/dist/types/handlers/ModalHandler.test.d.ts.map +0 -1
- package/dist/types/handlers/PanelHandler.test.d.ts +0 -2
- package/dist/types/handlers/PanelHandler.test.d.ts.map +0 -1
- package/dist/types/handlers/SectionHandler.test.d.ts +0 -2
- package/dist/types/handlers/SectionHandler.test.d.ts.map +0 -1
- package/dist/types/index.test.d.ts +0 -1
- package/dist/types/index.test.d.ts.map +0 -1
- package/dist/types/renderElementAsReact.test.d.ts +0 -2
- package/dist/types/renderElementAsReact.test.d.ts.map +0 -1
- package/dist/types/useExtensions.test.d.ts +0 -2
- package/dist/types/useExtensions.test.d.ts.map +0 -1
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { PanelHandler } from './PanelHandler';
|
|
4
|
-
const onMountCallbackSpy = jest.fn();
|
|
5
|
-
const onUnmountCallbackSpy = jest.fn();
|
|
6
|
-
// onAction method of an Extension
|
|
7
|
-
const testRenderFn = (api) => {
|
|
8
|
-
api.onMount(onMountCallbackSpy);
|
|
9
|
-
api.onUnmount(onUnmountCallbackSpy);
|
|
10
|
-
};
|
|
11
|
-
// onAction method of an Extension
|
|
12
|
-
// When an attribute of the extension changes, the useExtensions hook returns a completly new descriptor object
|
|
13
|
-
// This function is used to replicate that behaviour.
|
|
14
|
-
const changedTestRenderFn = (api) => {
|
|
15
|
-
api.onMount(onMountCallbackSpy);
|
|
16
|
-
api.onUnmount(onUnmountCallbackSpy);
|
|
17
|
-
};
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
19
|
-
const TestComponent = ({ render, RootType }) => {
|
|
20
|
-
return React.createElement(PanelHandler, { render: render, RootType: RootType });
|
|
21
|
-
};
|
|
22
|
-
describe('PanelHandler', () => {
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
onMountCallbackSpy.mockReset();
|
|
25
|
-
onUnmountCallbackSpy.mockReset();
|
|
26
|
-
});
|
|
27
|
-
it('should provide an onMount API method to render custom HTML in a container', async () => {
|
|
28
|
-
const CUSTOM_CONTENT = 'Custom content';
|
|
29
|
-
onMountCallbackSpy.mockImplementationOnce((container) => {
|
|
30
|
-
container.innerHTML = CUSTOM_CONTENT;
|
|
31
|
-
});
|
|
32
|
-
const { findByText } = render(React.createElement(TestComponent, { render: testRenderFn }));
|
|
33
|
-
expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
|
|
34
|
-
expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
|
|
35
|
-
});
|
|
36
|
-
it('should only rerender the extension content if something in the extension descriptor changed', async () => {
|
|
37
|
-
const CUSTOM_CONTENT = 'Custom content';
|
|
38
|
-
const DIFFERENT_CONTENT = 'Different content';
|
|
39
|
-
onMountCallbackSpy
|
|
40
|
-
.mockImplementationOnce((container) => {
|
|
41
|
-
container.innerHTML = CUSTOM_CONTENT;
|
|
42
|
-
})
|
|
43
|
-
.mockImplementationOnce((container) => {
|
|
44
|
-
container.innerHTML = DIFFERENT_CONTENT;
|
|
45
|
-
});
|
|
46
|
-
const { findByText, rerender } = render(React.createElement(TestComponent, { render: testRenderFn }));
|
|
47
|
-
expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
|
|
48
|
-
expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
|
|
49
|
-
// expect nothing to change
|
|
50
|
-
rerender(React.createElement(TestComponent, { render: testRenderFn }));
|
|
51
|
-
expect(onMountCallbackSpy).toHaveBeenCalledTimes(1);
|
|
52
|
-
expect(await findByText(CUSTOM_CONTENT)).toBeTruthy();
|
|
53
|
-
// expect the new value to be rendered when render function did changed
|
|
54
|
-
rerender(React.createElement(TestComponent, { render: changedTestRenderFn }));
|
|
55
|
-
expect(onMountCallbackSpy).toHaveBeenCalledTimes(2);
|
|
56
|
-
expect(await findByText(DIFFERENT_CONTENT)).toBeTruthy();
|
|
57
|
-
});
|
|
58
|
-
it('should provide an onUnmount API method to be called with the container element when destroying the extension', () => {
|
|
59
|
-
onMountCallbackSpy.mockImplementation((container) => {
|
|
60
|
-
expect(container).toHaveProperty('innerHTML');
|
|
61
|
-
});
|
|
62
|
-
const { unmount } = render(React.createElement(TestComponent, { render: changedTestRenderFn }));
|
|
63
|
-
expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
|
|
64
|
-
unmount();
|
|
65
|
-
expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);
|
|
66
|
-
});
|
|
67
|
-
it('should only call cleanUp callback if the extension changes or the container is destroyed', () => {
|
|
68
|
-
const { rerender, unmount } = render(React.createElement(TestComponent, { render: testRenderFn }));
|
|
69
|
-
expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
|
|
70
|
-
// the container rerenders with the same extension descriptor, so no need to call cleanup
|
|
71
|
-
rerender(React.createElement(TestComponent, { render: testRenderFn }));
|
|
72
|
-
expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(0);
|
|
73
|
-
// the extension descriptor changed, so cleanup is called
|
|
74
|
-
rerender(React.createElement(TestComponent, { render: changedTestRenderFn }));
|
|
75
|
-
expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(1);
|
|
76
|
-
// the container is destroyed, so cleanup is called
|
|
77
|
-
unmount();
|
|
78
|
-
expect(onUnmountCallbackSpy).toHaveBeenCalledTimes(2);
|
|
79
|
-
});
|
|
80
|
-
it('should allow to specify a span element as a container', () => {
|
|
81
|
-
const { asFragment } = render(React.createElement(TestComponent, { render: testRenderFn, RootType: "span" }));
|
|
82
|
-
expect(asFragment().firstElementChild).toMatchInlineSnapshot(`<span />`);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
//# 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,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAIhD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACrC,MAAM,oBAAoB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AM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,oBAAC,aAAa,IAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAC,MAAM,GAAG,CAAC,CAAC;QAEvF,MAAM,CAAC,UAAU,EAAE,CAAC,iBAAiB,CAAC,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["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,14 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { SectionHandler } from './SectionHandler';
|
|
4
|
-
const TestComponent = ({ children }) => {
|
|
5
|
-
return React.createElement(SectionHandler, null, children);
|
|
6
|
-
};
|
|
7
|
-
describe('SectionHandler', () => {
|
|
8
|
-
it('should render the children passed to it', async () => {
|
|
9
|
-
const { findByText } = render(React.createElement(TestComponent, null,
|
|
10
|
-
React.createElement("div", null, "some children")));
|
|
11
|
-
expect(await findByText('some children')).toBeTruthy();
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
//# 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,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,aAAa,GAAsB,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtD,OAAO,oBAAC,cAAc,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,MAAM,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"]}
|
package/dist/esm/index.test.js
DELETED
|
@@ -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,51 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { queryByTestId } from '@testing-library/dom';
|
|
3
|
-
import renderElementAsReact from './renderElementAsReact';
|
|
4
|
-
/* eslint-enable react/no-unused-prop-types */
|
|
5
|
-
describe('renderElementAsReact', () => {
|
|
6
|
-
let testContainer;
|
|
7
|
-
let onMountCallback;
|
|
8
|
-
let onUnmountCallback;
|
|
9
|
-
const testRenderAPI = {
|
|
10
|
-
onMount: (callback) => {
|
|
11
|
-
onMountCallback = callback;
|
|
12
|
-
return testRenderAPI;
|
|
13
|
-
},
|
|
14
|
-
onUnmount: (callback) => {
|
|
15
|
-
onUnmountCallback = callback;
|
|
16
|
-
return testRenderAPI;
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
const TestComponent = (props) => (React.createElement("div", { "data-testid": "test-component" },
|
|
20
|
-
React.createElement("h2", null, "A test content"),
|
|
21
|
-
React.createElement("p", { "data-testid": "test-props" }, JSON.stringify(props))));
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
testContainer = document.createElement('div');
|
|
24
|
-
});
|
|
25
|
-
it('should use the renderApi to mount and unmount the given react component', () => {
|
|
26
|
-
const getTestComponent = () => queryByTestId(testContainer, 'test-component');
|
|
27
|
-
renderElementAsReact(testRenderAPI, TestComponent);
|
|
28
|
-
// expect the component NOT to be rendered until onMount is called by the handler
|
|
29
|
-
expect(getTestComponent()).toBeFalsy();
|
|
30
|
-
onMountCallback(testContainer);
|
|
31
|
-
// rendered using onMount
|
|
32
|
-
expect(getTestComponent()).toBeTruthy();
|
|
33
|
-
expect(getTestComponent().textContent).toMatch('A test content');
|
|
34
|
-
onUnmountCallback(testContainer);
|
|
35
|
-
// destroyed using onUnmount
|
|
36
|
-
expect(getTestComponent()).toBeFalsy();
|
|
37
|
-
});
|
|
38
|
-
it('should receive additional props to assing to the given react component', () => {
|
|
39
|
-
const testProps = {
|
|
40
|
-
name: 'Meaning of life',
|
|
41
|
-
value: 42,
|
|
42
|
-
};
|
|
43
|
-
renderElementAsReact(testRenderAPI, TestComponent, testProps);
|
|
44
|
-
onMountCallback(testContainer);
|
|
45
|
-
const testPropsElement = queryByTestId(testContainer, 'test-props');
|
|
46
|
-
// props applied to the component when rendering
|
|
47
|
-
expect(testPropsElement).toBeTruthy();
|
|
48
|
-
expect(JSON.parse(testPropsElement.textContent)).toMatchObject(testProps);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
//# sourceMappingURL=renderElementAsReact.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderElementAsReact.test.js","sourceRoot":"","sources":["../../lib/renderElementAsReact.test.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MA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jE,iBAAiB,CAAC,aAAa,CAAC,CAAC;QAEjC,4BAA4B;QAC5B,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wEAAwE,EAAE,GAAG,EAAE;QAC9E,MAAM,SAAS,GAAc;YACzB,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,EAAE;SACZ,CAAC;QAEF,oBAAoB,CAAC,aAAa,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QAC9D,eAAe,CAAC,aAAa,CAAC,CAAC;QAE/B,MAAM,gBAAgB,GAAG,aAAa,CAAC,aAAa,EAAE,YAAY,CAAgB,CAAC;QAEnF,gDAAgD;QAChD,MAAM,CAAC,gBAAgB,CAAC,CAAC,UAAU,EAAE,CAAC;QACtC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,WAAqB,CAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import React from 'react';\nimport { queryByTestId } from '@testing-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"]}
|