-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #733 dont use index for keys testcases #823
base: staging
Are you sure you want to change the base?
Changes from all commits
38d0a7e
7ed8a9d
f5676cd
fa245af
963b50b
dc21b64
453c733
94c8ed0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,7 +204,7 @@ | |
"transformIgnorePatterns": [ | ||
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$", | ||
"^.+\\.module\\.(css|sass|scss)$", | ||
"node_modules\/(?!axios)" | ||
"node_modules/(?!axios)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice catch! |
||
], | ||
"modulePaths": [ | ||
"src" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. really good use of mock for a randomized ID from an external library. Once you merge this PR, you should definitely add this as an example test file in the Testing wiki |
||
return { | ||
v4: jest.fn(() => test_uuid), | ||
}; | ||
}); | ||
|
||
|
||
describe('ChapterContent Component', () => { | ||
const mockDispatch = jest.fn(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we aren't using these variables anywhere else, might be simpler to just have |
||
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(<ChapterContent {...props} />); | ||
|
||
expect(screen.getByText('Sample text content')).toBeVisible(); | ||
}); | ||
|
||
it('should render Tags components with correct keys', () => { | ||
render(<ChapterContent {...props} />); | ||
|
||
const tags = screen.getAllByTestId('ChapterContent-test-tag'); | ||
tags.forEach((tag) => { | ||
expect(tag).toHaveAttribute('key', `tag-${props.key}-${test_uuid}`); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(<ChapterInfo {...baseProps} />); | ||
|
||
const contents = screen.getAllByTestId('ChapterInfo-test-tag'); | ||
contents.forEach((content) => { | ||
expect(content).toHaveAttribute('key', `ch-content-chapter-id-1-${test_uuid}`); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(<SubChapterItem {...baseProps} />); | ||
|
||
const contents = screen.getAllByTestId('SubChapterItem-test-tag'); | ||
contents.forEach((content) => { | ||
expect(content).toHaveAttribute('key', `sch-content-chapter-id-1-${test_uuid}}`); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(<INoteChapter {...baseProps} />); | ||
|
||
const contents = screen.getAllByTestId('content'); | ||
contents.forEach((content) => { | ||
expect(content).toHaveAttribute('key', `ch-content-chapter-id-1-${test_uuid}}`); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a good idea to add this to the
.gitignore
, that way git won't accidently pick up config files.