@forge/react
Advanced tools
| export {}; | ||
| //# sourceMappingURL=useConfig.test.d.ts.map |
| {"version":3,"file":"useConfig.test.d.ts","sourceRoot":"","sources":["../../../src/hooks/__test__/useConfig.test.tsx"],"names":[],"mappings":""} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const tslib_1 = require("tslib"); | ||
| const jsx_runtime_1 = require("react/jsx-runtime"); | ||
| const mockGetContext = jest.fn(async () => null); | ||
| const react_1 = tslib_1.__importStar(require("react")); | ||
| const reconcilerTestRenderer_1 = tslib_1.__importDefault(require("../../__test__/reconcilerTestRenderer")); | ||
| const useConfig_1 = require("../useConfig"); | ||
| const testUtils_1 = require("../../__test__/testUtils"); | ||
| jest.mock('@forge/bridge', () => ({ | ||
| view: { | ||
| getContext: mockGetContext | ||
| } | ||
| })); | ||
| const MOCK_CONFIG = { | ||
| value: 1 | ||
| }; | ||
| const MOCK_CONTEXT_WITH_CONFIG = { | ||
| extension: { | ||
| config: MOCK_CONFIG | ||
| } | ||
| }; | ||
| const MOCK_CONTEXT_NO_CONFIG = { | ||
| extension: {} | ||
| }; | ||
| const configListener = jest.fn(); | ||
| const renderTest = async () => { | ||
| const Test = () => { | ||
| const config = (0, useConfig_1.useConfig)(); | ||
| (0, react_1.useEffect)(() => configListener(config), [config]); | ||
| return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, {}); | ||
| }; | ||
| await reconcilerTestRenderer_1.default.create((0, jsx_runtime_1.jsx)(Test, {})); | ||
| }; | ||
| describe('useConfig', () => { | ||
| beforeAll(() => (0, testUtils_1.setupBridge)()); | ||
| afterEach(() => jest.clearAllMocks()); | ||
| it('correctly outputs a given config', async () => { | ||
| mockGetContext.mockResolvedValue(MOCK_CONTEXT_WITH_CONFIG); | ||
| await renderTest(); | ||
| expect(configListener).toHaveBeenCalledWith(expect.objectContaining(MOCK_CONFIG)); | ||
| }); | ||
| it('when there is no config, outputs undefined', async () => { | ||
| mockGetContext.mockResolvedValue(MOCK_CONTEXT_NO_CONFIG); | ||
| await renderTest(); | ||
| expect(configListener.mock.calls[0][0]).toEqual(undefined); | ||
| expect(configListener).not.toHaveBeenNthCalledWith(2, expect.anything); | ||
| }); | ||
| }); |
| export {}; | ||
| //# sourceMappingURL=useProductContext.test.d.ts.map |
| {"version":3,"file":"useProductContext.test.d.ts","sourceRoot":"","sources":["../../../src/hooks/__test__/useProductContext.test.tsx"],"names":[],"mappings":""} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const tslib_1 = require("tslib"); | ||
| const jsx_runtime_1 = require("react/jsx-runtime"); | ||
| const mockGetContext = jest.fn(async () => null); | ||
| const useProductContext_1 = require("../useProductContext"); | ||
| const react_1 = tslib_1.__importStar(require("react")); | ||
| const testUtils_1 = require("../../__test__/testUtils"); | ||
| const reconcilerTestRenderer_1 = tslib_1.__importDefault(require("../../__test__/reconcilerTestRenderer")); | ||
| jest.mock('@forge/bridge', () => ({ | ||
| view: { | ||
| getContext: mockGetContext | ||
| } | ||
| })); | ||
| const MOCK_CONTEXT = { | ||
| accountId: 'client-accountId', | ||
| cloudId: 'DUMMY-cloudId', | ||
| extension: { contentId: 'DUMMY-contentId' }, | ||
| license: undefined, | ||
| localId: 'DUMMY-localId', | ||
| locale: 'DUMMY-locale', | ||
| moduleKey: 'DUMMY-moduleKey', | ||
| siteUrl: 'DUMMY-siteUrl', | ||
| timezone: 'DUMMY-timezone' | ||
| }; | ||
| const prodContListener = jest.fn(); | ||
| const renderTest = async () => { | ||
| const Test = () => { | ||
| const prodCont = (0, useProductContext_1.useProductContext)(); | ||
| (0, react_1.useEffect)(() => prodContListener(prodCont), [prodCont]); | ||
| return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, {}); | ||
| }; | ||
| await reconcilerTestRenderer_1.default.create((0, jsx_runtime_1.jsx)(Test, {})); | ||
| }; | ||
| describe('useProductContext', () => { | ||
| const LOAD_TIME = 500; | ||
| beforeAll(() => (0, testUtils_1.setupBridge)()); | ||
| afterEach(() => jest.clearAllMocks()); | ||
| it("automatically fetches data via bridge's view.getContext()", async () => { | ||
| await renderTest(); | ||
| expect(mockGetContext).toHaveBeenCalled(); | ||
| }); | ||
| it('corrently renders an expected ProductContext that is available upon load', async () => { | ||
| mockGetContext.mockResolvedValue(MOCK_CONTEXT); | ||
| await renderTest(); | ||
| expect(prodContListener.mock.calls[1][0]).toEqual(MOCK_CONTEXT); | ||
| }); | ||
| it('corrently renders an expected ProductContext that takes time to load', async () => { | ||
| mockGetContext.mockImplementation(async () => { | ||
| await new Promise((res) => setTimeout(res, LOAD_TIME)); | ||
| return MOCK_CONTEXT; | ||
| }); | ||
| await renderTest(); | ||
| expect(prodContListener).not.toHaveBeenNthCalledWith(2, expect.anything()); | ||
| await new Promise((res) => setTimeout(res, LOAD_TIME * 2)); | ||
| expect(prodContListener.mock.calls[1][0]).toEqual(MOCK_CONTEXT); | ||
| }, LOAD_TIME * 3); | ||
| }); |
| export declare const useConfig: () => any; | ||
| //# sourceMappingURL=useConfig.d.ts.map |
| {"version":3,"file":"useConfig.d.ts","sourceRoot":"","sources":["../../src/hooks/useConfig.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,WAGrB,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.useConfig = void 0; | ||
| const useProductContext_1 = require("./useProductContext"); | ||
| const useConfig = () => { | ||
| const context = (0, useProductContext_1.useProductContext)(); | ||
| return context === null || context === void 0 ? void 0 : context.extension.config; | ||
| }; | ||
| exports.useConfig = useConfig; |
| import { FullContext } from '@forge/bridge/out/types'; | ||
| export declare const useProductContext: () => FullContext | undefined; | ||
| //# sourceMappingURL=useProductContext.d.ts.map |
| {"version":3,"file":"useProductContext.d.ts","sourceRoot":"","sources":["../../src/hooks/useProductContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,eAAO,MAAM,iBAAiB,+BAa7B,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.useProductContext = void 0; | ||
| const bridge_1 = require("@forge/bridge"); | ||
| const react_1 = require("react"); | ||
| const useProductContext = () => { | ||
| const [productContext, setProductContext] = (0, react_1.useState)(); | ||
| (0, react_1.useEffect)(() => { | ||
| bridge_1.view | ||
| .getContext() | ||
| .then(setProductContext) | ||
| .catch((err) => { | ||
| throw err; | ||
| }); | ||
| }, []); | ||
| return productContext; | ||
| }; | ||
| exports.useProductContext = useProductContext; |
+8
-0
| # @forge/react | ||
| ## 9.2.0-next.1 | ||
| ### Minor Changes | ||
| - be57ee6: Created hooks for the package: | ||
| - useProductContext: outputs the app's environment context via @forge/bridge's view.getContext() | ||
| - useConfig: requests for product environment context and extracts the app's config (if available) | ||
| ## 9.2.0-next.0 | ||
@@ -4,0 +12,0 @@ |
+2
-0
@@ -0,1 +1,3 @@ | ||
| export { useProductContext } from './hooks/useProductContext'; | ||
| export { useConfig } from './hooks/useConfig'; | ||
| export { ForgeReconciler as default } from './reconciler'; | ||
@@ -2,0 +4,0 @@ export * from './components'; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAE1D,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAE1D,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"} |
+5
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.useSpaceProperty = exports.useContentProperty = exports.default = void 0; | ||
| exports.useSpaceProperty = exports.useContentProperty = exports.default = exports.useConfig = exports.useProductContext = void 0; | ||
| const tslib_1 = require("tslib"); | ||
| var useProductContext_1 = require("./hooks/useProductContext"); | ||
| Object.defineProperty(exports, "useProductContext", { enumerable: true, get: function () { return useProductContext_1.useProductContext; } }); | ||
| var useConfig_1 = require("./hooks/useConfig"); | ||
| Object.defineProperty(exports, "useConfig", { enumerable: true, get: function () { return useConfig_1.useConfig; } }); | ||
| var reconciler_1 = require("./reconciler"); | ||
@@ -6,0 +10,0 @@ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return reconciler_1.ForgeReconciler; } }); |
+1
-1
| { | ||
| "name": "@forge/react", | ||
| "version": "9.2.0-next.0", | ||
| "version": "9.2.0-next.1", | ||
| "description": "Forge React reconciler", | ||
@@ -5,0 +5,0 @@ "author": "Atlassian", |
Sorry, the diff of this file is not supported yet
219443
3.87%108
12.5%2716
5.64%