diff --git a/packages/library-detection/src/config.ts b/packages/library-detection/src/config.ts index ee838b58c..d8ae09d64 100644 --- a/packages/library-detection/src/config.ts +++ b/packages/library-detection/src/config.ts @@ -56,11 +56,6 @@ import { jetpackLikesDOMQuery, JETPACK_LIKES_HELP_URL, } from './libraries/jetpack-likes'; -import { - ReCaptchaAccordion, - reCaptchaDOMQuery, - RECAPTCHA_HELP_URL, -} from './libraries/reCaptcha'; const LIBRARIES = [ { @@ -115,12 +110,6 @@ const LIBRARIES = [ helpUrl: JETPACK_LIKES_HELP_URL, domQueryFunction: jetpackLikesDOMQuery, }, - { - name: 'reCaptcha', - component: ReCaptchaAccordion, - helpUrl: RECAPTCHA_HELP_URL, - domQueryFunction: reCaptchaDOMQuery, - }, ]; export default LIBRARIES; diff --git a/packages/library-detection/src/libraries/reCaptcha/accordion.tsx b/packages/library-detection/src/libraries/reCaptcha/accordion.tsx deleted file mode 100644 index 8023b5443..000000000 --- a/packages/library-detection/src/libraries/reCaptcha/accordion.tsx +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * External dependencies. - */ -import React from 'react'; - -/** - * Internal dependencies. - */ -import { Accordion, DetectionMessage } from '../../components'; -import type { AccordionProps } from '../../types'; -import { RECAPTCHA_HELP_URL } from './constants'; - -const ReCaptchaAccordion = ({ domQueryMatches }: AccordionProps) => { - if (!domQueryMatches) { - return null; - } - - const featuresCount = domQueryMatches.length; - - if (!featuresCount) { - return null; - } - - return ( - - - - ); -}; - -export default ReCaptchaAccordion; diff --git a/packages/library-detection/src/libraries/reCaptcha/constants.ts b/packages/library-detection/src/libraries/reCaptcha/constants.ts deleted file mode 100644 index a64f5c206..000000000 --- a/packages/library-detection/src/libraries/reCaptcha/constants.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const RECAPTCHA_HELP_URL = 'https://support.google.com/recaptcha/'; diff --git a/packages/library-detection/src/libraries/reCaptcha/index.ts b/packages/library-detection/src/libraries/reCaptcha/index.ts deleted file mode 100644 index b7f0169e7..000000000 --- a/packages/library-detection/src/libraries/reCaptcha/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export { default as ReCaptchaAccordion } from './accordion'; -export { default as reCaptchaDOMQuery } from './reCaptchaDOMQuery'; -export * from './constants'; diff --git a/packages/library-detection/src/libraries/reCaptcha/reCaptchaDOMQuery.ts b/packages/library-detection/src/libraries/reCaptcha/reCaptchaDOMQuery.ts deleted file mode 100644 index ac1feecb8..000000000 --- a/packages/library-detection/src/libraries/reCaptcha/reCaptchaDOMQuery.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -const reCaptchaDOMQuery = () => { - const matchItems: string[] = []; - - const reCaptchaClass = document.querySelector('.g-recaptcha'); - - const reCaptchaScriptSrcRegex = /^https:\/\/www\.google\.com\/recaptcha/; - - const scripts = document.querySelectorAll('script'); - - scripts.forEach((script) => { - if (script.src && reCaptchaScriptSrcRegex.test(script.src)) { - matchItems.push(`script[src]: ${script.src}`); - } - }); - - if (matchItems.length && reCaptchaClass) { - const reCaptchaTag = reCaptchaClass.tagName.toLowerCase(); - matchItems.push(`${reCaptchaTag}[class]: g-recaptcha`); - } - - return matchItems; -}; - -export default reCaptchaDOMQuery; diff --git a/packages/library-detection/src/libraries/reCaptcha/tests/accordion.tsx b/packages/library-detection/src/libraries/reCaptcha/tests/accordion.tsx deleted file mode 100644 index f6de2947f..000000000 --- a/packages/library-detection/src/libraries/reCaptcha/tests/accordion.tsx +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * External dependencies. - */ -import React from 'react'; -import { render, screen, fireEvent } from '@testing-library/react'; -import '@testing-library/jest-dom'; - -/** - * Internal dependencies. - */ -import ReCaptchaAccordion from '../accordion'; - -describe('reCAPTCHA Accordion', () => { - const accordionTitleText = 'reCAPTCHA'; - const accordionMessageText = - 'reCAPTCHA functionality may not work properly due to the phaseout of third-party cookies. To inquire further about the same, please visit the reCAPTCHA support forum.'; - - it('should show accordion', () => { - const domQueryMatches = ['']; - render(); - - const accordion = screen.getByTestId('library-detection-accordion'); - const accordionTitle = screen.getByText(accordionTitleText); - - expect(accordion).toBeInTheDocument(); - expect(accordionTitle).toBeInTheDocument(); - }); - - it('should not show accordion', () => { - const domQueryMatches = null; - render(); - - const accordion = screen.queryByTestId('library-detection-accordion'); - const accordionTitle = screen.queryByText(accordionTitleText); - - expect(accordion).not.toBeInTheDocument(); - expect(accordionTitle).not.toBeInTheDocument(); - }); - - it('should toggle accordion message after clicking the accordion', () => { - const domQueryMatches = [ - 'div[class]: g-recaptcha', - 'script[src]: https://www.google.com/recaptcha/api.js', - ]; - - render(); - - const accordion = screen.getByTestId('library-detection-accordion'); - const accordionTitle = screen.getByText(accordionTitleText); - - expect(accordion).not.toHaveTextContent(accordionMessageText); - - // Click the accordion - fireEvent.click(accordionTitle); - - expect(accordion).toHaveTextContent(accordionMessageText); - - // Click the accordion - fireEvent.click(accordionTitle); - - expect(accordion).not.toHaveTextContent(accordionMessageText); - }); -}); diff --git a/packages/library-detection/src/libraries/reCaptcha/tests/reCaptchaDOMQuery.ts b/packages/library-detection/src/libraries/reCaptcha/tests/reCaptchaDOMQuery.ts deleted file mode 100644 index 8cf3671cb..000000000 --- a/packages/library-detection/src/libraries/reCaptcha/tests/reCaptchaDOMQuery.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * External dependencies. - */ -import '@testing-library/jest-dom'; - -/** - * Internal dependencies. - */ -import reCaptchaDOMQuery from '../reCaptchaDOMQuery'; - -describe('Disqus Comments DOM Query', () => { - beforeEach(() => { - // Clean up the DOM before each test - document.body.innerHTML = ''; - }); - - it('should return the matches found', () => { - const script = document.createElement('script'); - script.src = 'https://www.google.com/recaptcha/api.js'; - - const div = document.createElement('div'); - div.classList.add('g-recaptcha'); - - document.body.appendChild(script); - document.body.appendChild(div); - - const matches = reCaptchaDOMQuery(); - - expect(matches).toHaveLength(2); - expect(Array.isArray(matches)).toBe(true); - expect(matches).toContain('div[class]: g-recaptcha'); - expect(matches).toContain( - 'script[src]: https://www.google.com/recaptcha/api.js' - ); - }); - - it('should detect library if script signature is found', () => { - const script = document.createElement('script'); - script.src = 'https://www.google.com/recaptcha/api.js'; - - document.body.appendChild(script); - - const matches = reCaptchaDOMQuery(); - - expect(matches).toHaveLength(1); - expect(Array.isArray(matches)).toBe(true); - }); - - it('should return empty array if script signature is not found', () => { - const div = document.createElement('div'); - div.classList.add('g-recaptcha'); - - document.body.appendChild(div); - - const matches = reCaptchaDOMQuery(); - - expect(matches).toHaveLength(0); - expect(Array.isArray(matches)).toBe(true); - }); - - it('should return empty array if no signature found', () => { - const matches = reCaptchaDOMQuery(); - - expect(matches).toHaveLength(0); - expect(Array.isArray(matches)).toBe(true); - }); -});