-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support full markdown syntax (#397)
## How to test? - yarn dev. try copy and paste [here](https://remarkjs.github.io/react-markdown/) then send a message. - or send message like below: - can you give me some random message with some markdown syntax applied? - can you give me another one with h1, h2, h3, ol and ul? - include any other markdown syntax I missed out. give me random authentic message. You can also test workflow by sending below message: - give me a markdown message ## Changes - Added support for wider range of markdown syntaxes ticket: [AC-4384] ## Additional Notes - To run snapshot test locally: https://sendbird.atlassian.net/wiki/spaces/AC/pages/2610724994/Widget+snapshot+test+plan ## Checklist Before requesting a code review, please check the following: - [x] **[Required]** CI has passed all checks. - [ ] **[Required]** A self-review has been conducted to ensure there are no minor mistakes. - [ ] **[Required]** Unnecessary comments/debugging code have been removed. - [ ] **[Required]** All requirements specified in the ticket have been accurately implemented. - [ ] Ensure the ticket has been updated with the sprint, status, and story points. [AC-4384]: https://sendbird.atlassian.net/browse/AC-4384?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
Showing
23 changed files
with
453 additions
and
110 deletions.
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
+33.6 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
+42.2 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.2 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
+47.1 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
+49.8 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.9 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
+38.9 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 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.
Binary file added
BIN
+43 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-6-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-6-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,8 @@ | ||
import { test } from '@playwright/test'; | ||
|
||
import { TestUrl, WidgetComponentIds } from './const'; | ||
import { WidgetComponentIds } from './const'; | ||
import { assertScreenshot, clickNthChip, deleteTestResources, loadWidget, sendTextMessage } from './utils/testUtils'; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto(TestUrl); | ||
|
||
const widgetWindow = page.locator(WidgetComponentIds.WIDGET_BUTTON); | ||
await widgetWindow.waitFor({ state: 'visible' }); | ||
}); | ||
|
||
test.afterEach(async ({ page }) => { | ||
await deleteTestResources(page); | ||
/** | ||
|
@@ -58,7 +51,7 @@ test('100', async ({ page, browserName }) => { | |
await inputs.nth(3).fill('[email protected]'); | ||
await inputs.nth(4).fill('123-456-7890'); | ||
await submitButton.click(); | ||
await page.waitForTimeout(1000); | ||
await page.waitForTimeout(2000); | ||
await assertScreenshot(page, '100-4', browserName); | ||
}); | ||
|
||
|
@@ -137,3 +130,69 @@ test('103', async ({ page, browserName }) => { | |
await page.waitForTimeout(2000); | ||
await assertScreenshot(page, '103-6', browserName); | ||
}); | ||
|
||
/** | ||
* 104 | ||
* Workflow - Markdown response | ||
* Steps: | ||
* 1. Send the trigger message: "give me a markdown message" | ||
* 2. Click "Part 2" | ||
* 3. Click "Back" | ||
* 4. Click "Part 3" | ||
* 5. Click "Back" | ||
* 6. Click "Part 4" | ||
*/ | ||
test('104', async ({ page, browserName }) => { | ||
await loadWidget(page); | ||
// 1 | ||
await sendTextMessage(page, 'give me a markdown message', 2000); | ||
|
||
// Check if the fallback component is visible | ||
const fallback = page.locator(WidgetComponentIds.MARKDOWN); | ||
await fallback.first().waitFor({ state: 'visible' }); | ||
let options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(4).waitFor({ state: 'visible' }); | ||
await assertScreenshot(page, '104-1', browserName); | ||
|
||
// 2 | ||
await options.nth(0).click(); | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(0).waitFor({ state: 'visible' }); // Wait for go back button to show | ||
await assertScreenshot(page, '104-2', browserName); | ||
await options.nth(0).click(); // Go back | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(4).waitFor({ state: 'visible' }); | ||
|
||
// 3 | ||
await options.nth(1).click(); | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(0).waitFor({ state: 'visible' }); // Wait for go back button to show | ||
await assertScreenshot(page, '104-3', browserName); | ||
await options.nth(0).click(); // Go back | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(4).waitFor({ state: 'visible' }); | ||
|
||
// 4 | ||
await options.nth(2).click(); | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(0).waitFor({ state: 'visible' }); // Wait for go back button to show | ||
await assertScreenshot(page, '104-4', browserName); | ||
await options.nth(0).click(); // Go back | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(4).waitFor({ state: 'visible' }); | ||
|
||
// 5 | ||
await options.nth(3).click(); | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(0).waitFor({ state: 'visible' }); // Wait for go back button to show | ||
await assertScreenshot(page, '104-5', browserName); | ||
await options.nth(0).click(); // Go back | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(4).waitFor({ state: 'visible' }); | ||
|
||
// 6 | ||
await options.nth(4).click(); | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(0).waitFor({ state: 'visible' }); // Wait for go back button to show | ||
await assertScreenshot(page, '104-6', browserName); | ||
}); |
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,26 +1,43 @@ | ||
import { lazy, Suspense } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { Source } from './SourceContainer'; | ||
import TokensBody, { TextContainer } from './TokensBody'; | ||
import { Token } from '../utils'; | ||
|
||
const TokensBody = lazy(() => import('./TokensBody')); | ||
|
||
type Props = { | ||
text: string; | ||
tokens?: Token[]; | ||
tokens: Token[]; | ||
sources?: Source[]; | ||
}; | ||
|
||
const TextContainer = styled.div` | ||
width: inherit; | ||
text-align: start; | ||
word-break: break-word; | ||
padding: 8px 12px; | ||
gap: 12px; | ||
white-space: pre-wrap; | ||
`; | ||
|
||
/** | ||
* Parses bot message text to process code snippets within the text. | ||
* @param props | ||
* @constructor | ||
*/ | ||
export default function ParsedBotMessageBody(props: Props) { | ||
const { text, tokens, sources } = props; | ||
if (tokens && tokens.length > 0) { | ||
return <TokensBody tokens={tokens} sources={sources} />; | ||
} | ||
|
||
return ( | ||
<TextContainer className="sendbird-word" style={{ borderRadius: 16 }}> | ||
{text} | ||
</TextContainer> | ||
<Suspense | ||
fallback={ | ||
<TextContainer className="sendbird-word" style={{ borderRadius: 16 }}> | ||
{text} | ||
</TextContainer> | ||
} | ||
> | ||
<TokensBody tokens={tokens} sources={sources} /> | ||
</Suspense> | ||
); | ||
} |
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
Oops, something went wrong.