|
| 1 | +import { marksEqual } from '@tiptap/core' |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | + |
| 4 | +describe('marksEqual', () => { |
| 5 | + it('returns true for identical marks with same attrs key order', () => { |
| 6 | + const a = [{ type: 'bold', attrs: { level: 1, color: 'red' } }] |
| 7 | + const b = [{ type: 'bold', attrs: { level: 1, color: 'red' } }] |
| 8 | + expect(marksEqual(a, b)).toBe(true) |
| 9 | + }) |
| 10 | + |
| 11 | + it('returns true for identical marks with different attrs key order', () => { |
| 12 | + const a = [{ type: 'bold', attrs: { level: 1, color: 'red' } }] |
| 13 | + const b = [{ type: 'bold', attrs: { color: 'red', level: 1 } }] |
| 14 | + expect(marksEqual(a, b)).toBe(true) |
| 15 | + }) |
| 16 | + |
| 17 | + it('returns true for identical marks without attrs', () => { |
| 18 | + const a = [{ type: 'italic' }, { type: 'bold' }] |
| 19 | + const b = [{ type: 'italic' }, { type: 'bold' }] |
| 20 | + expect(marksEqual(a, b)).toBe(true) |
| 21 | + }) |
| 22 | + |
| 23 | + it('returns false for marks with different types', () => { |
| 24 | + const a = [{ type: 'bold', attrs: { level: 1 } }] |
| 25 | + const b = [{ type: 'italic', attrs: { level: 1 } }] |
| 26 | + expect(marksEqual(a, b)).toBe(false) |
| 27 | + }) |
| 28 | + |
| 29 | + it('returns false for marks with different attrs', () => { |
| 30 | + const a = [{ type: 'bold', attrs: { level: 1 } }] |
| 31 | + const b = [{ type: 'bold', attrs: { level: 2 } }] |
| 32 | + expect(marksEqual(a, b)).toBe(false) |
| 33 | + }) |
| 34 | + |
| 35 | + it('returns false when arrays have different lengths', () => { |
| 36 | + const a = [{ type: 'bold' }, { type: 'italic' }] |
| 37 | + const b = [{ type: 'bold' }] |
| 38 | + expect(marksEqual(a, b)).toBe(false) |
| 39 | + }) |
| 40 | + |
| 41 | + it('returns false when one has attrs and the other does not', () => { |
| 42 | + const a = [{ type: 'bold', attrs: { level: 1 } }] |
| 43 | + const b = [{ type: 'bold' }] |
| 44 | + expect(marksEqual(a, b)).toBe(false) |
| 45 | + }) |
| 46 | + |
| 47 | + it('returns true for empty arrays', () => { |
| 48 | + expect(marksEqual([], [])).toBe(true) |
| 49 | + }) |
| 50 | +}) |
0 commit comments