diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..7a73a41bf --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/package.json b/package.json index f1a96c3ed..aac3ee047 100644 --- a/package.json +++ b/package.json @@ -204,7 +204,7 @@ "transformIgnorePatterns": [ "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$", "^.+\\.module\\.(css|sass|scss)$", - "node_modules\/(?!axios)" + "node_modules/(?!axios)" ], "modulePaths": [ "src" diff --git a/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterContent.js b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterContent.js index 54eb5b391..6d379189e 100644 --- a/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterContent.js +++ b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterContent.js @@ -25,7 +25,7 @@ let Tags = ({data, handleDelete}) => { } return ( - + {data} - {tags.map((data) => { - const uuid = uuidv4(); - return ( - - )})} + {tags.map((data) => + () + )} diff --git a/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterContent.test.js b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterContent.test.js new file mode 100644 index 000000000..fb92d0cdc --- /dev/null +++ b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterContent.test.js @@ -0,0 +1,49 @@ +import { render, screen } from '@testing-library/react'; +// TypeError: Cannot read properties of undefined (reading '__buildHTMLFromChapter') +// (src/screens/EPub/controllers/file-builders/EPubParser.js:6:46) +import { v4 as uuidv4 } from 'uuid'; +import ChapterContent from './ChapterContent'; + +const test_uuid = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'; + +jest.mock('uuid', () => { + return { + v4: jest.fn(() => test_uuid), + }; +}); + + +describe('ChapterContent Component', () => { + const mockDispatch = jest.fn(); + const mockOnInsert = jest.fn(); + const mockOnRemove = jest.fn(); + const mockOnTextChange = jest.fn(); + const mockOnImageChange = jest.fn(); + + const props = { + id: 'ch-content-12345-uuid-0', + key: 'ch-content-12345-uuid-12345', + content: 'Sample text content', + index: 0, + dispatch: mockDispatch, + onRemove: mockOnRemove, + onTextChange: mockOnTextChange, + onImageChange: mockOnImageChange, + onInsert: mockOnInsert, + }; + + it('should render text content correctly', () => { + render(); + + expect(screen.getByText('Sample text content')).toBeVisible(); + }); + + it('should render Tags components with correct keys', () => { + render(); + + const tags = screen.getAllByTestId('ChapterContent-test-tag'); + tags.forEach((tag) => { + expect(tag).toHaveAttribute('key', `tag-${props.key}-${test_uuid}`); + }); + }); + }); diff --git a/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterInfo.js b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterInfo.js index 0083c6cb1..92d6aaf72 100644 --- a/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterInfo.js +++ b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterInfo.js @@ -60,12 +60,11 @@ function ChapterInfo({ chapter, currChIndex, dispatch }) { onSave={onSaveTitle} /> - {contents.map((content, index) => { - const uuid = uuidv4(); - return ( + {contents.map((content, index) => + ( - )})} + ))} diff --git a/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterInfo.test.js b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterInfo.test.js new file mode 100644 index 000000000..f7aef4223 --- /dev/null +++ b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/ChapterInfo.test.js @@ -0,0 +1,29 @@ +import { render, screen } from '@testing-library/react'; +import { v4 as uuidv4 } from 'uuid'; +import ChapterInfo from './ChapterInfo'; + +const test_uuid = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'; + +jest.mock('uuid', () => { + return { + v4: jest.fn(() => test_uuid), + }; +}); + +describe('ChapterInfo Component', () => { + const baseProps = { + chapter: { id: 'chapter-id-1', title: 'Sample Chapter', contents: ["content 1", "content 2"], condition: "condition"}, + currChIndex: 0, + dispatch: jest.fn() + }; + + it('should render ChapterInfo components with correct keys', () => { + // Invariant Violation: Could not find "store" + render(); + + const contents = screen.getAllByTestId('ChapterInfo-test-tag'); + contents.forEach((content) => { + expect(content).toHaveAttribute('key', `ch-content-chapter-id-1-${test_uuid}`); + }); + }); +}); \ No newline at end of file diff --git a/src/screens/EPub/views/EditEPubChapter/ChapterEditor/SubChapterItem.js b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/SubChapterItem.js index 601be88da..37ad16b4c 100644 --- a/src/screens/EPub/views/EditEPubChapter/ChapterEditor/SubChapterItem.js +++ b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/SubChapterItem.js @@ -67,12 +67,11 @@ function SubChapterItem({ onSave={onSaveTitle} /> - {contents.map((content, index) => { - const uuid = uuidv4(); - return ( + {contents.map((content, index) => + ( - )})} + ))} diff --git a/src/screens/EPub/views/EditEPubChapter/ChapterEditor/SubChapterItem.test.js b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/SubChapterItem.test.js new file mode 100644 index 000000000..d4ab2aa52 --- /dev/null +++ b/src/screens/EPub/views/EditEPubChapter/ChapterEditor/SubChapterItem.test.js @@ -0,0 +1,30 @@ +import { render, screen } from '@testing-library/react'; +import { v4 as uuidv4 } from 'uuid'; +import SubChapterItem from './SubChapterItem'; + +const test_uuid = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'; + +jest.mock('uuid', () => { + return { + v4: jest.fn(() => test_uuid), + }; +}); + +describe('SubChapterItem Component', () => { + const baseProps = { + subChapter: { title: "title", id: 'chapter-id-1', contents : ["content 1", "content 2"] }, + subChapterIndex: 0, + currChIndex: 0, + dispatch: jest.fn() + }; + + it('should render SubChapterItem components with correct keys', () => { + // Invariant Violation: Could not find "store" + render(); + + const contents = screen.getAllByTestId('SubChapterItem-test-tag'); + contents.forEach((content) => { + expect(content).toHaveAttribute('key', `sch-content-chapter-id-1-${test_uuid}}`); + }); + }); +}); \ No newline at end of file diff --git a/src/screens/EPub/views/EditINote/INoteEditor/INoteChapter.js b/src/screens/EPub/views/EditINote/INoteEditor/INoteChapter.js index bdf80e936..23aeb2da3 100644 --- a/src/screens/EPub/views/EditINote/INoteEditor/INoteChapter.js +++ b/src/screens/EPub/views/EditINote/INoteEditor/INoteChapter.js @@ -247,10 +247,9 @@ function INoteChapter ({ ) : (// If the chapter has elements, then iterate through all of them - chapter.contents.map((content, itemIdx) => { - const uuid = uuidv4(); - return ( - + chapter.contents.map((content, itemIdx) => + ( + {mergeChapterBtnElement(itemIdx)} {splitBtnElement(itemIdx)} @@ -306,7 +305,7 @@ function INoteChapter ({ {watchVideoElement(chapter.contents.length)} )} - )}))} + )))} {insertType !== null && ( diff --git a/src/screens/EPub/views/EditINote/INoteEditor/INoteChapter.test.js b/src/screens/EPub/views/EditINote/INoteEditor/INoteChapter.test.js new file mode 100644 index 000000000..ffdb48b5e --- /dev/null +++ b/src/screens/EPub/views/EditINote/INoteEditor/INoteChapter.test.js @@ -0,0 +1,31 @@ +import { render, screen } from '@testing-library/react'; +// TypeError: Cannot read properties of undefined (reading '__buildHTMLFromChapter') +// (src/screens/EPub/controllers/file-builders/EPubParser.js:6:46) +import { v4 as uuidv4 } from 'uuid'; +import INoteChapter from './INoteChapter'; + +const test_uuid = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'; + +jest.mock('uuid', () => { + return { + v4: jest.fn(() => test_uuid), + }; +}); + +describe('INoteChapter Component', () => { + const baseProps = { + chapter: {id: "chapter-id-1", title: "Sample title"}, + chIdx: 0, + images: [], + dispatch: jest.fn() + }; + + it('should render INoteChapter components with correct keys', () => { + render(); + + const contents = screen.getAllByTestId('content'); + contents.forEach((content) => { + expect(content).toHaveAttribute('key', `ch-content-chapter-id-1-${test_uuid}}`); + }); + }); +}); \ No newline at end of file