-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(embed): handle snippet not found
- Loading branch information
1 parent
ff35be7
commit dbc26df
Showing
12 changed files
with
116 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
DATABASE_URL="mysql:https://root:@127.0.0.1:3311/sharingan" | ||
EMBED_STYLE_URL=https://cdn.jsdelivr.net/npm/sharingan-embed@latest/style.min.css | ||
EMBED_JS_URL=https://cdn.jsdelivr.net/npm/sharingan-embed@latest/script.min.js | ||
WEB_APP_URL=http:https://localhost:7500 | ||
ENV=development | ||
SENTRY_DSN= | ||
WEB_APP_URL=http:https://localhost:7500 | ||
WEB_APP_SNIPPET_VIEW_URL=http:https://localhost:7500/snippets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 16 additions & 2 deletions
18
packages/embed/src/renderer/content/tests/html-generator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
import { generateNoSnippetHtmlContent } from '../html-generator'; | ||
|
||
describe('Test HTML generator functions', () => { | ||
it('should generates html content for a non existing code snippet', () => {}); | ||
it.only('should generates html content for a non existing code snippet', () => { | ||
// GIVEN | ||
const WEB_APP_URL = 'https://sharingan.dev'; | ||
|
||
// WHEN | ||
const result = generateNoSnippetHtmlContent(WEB_APP_URL); | ||
|
||
it('should generates html content for a code snippet', () => {}); | ||
// THEN | ||
expect(result).toMatchInlineSnapshot(` | ||
"<div class="no-content"> | ||
<h3>Oops! Snippet not found!</h3> | ||
<div>Go to <a href="https://sharingan.dev" target="_blank">Sharingan</a> to ensure it exists and is accessible</div> | ||
</div>" | ||
`); | ||
}); | ||
}); |
73 changes: 71 additions & 2 deletions
73
packages/embed/src/renderer/content/tests/preview-template.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,74 @@ | ||
import { Args, generateHTMLPreview } from '../preview-template'; | ||
|
||
describe('Test generateHTMLPreview()', () => { | ||
it('should generates the html preview for a non existing code snippet', () => {}); | ||
it('should generates the html preview for a code snippet', () => { | ||
// GIVEN | ||
const args: Args = { | ||
code: | ||
'<span class="line">export const hashPassword = (password: string): string => {</span>\n' + | ||
'<span class="line"> const SALT_ROUNDS = 10;</span>\n' + | ||
'<span class="line"></span>\n' + | ||
'<span class="line"> return bcrypt.hashSync(password, SALT_ROUNDS);</span>\n' + | ||
'<span class="line">};</span>', | ||
color: '#f5f5f5', | ||
rawCode: | ||
'export const hashPassword = (password: string): string => {\n' + | ||
' const SALT_ROUNDS = 10;\n' + | ||
'\n' + | ||
' return bcrypt.hashSync(password, SALT_ROUNDS);\n' + | ||
'};', | ||
scriptUrl: 'https://cdn.com/sharigan/script.js', | ||
styleUrl: 'https://cdn.com/sharigan/style.css', | ||
title: 'helpers.ts', | ||
webAppUrl: 'https://sharingan.dev', | ||
}; | ||
|
||
// WHEN | ||
const result = generateHTMLPreview(args); | ||
|
||
// THEN | ||
expect(result).toMatchInlineSnapshot(` | ||
" | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="robots" content="noindex,"> | ||
<title>Sharingan - helpers.ts</title> | ||
<link rel="stylesheet" type="text/css" href="https://cdn.com/sharigan/style.css" /> | ||
</head> | ||
<body data-id="4D3Wsb"> | ||
<div class="ctner"> | ||
<div class="ctner-header"> | ||
<div>helpers.ts</div> | ||
<div>view on <a href="https://sharingan.dev" target="_blank">Sharingan</a></div> | ||
</div> | ||
<textarea id="raw-code-4D3Wsb" class="hidden" rows="1" cols="1">export const hashPassword = (password: string): string => { | ||
const SALT_ROUNDS = 10; | ||
it('should generates the html preview for a code snippet', () => {}); | ||
return bcrypt.hashSync(password, SALT_ROUNDS); | ||
};</textarea> | ||
<div class="code-editor-container" id="code-4D3Wsb" style="border: solid 1px #f5f5f5; background-color: #f5f5f5"> | ||
<button id="btn-copy-4D3Wsb" class="btn-copy hidden" style=""> | ||
<svg class="ic show" id="ic-copy-4D3Wsb" fill="none" stroke="#fff" viewBox="0 0 24 24" xmlns="http:https://www.w3.org/2000/svg"> | ||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path> | ||
</svg> | ||
<svg class="ic hidden" id="ic-copied-4D3Wsb" fill="none" stroke="#10B981" viewBox="0 0 24 24" xmlns="http:https://www.w3.org/2000/svg"> | ||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path> | ||
</svg> | ||
</button> | ||
<pre><span class="line">export const hashPassword = (password: string): string => {</span> | ||
<span class="line"> const SALT_ROUNDS = 10;</span> | ||
<span class="line"></span> | ||
<span class="line"> return bcrypt.hashSync(password, SALT_ROUNDS);</span> | ||
<span class="line">};</span></pre> | ||
</div> | ||
</div> | ||
<script type="text/javascript" src="https://cdn.com/sharigan/script.js"></script> | ||
</body> | ||
</html> | ||
" | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters