import { DOMUtils } from 'nylas-exports'; import BlockquoteManager from '../../src/components/contenteditable/blockquote-manager'; describe("BlockquoteManager", function BlockquoteManagerSpecs() { const outdentCases = [`
|
`, `
|
`, `

\n | `, `

| `, `
|
`, `
|
`, `

yo

|test `, ] const backspaceCases = [`
yo|
`, `
yo |
`, `

  | `, `

yo | `, `
yo|
`, `
yo |
`, `

yo

yo |test `, ] const setupContext = (testCase) => { const context = document.createElement("blockquote"); context.innerHTML = testCase; const {node, index} = DOMUtils.findCharacter(context, "|"); if (!node) { throw new Error("Couldn't find where to set Selection"); } const mockSelection = { isCollapsed: true, anchorNode: node, anchorOffset: index, }; return mockSelection; }; outdentCases.forEach(testCase => it(`outdents\n${testCase}`, () => { const mockSelection = setupContext(testCase); const editor = {currentSelection() { return mockSelection; }}; expect(BlockquoteManager._isInBlockquote(editor)).toBe(true); return expect(BlockquoteManager._isAtStartOfLine(editor)).toBe(true); }) ); return backspaceCases.forEach(testCase => it(`backspaces (does NOT outdent)\n${testCase}`, () => { const mockSelection = setupContext(testCase); const editor = {currentSelection() { return mockSelection; }}; expect(BlockquoteManager._isInBlockquote(editor)).toBe(true); return expect(BlockquoteManager._isAtStartOfLine(editor)).toBe(false); }) ); });