mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-17 16:44:49 -04:00
Move toolbar functions into redux reducer (#1763)
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
a6a2251c88
commit
b30cc5b390
80 changed files with 2481 additions and 2303 deletions
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { addLink } from './add-link'
|
||||
|
||||
describe('add link', () => {
|
||||
describe('without to-cursor', () => {
|
||||
it('inserts a link', () => {
|
||||
const actual = addLink([''], { from: { line: 0, character: 0 } }, '')
|
||||
expect(actual).toEqual(['[](https://)'])
|
||||
})
|
||||
|
||||
it('inserts a link into a line', () => {
|
||||
const actual = addLink(['aa'], { from: { line: 0, character: 1 } }, '')
|
||||
expect(actual).toEqual(['a[](https://)a'])
|
||||
})
|
||||
|
||||
it('inserts a link with a prefix', () => {
|
||||
const actual = addLink([''], { from: { line: 0, character: 0 } }, 'prefix')
|
||||
expect(actual).toEqual(['prefix[](https://)'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a normal text selected', () => {
|
||||
it('wraps the selection', () => {
|
||||
const actual = addLink(
|
||||
['a'],
|
||||
{
|
||||
from: { line: 0, character: 0 },
|
||||
to: {
|
||||
line: 0,
|
||||
character: 1
|
||||
}
|
||||
},
|
||||
''
|
||||
)
|
||||
expect(actual).toEqual(['[a](https://)'])
|
||||
})
|
||||
|
||||
it('wraps the selection inside of a line', () => {
|
||||
const actual = addLink(['aba'], { from: { line: 0, character: 1 }, to: { line: 0, character: 2 } }, '')
|
||||
expect(actual).toEqual(['a[b](https://)a'])
|
||||
})
|
||||
|
||||
it('wraps the selection with a prefix', () => {
|
||||
const actual = addLink(['a'], { from: { line: 0, character: 0 }, to: { line: 0, character: 1 } }, 'prefix')
|
||||
expect(actual).toEqual(['prefix[a](https://)'])
|
||||
})
|
||||
|
||||
it('wraps a multi line selection', () => {
|
||||
const actual = addLink(['a', 'b', 'c'], { from: { line: 0, character: 0 }, to: { line: 2, character: 1 } }, '')
|
||||
expect(actual).toEqual(['[a', 'b', 'c](https://)'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a url selected', () => {
|
||||
it('wraps the selection', () => {
|
||||
const actual = addLink(
|
||||
['https://google.com'],
|
||||
{
|
||||
from: { line: 0, character: 0 },
|
||||
to: {
|
||||
line: 0,
|
||||
character: 18
|
||||
}
|
||||
},
|
||||
''
|
||||
)
|
||||
expect(actual).toEqual(['[](https://google.com)'])
|
||||
})
|
||||
|
||||
it('wraps the selection with a prefix', () => {
|
||||
const actual = addLink(
|
||||
['https://google.com'],
|
||||
{
|
||||
from: { line: 0, character: 0 },
|
||||
to: {
|
||||
line: 0,
|
||||
character: 18
|
||||
}
|
||||
},
|
||||
'prefix'
|
||||
)
|
||||
expect(actual).toEqual(['prefix[](https://google.com)'])
|
||||
})
|
||||
|
||||
it(`wraps a multi line selection not as link`, () => {
|
||||
const actual = addLink(
|
||||
['a', 'https://google.com', 'c'],
|
||||
{ from: { line: 0, character: 0 }, to: { line: 2, character: 1 } },
|
||||
''
|
||||
)
|
||||
expect(actual).toEqual(['[a', 'https://google.com', 'c](https://)'])
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue