Skip to content

Commit

Permalink
chore: add test case(addImage, addLink)
Browse files Browse the repository at this point in the history
  • Loading branch information
js87zz committed Jul 6, 2021
1 parent e05eaac commit 3d7e36c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
22 changes: 22 additions & 0 deletions apps/editor/src/__test__/unit/markdown/mdCommand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@ describe('addImage command', () => {

expect(getTextContent(mde)).toBe('![image](myurl%20%28%29%5B%5D%3C%3E)');
});

it('should not decode url which is already encoded', () => {
cmd.exec('addImage', {
altText: 'image',
imageUrl: 'https://firebasestorage.googleapis.com/images%2Fimage.png?alt=media',
});

expect(getTextContent(mde)).toBe(
'![image](https://firebasestorage.googleapis.com/images%2Fimage.png?alt=media)'
);
});
});

describe('addLink command', () => {
Expand All @@ -318,6 +329,17 @@ describe('addLink command', () => {

expect(getTextContent(mde)).toBe('[TOAST UI](myurl%20%28%29%5B%5D%3C%3E)');
});

it('should not decode url which is already encoded', () => {
cmd.exec('addLink', {
linkText: 'TOAST UI',
linkUrl: 'https://firebasestorage.googleapis.com/links%2Fimage.png?alt=media',
});

expect(getTextContent(mde)).toBe(
'[TOAST UI](https://firebasestorage.googleapis.com/links%2Fimage.png?alt=media)'
);
});
});

describe('heading command', () => {
Expand Down
30 changes: 15 additions & 15 deletions apps/editor/src/__test__/unit/wysiwyg/wwCommand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,14 @@ describe('wysiwyg commands', () => {
expect(wwe.getHTML()).toBe('<p><br></p>');
});

it('should decode attribute and encode wrong markdown charactors', () => {
it('should not decode url which is already encoded', () => {
cmd.exec('addImage', {
imageUrl: 'foo %D1%88%D0%B5%D0%BB%D0%BB%D1%8B ()[]<>',
altText: 'foo ()[]<>',
imageUrl: 'https://firebasestorage.googleapis.com/images%2Fimage.png?alt=media',
altText: 'foo',
});

expect(wwe.getHTML()).toBe(
'<p><img src="foo%20шеллы%20%28%29%5B%5D%3C%3E" alt="foo \\(\\)\\[\\]\\<\\>"><br></p>'
'<p><img src="https://firebasestorage.googleapis.com/images%2Fimage.png?alt=media" alt="foo"><br></p>'
);
});
});
Expand Down Expand Up @@ -520,17 +520,6 @@ describe('wysiwyg commands', () => {
expect(wwe.getHTML()).toBe('<p><br></p>');
});

it('should decode attribute and encode wrong markdown charactors', () => {
cmd.exec('addLink', {
linkUrl: 'foo %D1%88%D0%B5%D0%BB%D0%BB%D1%8B ()[]<>',
linkText: 'foo ()[]<>',
});

expect(wwe.getHTML()).toBe(
'<p><a href="foo%20шеллы%20%28%29%5B%5D%3C%3E">foo ()[]&lt;&gt;</a></p>'
);
});

it('should change link url in selection', () => {
cmd.exec('addLink', {
linkUrl: '#',
Expand All @@ -554,6 +543,17 @@ describe('wysiwyg commands', () => {

expect(wwe.getHTML()).toBe(expected);
});

it('should not decode url which is already encoded', () => {
cmd.exec('addLink', {
linkUrl: 'https://firebasestorage.googleapis.com/links%2Fimage.png?alt=media',
linkText: 'foo',
});

expect(wwe.getHTML()).toBe(
'<p><a href="https://firebasestorage.googleapis.com/links%2Fimage.png?alt=media">foo</a></p>'
);
});
});

describe(`addLink command with 'linkAttributes' option`, () => {
Expand Down

0 comments on commit 3d7e36c

Please sign in to comment.