-
Notifications
You must be signed in to change notification settings - Fork 40
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
test/add more table test #527
Conversation
WalkthroughThis pull request introduces new test suites for various functionalities within the table module. It includes tests for the Changes
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 3
🧹 Nitpick comments (5)
packages/table-module/__tests__/utils/util.test.ts (1)
3-23
: Test suite looks good, consider adding edge cases.The test cases cover the basic functionality well. Consider adding:
- Edge case for empty prefix
- Test for consistent string format (e.g., length, character set)
- Multiple consecutive calls to strengthen uniqueness test
describe('genRandomStr', () => { // ... existing tests ... + + it('should handle empty prefix', () => { + const result = genRandomStr('') + expect(result).toMatch(/^-/) + }) + + it('should generate strings with consistent format', () => { + const result = genRandomStr() + expect(result).toMatch(/^r-[a-zA-Z0-9]{8}$/) + }) + + it('should generate multiple unique strings', () => { + const results = new Set(Array.from({ length: 100 }, () => genRandomStr())) + expect(results.size).toBe(100) + }) })packages/table-module/__tests__/utils/point.test.ts (1)
3-31
: Enhance Point class test coverage.While the basic functionality is well tested, consider adding:
- Edge cases with zero/negative coordinates
- Tests to ensure Point instances are immutable
- Tests for error handling (e.g., non-numeric inputs)
describe('Point', () => { // ... existing tests ... + + test('should handle zero and negative coordinates', () => { + const point1 = new Point(0, 0) + const point2 = new Point(-1, -2) + + expect(point1.x).toBe(0) + expect(point1.y).toBe(0) + expect(point2.x).toBe(-1) + expect(point2.y).toBe(-2) + }) + + test('should be immutable', () => { + const point = new Point(1, 2) + expect(() => { + // @ts-expect-error Testing runtime immutability + point.x = 3 + }).toThrow() + }) + + test('should validate numeric inputs', () => { + expect(() => { + // @ts-expect-error Testing runtime type checking + new Point('1', '2') + }).toThrow() + }) })packages/table-module/__tests__/utils/vdom.test.ts (1)
5-32
: Expand vdom style manipulation test coverage.The current tests cover basic scenarios well. Consider adding:
- Edge cases with null/undefined styles
- Style property overwriting behavior
- Complex nested style objects
describe('addVnodeStyle', () => { // ... existing tests ... + + it('should handle null/undefined styles gracefully', () => { + const vnode: VNode = { data: {} } as VNode + addVnodeStyle(vnode, null as any) + expect(vnode.data?.style).toEqual({}) + + addVnodeStyle(vnode, undefined as any) + expect(vnode.data?.style).toEqual({}) + }) + + it('should properly overwrite existing style properties', () => { + const vnode: VNode = h('div', { style: { color: 'blue', fontSize: '12px' } }) + addVnodeStyle(vnode, { color: 'red' }) + expect(vnode.data?.style).toEqual({ color: 'red', fontSize: '12px' }) + }) + + it('should handle complex nested style objects', () => { + const vnode: VNode = h('div', { + style: { + transform: 'scale(1)', + transition: 'all 0.3s' + } + }) + addVnodeStyle(vnode, { + transform: 'scale(1.1) rotate(45deg)', + animation: 'fade 0.3s' + }) + expect(vnode.data?.style).toEqual({ + transform: 'scale(1.1) rotate(45deg)', + transition: 'all 0.3s', + animation: 'fade 0.3s' + }) + }) })packages/table-module/__tests__/helper.test.ts (2)
8-16
: Add JSDoc comments to helper function.The
setEditorSelection
helper function would benefit from documentation explaining its purpose and parameters.+/** + * Helper function to set the editor's selection state during tests + * @param editor The editor instance + * @param selection Optional selection state, defaults to start of document + */ function setEditorSelection( editor: core.IDomEditor, selection: slate.Selection = {
19-92
: Consider extracting test fixture data.The large content object could be moved to a separate fixture file to improve test readability.
Consider creating a new file
__fixtures__/table-content.ts
and moving the content object there.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/table-module/__tests__/helper.test.ts
(1 hunks)packages/table-module/__tests__/utils/point.test.ts
(1 hunks)packages/table-module/__tests__/utils/util.test.ts
(1 hunks)packages/table-module/__tests__/utils/vdom.test.ts
(1 hunks)
🧰 Additional context used
🪛 ESLint
packages/table-module/__tests__/helper.test.ts
[error] 5-5: 'TableCellElement' is defined but never used.
(@typescript-eslint/no-unused-vars)
editor.selection = selection | ||
} | ||
|
||
describe('hasCommon', () => { |
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.
🛠️ Refactor suggestion
Update describe block name to match tested functionality.
The describe block name 'hasCommon' doesn't match the actual functionality being tested (isCellInFirstRow
).
-describe('hasCommon', () => {
+describe('isCellInFirstRow', () => {
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
describe('hasCommon', () => { | |
describe('isCellInFirstRow', () => { |
import * as slate from 'slate' | ||
|
||
import createEditor from '../../../tests/utils/create-editor' | ||
import { TableCellElement, TableElement } from '../src/module/custom-types' |
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.
🛠️ Refactor suggestion
Remove unused import.
The TableCellElement
import is not being used in the test file.
-import { TableCellElement, TableElement } from '../src/module/custom-types'
+import { TableElement } from '../src/module/custom-types'
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
import { TableCellElement, TableElement } from '../src/module/custom-types' | |
import { TableElement } from '../src/module/custom-types' |
🧰 Tools
🪛 ESLint
[error] 5-5: 'TableCellElement' is defined but never used.
(@typescript-eslint/no-unused-vars)
it('should return true if paths have a common ancestor of type table', () => { | ||
const result = isCellInFirstRow(editor, (editor.children[1] as TableElement).children[0].children[0]) | ||
|
||
expect(result).toBe(true) | ||
// @Todo: test other cases | ||
// @ts-ignore | ||
const result1 = isCellInFirstRow(editor, editor.children[1].children[0]) | ||
|
||
expect(result1).toBe(false) | ||
}) |
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.
🛠️ Refactor suggestion
Improve test coverage and remove @ts-ignore.
The test suite needs improvement:
- The TODO comment indicates missing test cases
- Using @ts-ignore should be avoided
- Test description could be more specific
- it('should return true if paths have a common ancestor of type table', () => {
+ it('should correctly identify cells in the first row', () => {
const result = isCellInFirstRow(editor, (editor.children[1] as TableElement).children[0].children[0])
expect(result).toBe(true)
- // @Todo: test other cases
- // @ts-ignore
- const result1 = isCellInFirstRow(editor, editor.children[1].children[0])
- expect(result1).toBe(false)
+
+ // Test cell in second row
+ const secondRowCell = (editor.children[1] as TableElement).children[1].children[0]
+ expect(isCellInFirstRow(editor, secondRowCell)).toBe(false)
+
+ // Test non-cell element
+ const nonCellElement = editor.children[0]
+ expect(isCellInFirstRow(editor, nonCellElement as any)).toBe(false)
})
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
it('should return true if paths have a common ancestor of type table', () => { | |
const result = isCellInFirstRow(editor, (editor.children[1] as TableElement).children[0].children[0]) | |
expect(result).toBe(true) | |
// @Todo: test other cases | |
// @ts-ignore | |
const result1 = isCellInFirstRow(editor, editor.children[1].children[0]) | |
expect(result1).toBe(false) | |
}) | |
it('should correctly identify cells in the first row', () => { | |
const result = isCellInFirstRow(editor, (editor.children[1] as TableElement).children[0].children[0]) | |
expect(result).toBe(true) | |
// Test cell in second row | |
const secondRowCell = (editor.children[1] as TableElement).children[1].children[0] | |
expect(isCellInFirstRow(editor, secondRowCell)).toBe(false) | |
// Test non-cell element | |
const nonCellElement = editor.children[0] | |
expect(isCellInFirstRow(editor, nonCellElement as any)).toBe(false) | |
}) |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/table-module/__tests__/helper.test.ts (1)
98-112
: Consider breaking down the test cases for better organization.While the test cases cover important scenarios, they could be better organized for clarity and maintainability.
Consider splitting into separate test cases:
- it('should correctly identify cells in the first row', () => { - const result = isCellInFirstRow(editor, (editor.children[1] as TableElement).children[0].children[0]) - expect(result).toBe(true) - - // Test cell in second row - const secondRowCell = (editor.children[1] as TableElement).children[1].children[0] - expect(isCellInFirstRow(editor, secondRowCell)).toBe(false) - - // Test non-cell element - const nonCellElement = editor.children[0] - expect(isCellInFirstRow(editor, nonCellElement as any)).toBe(false) - }) + describe('isCellInFirstRow', () => { + it('should return true for cells in the first row', () => { + const firstRowCell = (editor.children[1] as TableElement).children[0].children[0] + expect(isCellInFirstRow(editor, firstRowCell)).toBe(true) + }) + + it('should return false for cells in other rows', () => { + const secondRowCell = (editor.children[1] as TableElement).children[1].children[0] + expect(isCellInFirstRow(editor, secondRowCell)).toBe(false) + }) + + it('should return false for non-cell elements', () => { + const nonCellElement = editor.children[0] + expect(isCellInFirstRow(editor, nonCellElement as any)).toBe(false) + }) + })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/table-module/__tests__/helper.test.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test
- GitHub Check: test-e2e
🔇 Additional comments (2)
packages/table-module/__tests__/helper.test.ts (2)
1-16
: LGTM! Clean imports and well-defined helper function.The imports are minimal and necessary, and the
setEditorSelection
helper function is well-typed with good defaults.
18-96
: LGTM! Well-structured test data.The test content provides a comprehensive table structure with header cells, multiple rows, and proper dimensions. The setup is thorough and matches real-world scenarios.
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/table-module/__tests__/parse-html.test.ts (1)
100-147
: Improve test data readability with constants and documentation.While the test data structure is comprehensive, it could be more maintainable and self-documenting.
Consider extracting common properties and adding documentation:
+// Common cell properties for merged table cells +const DEFAULT_CELL_PROPS = { + isHeader: false, + width: 'auto', + hidden: false, + borderWidth: '1', + borderStyle: 'solid', + borderColor: '#ccc', +} + +// Empty text node commonly used in cells +const EMPTY_TEXT_NODE = { text: '' } + const mergeChildren = [ { type: 'table-row', children: [ { type: 'table-cell', - isHeader: false, + ...DEFAULT_CELL_PROPS, colSpan: 2, rowSpan: 1, - width: 'auto', - children: [{ text: '' }], - hidden: false, - borderWidth: '1', - borderStyle: 'solid', - borderColor: '#ccc', + children: [EMPTY_TEXT_NODE], }, { type: 'table-cell', - children: [{ text: '' }], + children: [EMPTY_TEXT_NODE], hidden: true, }, { type: 'table-cell', - isHeader: false, + ...DEFAULT_CELL_PROPS, colSpan: 1, rowSpan: 1, - width: 'auto', - children: [{ text: '' }], - hidden: true, - borderWidth: '1', - borderStyle: 'solid', - borderColor: '#ccc', + children: [EMPTY_TEXT_NODE], + hidden: true, }, ], }, ]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/table-module/__tests__/parse-html.test.ts
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test
- GitHub Check: test-e2e
expect(parseTableHtmlConf.parseElemHtml($table[0], mergeChildren, editor)).toEqual({ | ||
type: 'table', | ||
width: '100%', | ||
mergeChildren, | ||
height: 0, | ||
}) |
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.
🛠️ Refactor suggestion
Add a descriptive test case for merged cells.
The test case for merged cells should be in its own it
block with a descriptive name.
Consider restructuring the test:
-expect(parseTableHtmlConf.parseElemHtml($table[0], mergeChildren, editor)).toEqual({
- type: 'table',
- width: '100%',
- mergeChildren,
- height: 0,
-})
+it('should parse table with merged cells', () => {
+ const $table = $('<table style="width: 100%;"></table>')
+ expect(parseTableHtmlConf.parseElemHtml($table[0], mergeChildren, editor)).toEqual({
+ type: 'table',
+ width: '100%',
+ mergeChildren,
+ height: 0,
+ })
+})
Committable suggestion skipped: line range outside the PR's diff.
Changes Overview
Implementation Approach
Testing Done
Verification Steps
Additional Notes
Checklist
Related Issues
Summary by CodeRabbit