Skip to content

Commit

Permalink
Rename removeNonBreakingSpaces to removeUncommonSpacesFromBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
nygrenh committed Jan 16, 2025
1 parent f9ef26d commit 7626420
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions services/cms/src/components/editors/PageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { EditorContentDispatch, editorContentReducer } from "../../contexts/Edit
import usePageInfo from "../../hooks/usePageInfo"
import mediaUploadBuilder from "../../services/backend/media/mediaUpload"
import { fetchNextPageRoutingData } from "../../services/backend/pages"
import { modifyBlocks, removeNonBreakingSpaces } from "../../utils/Gutenberg/modifyBlocks"
import { modifyBlocks, removeUncommonSpacesFromBlocks } from "../../utils/Gutenberg/modifyBlocks"
import { removeUnsupportedBlockType } from "../../utils/Gutenberg/removeUnsupportedBlockType"
import { denormalizeDocument, normalizeDocument } from "../../utils/documentSchemaProcessor"
import { makeSurePeerOrSelfReviewConfigAdditionalInstructionsAreNullInsteadOfEmptyLookingArray } from "../../utils/peerOrSelfReviewConfig"
Expand Down Expand Up @@ -89,7 +89,7 @@ const PageEditor: React.FC<React.PropsWithChildren<PageEditorProps>> = ({
setCurrentlySaving(true)
const dataToSave = normalizeDocument({
chapterId: data.chapter_id,
content: removeNonBreakingSpaces(removeUnsupportedBlockType(content)),
content: removeUncommonSpacesFromBlocks(removeUnsupportedBlockType(content)),
title,
urlPath: data.url_path,
})
Expand Down
4 changes: 2 additions & 2 deletions services/cms/src/utils/Gutenberg/modifyBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const modifyBlocks = (
* @param blocks - Array of Gutenberg block instances to process
* @returns A new array of blocks with uncommon spaces replaced
*/
export const removeNonBreakingSpaces = (blocks: BlockInstance[]): BlockInstance[] => {
export const removeUncommonSpacesFromBlocks = (blocks: BlockInstance[]): BlockInstance[] => {
return blocks.map((block) => {
const newBlock = { ...block }

Expand All @@ -52,7 +52,7 @@ export const removeNonBreakingSpaces = (blocks: BlockInstance[]): BlockInstance[
}

if (block.innerBlocks && block.innerBlocks.length > 0) {
newBlock.innerBlocks = removeNonBreakingSpaces(block.innerBlocks)
newBlock.innerBlocks = removeUncommonSpacesFromBlocks(block.innerBlocks)
}

return newBlock
Expand Down
12 changes: 6 additions & 6 deletions services/cms/tests/utils/modifyBlocks.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BlockInstance } from "@wordpress/blocks"

import { removeNonBreakingSpaces } from "../../src/utils/Gutenberg/modifyBlocks"
import { removeUncommonSpacesFromBlocks } from "../../src/utils/Gutenberg/modifyBlocks"

describe("removeNonBreakingSpaces", () => {
describe("removeUncommonSpacesFromBlocks", () => {
it("should replace non-breaking spaces with regular spaces in paragraph blocks", () => {
const blocks: BlockInstance[] = [
{
Expand All @@ -16,7 +16,7 @@ describe("removeNonBreakingSpaces", () => {
},
]

const result = removeNonBreakingSpaces(blocks)
const result = removeUncommonSpacesFromBlocks(blocks)

// Check that the result has the correct content
expect(result[0].attributes.content).toBe("Hello World More Text")
Expand Down Expand Up @@ -45,7 +45,7 @@ describe("removeNonBreakingSpaces", () => {
},
]

const result = removeNonBreakingSpaces(blocks)
const result = removeUncommonSpacesFromBlocks(blocks)

// Check that the nested content was modified in the result
expect(result[0].innerBlocks[0].attributes.content).toBe("Nested Content")
Expand All @@ -66,7 +66,7 @@ describe("removeNonBreakingSpaces", () => {
},
]

const result = removeNonBreakingSpaces(blocks)
const result = removeUncommonSpacesFromBlocks(blocks)

expect(result[0].attributes.content).toBe("Header\u00A0Text")
// Verify original wasn't modified
Expand All @@ -75,7 +75,7 @@ describe("removeNonBreakingSpaces", () => {

it("should handle empty blocks array", () => {
const blocks: BlockInstance[] = []
const result = removeNonBreakingSpaces(blocks)
const result = removeUncommonSpacesFromBlocks(blocks)
expect(result).toEqual([])
})
})

0 comments on commit 7626420

Please sign in to comment.