diff --git a/assets/src/admin/search/index.tsx b/assets/src/admin/search/index.tsx index 93d8eac0..73ac5309 100644 --- a/assets/src/admin/search/index.tsx +++ b/assets/src/admin/search/index.tsx @@ -1,6 +1,3 @@ -/** - * WordPress dependencies - */ import { Button, Modal, Snackbar } from '@wordpress/components'; import { createRoot, @@ -11,20 +8,12 @@ import { } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import apiFetch from '@wordpress/api-fetch'; - -/** - * External dependencies - */ import type { NoticeType } from '@/admin/settings/page'; import SiteIndexableEntities from '@/components/SiteIndexableEntities'; import SiteSearchSettings, { type PostTypeOption, } from '@/components/SiteSearchSettings'; -import { - CURRENT_SITE_URL, - REST_NAMESPACE, - withTrailingSlash, -} from '@/js/utils'; +import { CURRENT_SITE_URL, withTrailingSlash } from '@/js/utils'; import type { SiteType } from '@/types/global'; interface AllPostTypesMap { @@ -147,7 +136,7 @@ const OneSearchSettingsPage = () => { const fetchAllPostTypes = async () => { try { const data = await apiFetch< FetchAllPostTypesResponse >( { - path: `/${ REST_NAMESPACE }/all-post-types`, + path: '/onesearch/v1/all-post-types', } ); const mapped = toEntitiesMap( data ); setAllPostTypes( mapped ); diff --git a/assets/src/admin/settings/index.tsx b/assets/src/admin/settings/index.tsx index a3291e98..a48ace87 100644 --- a/assets/src/admin/settings/index.tsx +++ b/assets/src/admin/settings/index.tsx @@ -1,11 +1,4 @@ -/** - * External dependencies - */ import { createRoot } from 'react-dom/client'; - -/** - * Internal dependencies - */ import SettingsPage from './page'; // Render to Gutenberg admin page with ID: onesearch-settings-page diff --git a/assets/src/admin/settings/page.tsx b/assets/src/admin/settings/page.tsx index c8895d31..25d186a9 100644 --- a/assets/src/admin/settings/page.tsx +++ b/assets/src/admin/settings/page.tsx @@ -1,24 +1,13 @@ -/** - * WordPress dependencies - */ -/** - * External dependencies - */ -import { useState, useRef, useCallback } from 'react'; +import { useState, useRef, useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Notice, Snackbar } from '@wordpress/components'; import apiFetch from '@wordpress/api-fetch'; - -/** - * Internal dependencies - */ import SiteTable from '@/components/SiteTable'; import SiteModal from '@/components/SiteModal'; import SiteSettings from '@/components/SiteSettings'; import AlgoliaSettings from '@/components/AlgoliaSettings'; import SiteTypeSettings from '@/components/SiteTypeSettings'; import DeactivationSettings from '@/components/deactivation-settings'; -import { REST_NAMESPACE } from '@/js/utils'; export interface NoticeType { // Set by the settings page, so each notice gets its own Snackbar. @@ -44,7 +33,7 @@ export const defaultBrandSite: BrandSite = { export type EditingIndex = number | null; const SITE_TYPE = window.OneSearchSettings.siteType || null; -const SHARED_SITES_ENDPOINT = `/${ REST_NAMESPACE }/shared-sites`; +const SHARED_SITES_ENDPOINT = '/onesearch/v1/shared-sites'; interface DeleteSiteResponse { governing_site_notified?: boolean; diff --git a/assets/src/components/AlgoliaSettings.tsx b/assets/src/components/AlgoliaSettings.tsx index fa827a71..42ce902c 100644 --- a/assets/src/components/AlgoliaSettings.tsx +++ b/assets/src/components/AlgoliaSettings.tsx @@ -1,10 +1,4 @@ -/** - * WordPress dependencies - */ -/** - * External dependencies - */ -import { useState } from 'react'; +import { useState } from '@wordpress/element'; import { Button, CardBody, @@ -15,19 +9,14 @@ import { } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import apiFetch from '@wordpress/api-fetch'; - -/** - * Internal dependencies - */ import type { NoticeType } from '@/admin/settings/page'; -import { REST_NAMESPACE } from '@/js/utils'; interface AlgoliaCredentials { app_id: string; write_key: string; } -const CREDENTIALS_ENDPOINT = `/${ REST_NAMESPACE }/algolia-credentials`; +const CREDENTIALS_ENDPOINT = '/onesearch/v1/algolia-credentials'; const AlgoliaSettings = ( { setNotice, diff --git a/assets/src/components/IndexSummary.tsx b/assets/src/components/IndexSummary.tsx index 2f88931f..4bdf502f 100644 --- a/assets/src/components/IndexSummary.tsx +++ b/assets/src/components/IndexSummary.tsx @@ -1,13 +1,6 @@ -/** - * WordPress dependencies - */ import { Button } from '@wordpress/components'; import { useState } from '@wordpress/element'; import { __, _n, sprintf } from '@wordpress/i18n'; - -/** - * External dependencies - */ import type { IndexSummaryData } from '@/js/use-index-status'; // How many failed posts to show before the rest are asked for. diff --git a/assets/src/components/JobStatus.tsx b/assets/src/components/JobStatus.tsx index 8fb41ca1..32751b64 100644 --- a/assets/src/components/JobStatus.tsx +++ b/assets/src/components/JobStatus.tsx @@ -1,11 +1,4 @@ -/** - * WordPress dependencies - */ import { __, _n, sprintf } from '@wordpress/i18n'; - -/** - * External dependencies - */ import type { JobStatusData } from '@/js/use-index-status'; // What each job is, and what its failure means for search and what to do. diff --git a/assets/src/components/MultiSelectChips.tsx b/assets/src/components/MultiSelectChips.tsx index 6d41654b..5abbbe5c 100644 --- a/assets/src/components/MultiSelectChips.tsx +++ b/assets/src/components/MultiSelectChips.tsx @@ -1,14 +1,7 @@ -/** - * WordPress dependencies - */ import { Popover, Icon } from '@wordpress/components'; import { chevronDown, closeSmall } from '@wordpress/icons'; import { __, sprintf } from '@wordpress/i18n'; - -/** - * External dependencies - */ -import { useState, useRef, useEffect } from 'react'; +import { useState, useRef, useEffect } from '@wordpress/element'; interface MultiSelectChipsProps { label?: string; diff --git a/assets/src/components/SiteIndexableEntities.tsx b/assets/src/components/SiteIndexableEntities.tsx index 8b445ef5..91369c59 100644 --- a/assets/src/components/SiteIndexableEntities.tsx +++ b/assets/src/components/SiteIndexableEntities.tsx @@ -1,6 +1,3 @@ -/** - * WordPress dependencies - */ import { Card, CardHeader, @@ -10,17 +7,9 @@ import { Modal, Notice, } from '@wordpress/components'; - -/** - * External dependencies - */ -import { useState, useEffect } from 'react'; +import { useState, useEffect } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import apiFetch from '@wordpress/api-fetch'; - -/** - * Internal dependencies - */ import MultiSelectChips from './MultiSelectChips'; import IndexSummary from './IndexSummary'; import JobStatus from './JobStatus'; diff --git a/assets/src/components/SiteModal.tsx b/assets/src/components/SiteModal.tsx index 1711dc6b..98281315 100644 --- a/assets/src/components/SiteModal.tsx +++ b/assets/src/components/SiteModal.tsx @@ -1,9 +1,3 @@ -/** - * WordPress dependencies - */ -/** - * External dependencies - */ import { Button, Modal, @@ -12,13 +6,10 @@ import { TextareaControl, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -import { useMemo, useState } from 'react'; - -/** - * Internal dependencies - */ +import { useMemo, useState } from '@wordpress/element'; import type { defaultBrandSite } from '@/admin/settings/page'; -import { isValidUrl, withTrailingSlash } from '../js/utils'; +import { isValidUrl, withTrailingSlash } from '@/js/utils'; + interface ErrorsType { name: string; url: string; diff --git a/assets/src/components/SiteSearchSettings.tsx b/assets/src/components/SiteSearchSettings.tsx index 069decb5..f7325db7 100644 --- a/assets/src/components/SiteSearchSettings.tsx +++ b/assets/src/components/SiteSearchSettings.tsx @@ -1,6 +1,3 @@ -/** - * WordPress dependencies - */ import apiFetch from '@wordpress/api-fetch'; import { Button, @@ -12,17 +9,9 @@ import { ToggleControl, } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; - -/** - * External dependencies - */ -import { useCallback, useEffect, useRef, useState } from 'react'; - -/** - * Internal dependencies - */ +import { useCallback, useEffect, useRef, useState } from '@wordpress/element'; import type { NoticeType } from '@/admin/settings/page'; -import { withTrailingSlash } from '../js/utils'; +import { withTrailingSlash } from '@/js/utils'; export interface PostTypeOption { slug: string; diff --git a/assets/src/components/SiteSettings.tsx b/assets/src/components/SiteSettings.tsx index 8b600f93..21d939f1 100644 --- a/assets/src/components/SiteSettings.tsx +++ b/assets/src/components/SiteSettings.tsx @@ -1,10 +1,4 @@ -/** - * WordPress dependencies - */ -/** - * External dependencies - */ -import { useEffect, useState, useCallback } from 'react'; +import { useEffect, useState, useCallback } from '@wordpress/element'; import { TextareaControl, Button, @@ -18,12 +12,8 @@ import { } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import apiFetch from '@wordpress/api-fetch'; - -/** - * Internal dependencies - */ import type { NoticeType } from '@/admin/settings/page'; -import { API_KEY, REST_NAMESPACE } from '@/js/utils'; +import { API_KEY } from '@/js/utils'; const SiteSettings = () => { const [ apiKey, setApiKey ] = useState( API_KEY ); @@ -36,7 +26,7 @@ const SiteSettings = () => { const regenerateApiKey = useCallback( async () => { try { const data = await apiFetch< { secret_key?: string } >( { - path: `/${ REST_NAMESPACE }/secret-key`, + path: '/onesearch/v1/secret-key', method: 'POST', } ); if ( data?.secret_key ) { @@ -95,7 +85,7 @@ const SiteSettings = () => { governing_site_notified: boolean; message: string; } >( { - path: `/${ REST_NAMESPACE }/governing-site`, + path: '/onesearch/v1/governing-site', method: 'DELETE', } ); setGoverningSite( '' ); diff --git a/assets/src/components/SiteTable.tsx b/assets/src/components/SiteTable.tsx index cc6e9060..ac045fd4 100644 --- a/assets/src/components/SiteTable.tsx +++ b/assets/src/components/SiteTable.tsx @@ -1,10 +1,4 @@ -/** - * WordPress dependencies - */ -/** - * External dependencies - */ -import { useState } from 'react'; +import { useState } from '@wordpress/element'; import { Button, Card, diff --git a/assets/src/components/SiteTypeSettings.tsx b/assets/src/components/SiteTypeSettings.tsx index 1ebac0bd..c5a0ed6f 100644 --- a/assets/src/components/SiteTypeSettings.tsx +++ b/assets/src/components/SiteTypeSettings.tsx @@ -1,11 +1,4 @@ -/** - * External dependencies - */ -import { useState } from 'react'; - -/** - * WordPress dependencies - */ +import { useState } from '@wordpress/element'; import apiFetch from '@wordpress/api-fetch'; import { __ } from '@wordpress/i18n'; import { @@ -16,10 +9,6 @@ import { Button, SelectControl, } from '@wordpress/components'; - -/** - * Internal dependencies - */ import type { SiteType } from '@/types/global'; const BRAND_SITE = 'brand-site' as const; diff --git a/assets/src/components/deactivation-settings.tsx b/assets/src/components/deactivation-settings.tsx index b9af3255..d8d3e229 100644 --- a/assets/src/components/deactivation-settings.tsx +++ b/assets/src/components/deactivation-settings.tsx @@ -1,12 +1,5 @@ -/** - * External dependencies - */ -import { useState } from 'react'; - -/** - * WordPress dependencies - */ import apiFetch from '@wordpress/api-fetch'; +import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Card, @@ -14,10 +7,6 @@ import { CardHeader, ToggleControl, } from '@wordpress/components'; - -/** - * Internal dependencies - */ import type { NoticeType } from '@/admin/settings/page'; import type { SiteType } from '@/types/global'; diff --git a/assets/src/js/use-index-status.ts b/assets/src/js/use-index-status.ts index 951f2eec..268206b0 100644 --- a/assets/src/js/use-index-status.ts +++ b/assets/src/js/use-index-status.ts @@ -1,14 +1,6 @@ -/** - * WordPress dependencies - */ import { useCallback, useEffect, useState } from '@wordpress/element'; import apiFetch from '@wordpress/api-fetch'; -/** - * Internal dependencies - */ -import { REST_NAMESPACE } from './utils'; - export type JobState = 'queued' | 'running' | 'completed' | 'failed'; /** @@ -49,7 +41,7 @@ interface StatusResponse { jobs: JobStatusData[]; } -const INDEXER_PATH = `/${ REST_NAMESPACE }/indexer`; +const INDEXER_PATH = '/onesearch/v1/indexer'; // How often to check on the jobs while any of them is going, in milliseconds. export const POLL_INTERVAL = 10000; diff --git a/assets/src/js/utils.ts b/assets/src/js/utils.ts index be7cff04..91a32edc 100644 --- a/assets/src/js/utils.ts +++ b/assets/src/js/utils.ts @@ -31,14 +31,6 @@ export const withTrailingSlash = ( url: string ): string => { */ export const API_KEY = window.OneSearchSettings.api_key; -/** - * REST namespace used by the OneSearch plugin. - * - * @constant - * @type {string} - */ -export const REST_NAMESPACE = window.OneSearchSettings.restNamespace; - /** * Current site’s base URL. * diff --git a/assets/src/types/global.d.ts b/assets/src/types/global.d.ts index 87fdc2b1..31e2d660 100644 --- a/assets/src/types/global.d.ts +++ b/assets/src/types/global.d.ts @@ -19,7 +19,6 @@ export interface OneSearchSettings { setupUrl: string; siteType: SiteType | null; sharedSites?: OneSearchSharedSite[]; - restNamespace: string; currentSiteUrl: string; algoliaAppId?: string; hasAlgoliaCredentials?: '1' | ''; diff --git a/babel.config.js b/babel.config.js index 96b29733..0c83ccbe 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,6 +1,3 @@ -/** - * WordPress dependencies - */ const defaultConfig = require( '@wordpress/babel-preset-default' ); module.exports = function ( api ) { diff --git a/eslint.config.mjs b/eslint.config.mjs index acdfb0dc..3bbec509 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -39,7 +39,6 @@ export default [ '@wordpress/i18n-no-flanking-whitespace': 'error', // Additional WordPress rules not in recommended preset - '@wordpress/dependency-group': 'error', '@wordpress/data-no-store-string-literals': 'error', '@wordpress/wp-global-usage': 'error', '@wordpress/react-no-unsafe-timeout': 'error', diff --git a/inc/Modules/Core/Assets.php b/inc/Modules/Core/Assets.php index ce7a2704..a6946c79 100644 --- a/inc/Modules/Core/Assets.php +++ b/inc/Modules/Core/Assets.php @@ -10,7 +10,6 @@ namespace OneSearch\Modules\Core; use OneSearch\Contracts\Interfaces\Registrable; -use OneSearch\Modules\Rest\Abstract_REST_Controller; use OneSearch\Modules\Search\Settings as Search_Settings; use OneSearch\Modules\Settings\Settings; use OneSearch\Utils; @@ -74,7 +73,6 @@ public static function get_localized_data(): array { 'hasAlgoliaCredentials' => ! empty( $algolia_creds['app_id'] ) && ! empty( $algolia_creds['write_key'] ), // Only brand sites use a key of their own, so governing sites don't generate one. 'api_key' => Settings::is_consumer_site() ? Settings::get_api_key() : '', - 'restNamespace' => Abstract_REST_Controller::NAMESPACE, 'setupUrl' => admin_url( 'admin.php?page=onesearch-settings' ), 'sharedSites' => Settings::get_shared_sites_without_keys(), 'siteType' => Settings::get_site_type(), diff --git a/playwright.config.ts b/playwright.config.ts index c077f81c..866529d6 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,6 +1,3 @@ -/** - * External dependencies - */ import { defineConfig, type PlaywrightTestConfig } from '@playwright/test'; import path from 'path'; diff --git a/tests/e2e/settings/activation.spec.ts b/tests/e2e/settings/activation.spec.ts index 4f07281a..8212c6a2 100644 --- a/tests/e2e/settings/activation.spec.ts +++ b/tests/e2e/settings/activation.spec.ts @@ -1,6 +1,3 @@ -/** - * WordPress dependencies - */ import { expect, test } from '@wordpress/e2e-test-utils-playwright'; test.describe( 'plugin activation', () => { diff --git a/tests/js/AlgoliaSettings.test.tsx b/tests/js/AlgoliaSettings.test.tsx index 1a6b739d..1d82deed 100644 --- a/tests/js/AlgoliaSettings.test.tsx +++ b/tests/js/AlgoliaSettings.test.tsx @@ -1,6 +1,3 @@ -/** - * External dependencies - */ import { beforeEach, describe, @@ -10,12 +7,7 @@ import { vi, } from 'vitest'; import { fireEvent, render, screen, waitFor } from '@testing-library/react'; - -/** - * WordPress dependencies - */ import apiFetch from '@wordpress/api-fetch'; - import AlgoliaSettings from '@/components/AlgoliaSettings'; const mockedApiFetch = apiFetch as MockedFunction< typeof apiFetch >; diff --git a/tests/js/IndexStatus.test.tsx b/tests/js/IndexStatus.test.tsx index 7cd211d1..5dfd8d30 100644 --- a/tests/js/IndexStatus.test.tsx +++ b/tests/js/IndexStatus.test.tsx @@ -1,9 +1,5 @@ -/** - * External dependencies - */ import { describe, expect, it } from 'vitest'; import { fireEvent, render, screen } from '@testing-library/react'; - import IndexSummary from '@/components/IndexSummary'; import JobStatus from '@/components/JobStatus'; import type { JobStatusData } from '@/js/use-index-status'; diff --git a/tests/js/MultiSelectChips.test.tsx b/tests/js/MultiSelectChips.test.tsx index 12058f1f..bcf326d5 100644 --- a/tests/js/MultiSelectChips.test.tsx +++ b/tests/js/MultiSelectChips.test.tsx @@ -1,9 +1,5 @@ -/** - * External dependencies - */ import { describe, expect, it, vi } from 'vitest'; import { act, fireEvent, render, screen } from '@testing-library/react'; - import MultiSelectChips from '@/components/MultiSelectChips'; const options = [ diff --git a/tests/js/SearchPage.test.tsx b/tests/js/SearchPage.test.tsx index 76b1fb02..d301167d 100644 --- a/tests/js/SearchPage.test.tsx +++ b/tests/js/SearchPage.test.tsx @@ -1,6 +1,3 @@ -/** - * External dependencies - */ import { fireEvent, screen, waitFor, within } from '@testing-library/react'; import type { Root } from 'react-dom/client'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; diff --git a/tests/js/SettingsPage.test.tsx b/tests/js/SettingsPage.test.tsx index 442dd1f0..38c7bade 100644 --- a/tests/js/SettingsPage.test.tsx +++ b/tests/js/SettingsPage.test.tsx @@ -1,6 +1,3 @@ -/** - * External dependencies - */ import { afterEach, beforeEach, @@ -17,9 +14,6 @@ import { screen, waitFor, } from '@testing-library/react'; -/** - * WordPress dependencies - */ import apiFetch from '@wordpress/api-fetch'; // Mock child components to isolate SettingsPage behavior diff --git a/tests/js/SiteIndexableEntities.test.tsx b/tests/js/SiteIndexableEntities.test.tsx index 2bad1efa..e254a6e8 100644 --- a/tests/js/SiteIndexableEntities.test.tsx +++ b/tests/js/SiteIndexableEntities.test.tsx @@ -1,6 +1,3 @@ -/** - * External dependencies - */ import { describe, expect, it, type MockedFunction, vi } from 'vitest'; import { act, @@ -10,12 +7,7 @@ import { waitFor, within, } from '@testing-library/react'; - -/** - * WordPress dependencies - */ import apiFetch from '@wordpress/api-fetch'; - import SiteIndexableEntities from '@/components/SiteIndexableEntities'; import { POLL_INTERVAL, type JobStatusData } from '@/js/use-index-status'; diff --git a/tests/js/SiteModal.test.tsx b/tests/js/SiteModal.test.tsx index 95123cd0..c5ca650b 100644 --- a/tests/js/SiteModal.test.tsx +++ b/tests/js/SiteModal.test.tsx @@ -1,6 +1,8 @@ -/** - * External dependencies - */ +import { defaultBrandSite } from '@/admin/settings/page'; +import SiteModal from '@/components/SiteModal'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import apiFetch from '@wordpress/api-fetch'; +import { useState } from '@wordpress/element'; import { describe, expect, @@ -9,19 +11,6 @@ import { type MockedFunction, vi, } from 'vitest'; -import { useState } from 'react'; -import { fireEvent, render, screen, waitFor } from '@testing-library/react'; -/** - * WordPress dependencies - */ -import apiFetch from '@wordpress/api-fetch'; - -import SiteModal from '@/components/SiteModal'; -import { defaultBrandSite } from '@/admin/settings/page'; - -/** - * Internal dependencies - */ import { findNotice } from './helpers'; const mockedApiFetch = apiFetch as MockedFunction< typeof apiFetch >; diff --git a/tests/js/SiteSearchSettings.test.tsx b/tests/js/SiteSearchSettings.test.tsx index a5d40bb2..f57f09f3 100644 --- a/tests/js/SiteSearchSettings.test.tsx +++ b/tests/js/SiteSearchSettings.test.tsx @@ -1,6 +1,3 @@ -/** - * External dependencies - */ import { beforeEach, describe, @@ -16,11 +13,7 @@ import { waitFor, within, } from '@testing-library/react'; -/** - * WordPress dependencies - */ import apiFetch from '@wordpress/api-fetch'; - import SiteSearchSettings from '@/components/SiteSearchSettings'; const mockedApiFetch = apiFetch as MockedFunction< typeof apiFetch >; diff --git a/tests/js/SiteSettings.test.tsx b/tests/js/SiteSettings.test.tsx index fa505820..248b2b05 100644 --- a/tests/js/SiteSettings.test.tsx +++ b/tests/js/SiteSettings.test.tsx @@ -1,14 +1,6 @@ -/** - * External dependencies - */ import { describe, expect, it, type MockedFunction, vi } from 'vitest'; import { fireEvent, render, screen, waitFor } from '@testing-library/react'; - -/** - * WordPress dependencies - */ import apiFetch from '@wordpress/api-fetch'; - import SiteSettings from '@/components/SiteSettings'; const mockedApiFetch = apiFetch as MockedFunction< typeof apiFetch >; diff --git a/tests/js/SiteTable.test.tsx b/tests/js/SiteTable.test.tsx index edcd1637..125b35ec 100644 --- a/tests/js/SiteTable.test.tsx +++ b/tests/js/SiteTable.test.tsx @@ -1,9 +1,5 @@ -/** - * External dependencies - */ import { describe, expect, it, vi } from 'vitest'; import { fireEvent, render, screen, within } from '@testing-library/react'; - import SiteTable from '@/components/SiteTable'; const sites = [ diff --git a/tests/js/SiteTypeSettings.test.tsx b/tests/js/SiteTypeSettings.test.tsx index 0b10af22..1c190fd2 100644 --- a/tests/js/SiteTypeSettings.test.tsx +++ b/tests/js/SiteTypeSettings.test.tsx @@ -1,6 +1,6 @@ -/** - * External dependencies - */ +import SiteTypeSettings from '@/components/SiteTypeSettings'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import apiFetch from '@wordpress/api-fetch'; import { afterEach, beforeEach, @@ -11,13 +11,6 @@ import { type MockInstance, vi, } from 'vitest'; -import { fireEvent, render, screen, waitFor } from '@testing-library/react'; -/** - * WordPress dependencies - */ -import apiFetch from '@wordpress/api-fetch'; - -import SiteTypeSettings from '@/components/SiteTypeSettings'; const mockedApiFetch = apiFetch as MockedFunction< typeof apiFetch >; diff --git a/tests/js/deactivation-settings.test.tsx b/tests/js/deactivation-settings.test.tsx index 435c10ad..32fab3e1 100644 --- a/tests/js/deactivation-settings.test.tsx +++ b/tests/js/deactivation-settings.test.tsx @@ -1,6 +1,3 @@ -/** - * External dependencies - */ import { afterEach, beforeEach, @@ -12,11 +9,7 @@ import { vi, } from 'vitest'; import { fireEvent, render, screen, waitFor } from '@testing-library/react'; -/** - * WordPress dependencies - */ import apiFetch from '@wordpress/api-fetch'; - import DeactivationSettings from '@/components/deactivation-settings'; const mockedApiFetch = apiFetch as MockedFunction< typeof apiFetch >; diff --git a/tests/js/helpers.ts b/tests/js/helpers.ts index c5014bb2..4bd3c203 100644 --- a/tests/js/helpers.ts +++ b/tests/js/helpers.ts @@ -1,6 +1,3 @@ -/** - * External dependencies - */ import { screen } from '@testing-library/react'; /** diff --git a/tests/js/setup.ts b/tests/js/setup.ts index faa2930f..c418996f 100644 --- a/tests/js/setup.ts +++ b/tests/js/setup.ts @@ -1,6 +1,3 @@ -/** - * External dependencies - */ import '@testing-library/jest-dom/vitest'; import { cleanup } from '@testing-library/react'; import type { EventEmitter } from 'node:events'; @@ -27,7 +24,6 @@ Object.defineProperty( global, 'fetch', { Object.defineProperty( window, 'OneSearchSettings', { value: { - restNamespace: 'onesearch/v1', api_key: 'api-key', currentSiteUrl: 'https://governing.example.com/', siteType: 'governing-site', diff --git a/tests/js/utils.test.ts b/tests/js/utils.test.ts index 915b2e55..34eb7ebb 100644 --- a/tests/js/utils.test.ts +++ b/tests/js/utils.test.ts @@ -1,11 +1,7 @@ -/** - * External dependencies - */ import { describe, expect, it } from 'vitest'; import { API_KEY, CURRENT_SITE_URL, - REST_NAMESPACE, isValidUrl, withTrailingSlash, } from '@/js/utils'; @@ -35,7 +31,6 @@ describe( 'utils', () => { it( 'reads wordpress settings constants from the global config', () => { expect( API_KEY ).toBe( 'api-key' ); - expect( REST_NAMESPACE ).toBe( 'onesearch/v1' ); expect( CURRENT_SITE_URL ).toBe( 'https://governing.example.com/' ); } ); } ); diff --git a/tests/phpunit/Integration/Modules/Core/AssetsTest.php b/tests/phpunit/Integration/Modules/Core/AssetsTest.php index 0dcc0637..b69a300f 100644 --- a/tests/phpunit/Integration/Modules/Core/AssetsTest.php +++ b/tests/phpunit/Integration/Modules/Core/AssetsTest.php @@ -31,6 +31,22 @@ public function test_assets_class_instantiation(): void { $this->assertTrue( true ); } + /** + * Registering a script again still gives it the dependencies from its asset file. + */ + public function test_registering_a_script_again_keeps_its_dependencies(): void { + $assets = new Assets(); + + $assets->register_assets(); + wp_deregister_script( Assets::SETTINGS_SCRIPT_HANDLE ); + $assets->register_assets(); + + $asset = require ONESEARCH_DIR . 'build/settings.asset.php'; + + $this->assertNotEmpty( $asset['dependencies'] ); + $this->assertSame( $asset['dependencies'], wp_scripts()->registered[ Assets::SETTINGS_SCRIPT_HANDLE ]->deps ); + } + /** * Ensures plugin scripts receive a defer attribute. */ @@ -60,7 +76,7 @@ public function test_defer_scripts_does_not_duplicate_defer_attribute(): void { $assets = new Assets(); $tag = ''; - $this->assertSame( $tag, $assets->defer_scripts( $tag, Assets::SEARCH_SCRIPT_HANDLE ) ); + $this->assertSame( $tag, $assets->defer_scripts( $tag, Assets::SETTINGS_SCRIPT_HANDLE ) ); } /** @@ -71,13 +87,7 @@ public function test_get_localized_data_returns_expected_keys(): void { $data = Assets::get_localized_data(); - $this->assertArrayHasKey( 'currentSiteUrl', $data ); - $this->assertArrayHasKey( 'algoliaAppId', $data ); - $this->assertArrayHasKey( 'api_key', $data ); - $this->assertArrayHasKey( 'restNamespace', $data ); - $this->assertArrayHasKey( 'setupUrl', $data ); - $this->assertArrayHasKey( 'sharedSites', $data ); - $this->assertArrayHasKey( 'siteType', $data ); + $this->assertEqualsCanonicalizing( [ 'algoliaAppId', 'api_key', 'currentSiteUrl', 'deleteDataOnDeactivation', 'hasAlgoliaCredentials', 'setupUrl', 'sharedSites', 'siteType' ], array_keys( $data ) ); } /** diff --git a/tests/phpunit/Integration/Modules/Rest/Brand_Site_Controller_GoverningSiteTest.php b/tests/phpunit/Integration/Modules/Rest/Brand_Site_Controller_GoverningSiteTest.php index c6042b3e..89ec394c 100644 --- a/tests/phpunit/Integration/Modules/Rest/Brand_Site_Controller_GoverningSiteTest.php +++ b/tests/phpunit/Integration/Modules/Rest/Brand_Site_Controller_GoverningSiteTest.php @@ -166,7 +166,7 @@ public function test_remove_brand_site_rejects_wrong_token(): void { } /** - * Only a brand site can remove itself, so a logged-in admin (from set_up) without its key is refused. + * Only a brand site can remove itself, so a logged-in admin (from setUp) without its key is refused. */ public function test_remove_brand_site_refuses_an_admin_without_a_brand_key(): void { Settings::set_shared_sites( @@ -199,7 +199,7 @@ public function test_registers_brand_site_config_get(): void { } /** - * Only brand sites use brand-site/config, so a logged-in admin (from set_up) without a brand's key is refused. + * Only brand sites use brand-site/config, so a logged-in admin (from setUp) without a brand's key is refused. */ public function test_get_brand_config_refuses_an_admin_without_a_brand_key(): void { $request = new WP_REST_Request( 'GET', '/onesearch/v1/brand-site/config' ); diff --git a/tests/phpunit/Integration/Modules/Rest/Governing_Site_Controller_ConsumerSiteTest.php b/tests/phpunit/Integration/Modules/Rest/Governing_Site_Controller_ConsumerSiteTest.php index 195cfaa8..4f7ebcff 100644 --- a/tests/phpunit/Integration/Modules/Rest/Governing_Site_Controller_ConsumerSiteTest.php +++ b/tests/phpunit/Integration/Modules/Rest/Governing_Site_Controller_ConsumerSiteTest.php @@ -152,7 +152,7 @@ public function test_remove_governing_site_warns_when_governing_site_does_not_re } /** - * Only a governing site with this site's key can connect it, so a logged-in admin (from set_up) is refused. + * Only a governing site with this site's key can connect it, so a logged-in admin (from setUp) is refused. */ public function test_connect_refuses_an_admin_without_the_key(): void { delete_option( Settings::OPTION_CONSUMER_PARENT_SITE_URL ); @@ -344,7 +344,7 @@ public function test_delete_brand_config_cache_succeeds_when_no_cache(): void { } /** - * Only the governing site clears the cached brand config, so a logged-in admin (from set_up) is refused. + * Only the governing site clears the cached brand config, so a logged-in admin (from setUp) is refused. */ public function test_delete_brand_config_cache_refuses_an_admin(): void { set_transient( Remote_Client::TRANSIENT_KEY, [ 'cached' => true ], 3600 ); diff --git a/vitest.config.mjs b/vitest.config.mjs index b5d41fa9..5fd241ef 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -4,9 +4,6 @@ * @see https://vitest.dev/config/ */ -/** - * External dependencies - */ import { fileURLToPath } from 'node:url'; import { configDefaults, defineConfig } from 'vitest/config'; diff --git a/webpack.config.js b/webpack.config.js index afd2c1c9..bafc0196 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,13 +1,6 @@ -/** - * External dependencies - */ const fs = require( 'fs' ); const path = require( 'path' ); const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' ); - -/** - * WordPress dependencies - */ const [ defaultScriptConfig, ] = require( '@wordpress/scripts/config/webpack.config' );