From def89b499fd322d666f1374a47b7a9332d033001 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Thu, 13 Jul 2023 09:55:22 +0200 Subject: [PATCH] WIP add test?? --- src/components/__tests__/codeBlock.test.js | 54 ++++++++++++++++++++++ src/components/basePage.tsx | 6 +-- src/components/codeContext.tsx | 18 ++++++-- 3 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 src/components/__tests__/codeBlock.test.js diff --git a/src/components/__tests__/codeBlock.test.js b/src/components/__tests__/codeBlock.test.js new file mode 100644 index 00000000000000..b552b287d3b52f --- /dev/null +++ b/src/components/__tests__/codeBlock.test.js @@ -0,0 +1,54 @@ +import React from 'react'; +import renderer from 'react-test-renderer'; + +import {CodeWrapper} from '../codeBlock'; +import {CodeContextProvider, DEFAULTS} from '../codeContext'; + +jest.mock('../hooks/usePlatform'); + +describe('CodeWrapper', () => { + it('renders without placeholder', () => { + const tree = renderer + .create( + DEFAULTS}> + process.env.MY_ENV = 'foo' + + ) + .toJSON(); + expect(tree).toMatchSnapshot(); + }); + + /* it('renders with placeholder', () => { + const tree = renderer + .create(process.env.MY_ENV = ___ORG_SLUG___) + .toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('renders with placeholder in middle of text', () => { + const tree = renderer + .create( + process.env.MY_ENV = https://___ORG_SLUG___.sentry.io + ) + .toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('renders org auth token placeholder', () => { + const tree = renderer + .create(process.env.MY_ENV = ___ORG_AUTH_TOKEN___) + .toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('renders multiple placeholders', () => { + const tree = renderer + .create( + + process.env.MY_ENV = ___ORG_SLUG___ + ___PROJECT_SLUG___ + + ) + .toJSON(); + expect(tree).toMatchSnapshot(); + }); */ +}); diff --git a/src/components/basePage.tsx b/src/components/basePage.tsx index e174e79a034237..caa0c4817ef769 100644 --- a/src/components/basePage.tsx +++ b/src/components/basePage.tsx @@ -3,7 +3,7 @@ import React, {Fragment, useRef} from 'react'; import {getCurrentTransaction} from '../utils'; import {Banner} from './banner'; -import {CodeContext, useCodeContextState} from './codeContext'; +import {CodeContextProvider} from './codeContext'; import {GitHubCTA} from './githubCta'; import {Layout} from './layout'; import {SEO} from './seo'; @@ -77,9 +77,7 @@ export function BasePage({ >

{title}

- - {children} - + {children} {file && ( Promise; +}) { const [codeKeywords, setCodeKeywords] = useState(cachedCodeKeywords ?? DEFAULTS); const [isLoading, setIsLoading] = useState(cachedCodeKeywords ? false : true); + const _fetcher = fetcher || fetchCodeKeywords; + useEffect(() => { if (cachedCodeKeywords === null) { setIsLoading(true); - fetcher().then((config: CodeKeywords) => { + _fetcher().then((config: CodeKeywords) => { cachedCodeKeywords = config; setCodeKeywords(config); setIsLoading(false); }); } - }, [setIsLoading, setCodeKeywords, fetcher]); + }, [setIsLoading, setCodeKeywords, _fetcher]); // sharedKeywordSelection maintains a global mapping for each "keyword" // namespace to the index of the selected item. @@ -273,5 +281,5 @@ export function useCodeContextState(fetcher = fetchCodeKeywords): CodeContextTyp isLoading, }; - return result; + return {children}; }