-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Custom message unit test setup (duplicate) #398
Closed
liamcho
wants to merge
14
commits into
feat/AC-44290-compare-markdown-libraries-2
from
feat/AC-44290-compare-markdown-libraries-2_unit-test-setup
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6d1ce51
temp
liamcho 7c5fab5
fix
liamcho ffa5e18
testing
liamcho 73a0580
testing
liamcho 117fd03
applied all markdown syntaxes
liamcho 3147a49
apply feeds
liamcho 88a7d10
apply feeds
liamcho 007431a
apply feeds
liamcho 96cefa1
lazy load markdown library
liamcho 9ee75e1
Added new tests
liamcho bae8051
Format
liamcho 6bef0d9
apply feeds
liamcho c7903de
fix
liamcho ca90f0c
Added unit test for markdown message
liamcho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
+172 Bytes
(100%)
__visual_tests__/__snapshots__/workflow-tests.spec.ts/101-1-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.74 KB
(100%)
__visual_tests__/__snapshots__/workflow-tests.spec.ts/101-1-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.7 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-1-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+48 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-1-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.1 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-2-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+48 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-2-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.2 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-3-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+50.5 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-3-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.6 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-4-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+46.4 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-4-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-5-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.1 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-5-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
/** | ||
* markdown message | ||
*/ | ||
test(`100`, async ({ page }) => { | ||
const message = | ||
'# A demo of `react-markdown`\n' + | ||
'\n' + | ||
'`react-markdown` is a markdown component for React.\n' + | ||
'\n' + | ||
'👉 Changes are re-rendered as you type.\n' + | ||
'\n' + | ||
'👈 Try writing some markdown on the left.\n' + | ||
'\n' + | ||
'## Overview\n' + | ||
'\n' + | ||
'* Follows [CommonMark](https://commonmark.org)\n' + | ||
'* Optionally follows [GitHub Flavored Markdown](https://github.github.com/gfm/)\n' + | ||
'* Renders actual React elements instead of using `dangerouslySetInnerHTML`\n' + | ||
"* Lets you define your own components (to render `MyHeading` instead of `'h1'`)\n" + | ||
'* Has a lot of plugins\n' + | ||
'\n' + | ||
'## Contents\n' + | ||
'\n' + | ||
'Here is an example of a plugin in action\n' + | ||
'([`remark-toc`](https://github.com/remarkjs/remark-toc)).\n' + | ||
'**This section is replaced by an actual table of contents**.\n' + | ||
'\n' + | ||
'## Syntax highlighting\n' + | ||
'\n' + | ||
'Here is an example of a plugin to highlight code:\n' + | ||
'[`rehype-highlight`](https://github.com/rehypejs/rehype-highlight).\n' + | ||
'\n' + | ||
'```js\n' + | ||
"import React from 'react'\n" + | ||
"import ReactDOM from 'react-dom'\n" + | ||
"import Markdown from 'react-markdown'\n" + | ||
"import rehypeHighlight from 'rehype-highlight'\n" + | ||
'\n' + | ||
'const markdown = `\n' + | ||
'# Your markdown here\n' + | ||
'`\n' + | ||
'\n' + | ||
'ReactDOM.render(\n' + | ||
' <Markdown rehypePlugins={[rehypeHighlight]}>{markdown}</Markdown>,\n' + | ||
" document.querySelector('#content')\n" + | ||
')\n' + | ||
'```\n' + | ||
'\n' + | ||
'Pretty neat, eh?\n' + | ||
'\n' + | ||
'## GitHub flavored markdown (GFM)\n' + | ||
'\n' + | ||
'For GFM, you can *also* use a plugin:\n' + | ||
'[`remark-gfm`](https://github.com/remarkjs/react-markdown#use).\n' + | ||
'It adds support for GitHub-specific extensions to the language:\n' + | ||
'tables, strikethrough, tasklists, and literal URLs.\n' + | ||
'\n' + | ||
'These features **do not work by default**.\n' + | ||
'👆 Use the toggle above to add the plugin.\n' + | ||
'\n' + | ||
'| Feature | Support |\n' + | ||
'| ---------: | :------------------- |\n' + | ||
'| CommonMark | 100% |\n' + | ||
'| GFM | 100% w/ `remark-gfm` |\n' + | ||
'\n' + | ||
'~~strikethrough~~\n' + | ||
'\n' + | ||
'* [ ] task list\n' + | ||
'* [x] checked item\n' + | ||
'\n' + | ||
'https://example.com\n' + | ||
'\n' + | ||
'## HTML in markdown\n' + | ||
'\n' + | ||
'⚠️ HTML in markdown is quite unsafe, but if you want to support it, you can\n' + | ||
'use [`rehype-raw`](https://github.com/rehypejs/rehype-raw).\n' + | ||
'You should probably combine it with\n' + | ||
'[`rehype-sanitize`](https://github.com/rehypejs/rehype-sanitize).\n' + | ||
'\n' + | ||
'<blockquote>\n' + | ||
' 👆 Use the toggle above to add the plugin.\n' + | ||
'</blockquote>\n' + | ||
'\n' + | ||
'## Components\n' + | ||
'\n' + | ||
'You can pass components to change things:\n' + | ||
'\n' + | ||
'```js\n' + | ||
"import React from 'react'\n" + | ||
"import ReactDOM from 'react-dom'\n" + | ||
"import Markdown from 'react-markdown'\n" + | ||
"import MyFancyRule from './components/my-fancy-rule.js'\n" + | ||
'\n' + | ||
'const markdown = `\n' + | ||
'# Your markdown here\n' + | ||
'`\n' + | ||
'\n' + | ||
'ReactDOM.render(\n' + | ||
' <Markdown\n' + | ||
' components={{\n' + | ||
' // Use h2s instead of h1s\n' + | ||
" h1: 'h2',\n" + | ||
' // Use a component instead of hrs\n' + | ||
' hr(props) {\n' + | ||
' const {node, ...rest} = props\n' + | ||
' return <MyFancyRule {...rest} />\n' + | ||
' }\n' + | ||
' }}\n' + | ||
' >\n' + | ||
' {markdown}\n' + | ||
' </Markdown>,\n' + | ||
" document.querySelector('#content')\n" + | ||
')\n' + | ||
'```\n' + | ||
'\n' + | ||
'## More info?\n' + | ||
'\n' + | ||
'Much more info is available in the\n' + | ||
'[readme on GitHub](https://github.com/remarkjs/react-markdown)!\n' + | ||
'\n' + | ||
'***\n' + | ||
'\n' + | ||
'A component by [Espen Hovlandsdal](https://espen.codes/)'; | ||
|
||
// For logging. | ||
// page.on('console', msg => console.log('BROWSER LOG:', msg.text())); | ||
|
||
await page.goto('http://localhost:5273/', { waitUntil: 'networkidle' }); | ||
|
||
// Ensure the root is loaded | ||
const appRoot = page.locator('[data-testid="snapshot-unit-test-app-root"]'); | ||
await expect(appRoot).toBeVisible(); | ||
|
||
// Debug: Ensure CustomMessage is not already there | ||
const preRenderCheck = await page.isVisible('[data-testid="wowwow"]'); | ||
expect(preRenderCheck).toBeFalsy(); // Assert false | ||
|
||
// Simulate setting a message through a mocked action | ||
await page.evaluate((msg) => { | ||
if (typeof (window as any).setMessage === 'function') { | ||
(window as any).setMessage(msg); | ||
} else { | ||
throw new Error('setMessage not exposed!'); | ||
} | ||
}, message); | ||
|
||
await page.waitForSelector('[data-testid="wowwow"]', { | ||
state: 'visible', | ||
timeout: 5000, // Give React time to re-render | ||
}); | ||
|
||
const customMessage = page.locator('[data-testid="wowwow"]'); | ||
await customMessage.isVisible(); | ||
await expect(customMessage).toHaveScreenshot({ omitBackground: false }); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Widget snapshot unit test</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@sendbird/visual-unit-test", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc -b && vite build", | ||
"lint": "eslint .", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.15.0", | ||
"@types/react": "^18.3.12", | ||
"@types/react-dom": "^18.3.1", | ||
"@vitejs/plugin-react": "^4.3.4", | ||
"globals": "^15.12.0", | ||
"typescript": "~5.6.2", | ||
"typescript-eslint": "^8.15.0", | ||
"vite": "^6.0.1" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { UserMessage } from '@sendbird/chat/message'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { getMockedUserMessage } from './utils.ts'; | ||
import CustomMessage from '../../../src/components/CustomMessage.tsx'; | ||
|
||
const App = () => { | ||
const [message, setMessage] = useState<UserMessage | null>(getMockedUserMessage()); | ||
|
||
// Expose setMessage for testing purposes | ||
useEffect(() => { | ||
if (import.meta.env.MODE === 'test') { | ||
(window as any).setMessage = (msg: string) => { | ||
setMessage(getMockedUserMessage(msg)); | ||
}; | ||
} | ||
}, []); | ||
|
||
return ( | ||
<div data-testid="snapshot-unit-test-app-root"> | ||
<h1>Test</h1> | ||
{message && ( | ||
<div data-testid="wowwow"> | ||
{/*FIXME: Note that below component must be wrapped with ChatProvider.*/} | ||
<CustomMessage message={message} activeSpinnerId={-1} /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that
CustomMessage
must be wrapped withChatProvider
in order for this app to work.