-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into separate-awards-perf
- Loading branch information
Showing
18 changed files
with
344 additions
and
28 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
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
55 changes: 55 additions & 0 deletions
55
...es/js/features/forums/components/ShortcodeRenderer/ShortcodeQuote/ShortcodeQuote.test.tsx
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,55 @@ | ||
import { render, screen } from '@/test'; | ||
|
||
import { ShortcodeQuote } from './ShortcodeQuote'; | ||
|
||
describe('Component: ShortcodeQuote', () => { | ||
it('renders without crashing', () => { | ||
// ARRANGE | ||
const { container } = render(<ShortcodeQuote>Test content</ShortcodeQuote>); | ||
|
||
// ASSERT | ||
expect(container).toBeTruthy(); | ||
}); | ||
|
||
it('given a simple string child, renders it inside a span with the quotedtext class', () => { | ||
// ARRANGE | ||
render(<ShortcodeQuote>test content</ShortcodeQuote>); | ||
|
||
// ASSERT | ||
const spanEl = screen.getByText(/test content/i); | ||
|
||
expect(spanEl).toBeVisible(); | ||
expect(spanEl).toHaveClass('quotedtext'); | ||
}); | ||
|
||
it('removes leading line breaks in the output', () => { | ||
// ARRANGE | ||
render( | ||
<ShortcodeQuote> | ||
<br /> | ||
test content | ||
</ShortcodeQuote>, | ||
); | ||
|
||
// ASSERT | ||
const spanEl = screen.getByText(/test/i); | ||
expect(spanEl).toBeVisible(); | ||
expect(spanEl.innerHTML).toEqual('test content'); | ||
}); | ||
|
||
it('retains inner line breaks in the output', () => { | ||
// ARRANGE | ||
render( | ||
<ShortcodeQuote> | ||
test | ||
<br /> | ||
content | ||
</ShortcodeQuote>, | ||
); | ||
|
||
// ASSERT | ||
const spanEl = screen.getByText(/test/i); | ||
expect(spanEl).toBeVisible(); | ||
expect(spanEl.innerHTML).toEqual('test<br>content'); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
resources/js/features/forums/components/ShortcodeRenderer/ShortcodeQuote/ShortcodeQuote.tsx
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 @@ | ||
import type { FC, ReactNode } from 'react'; | ||
|
||
interface ShortcodeQuoteProps { | ||
children: ReactNode; | ||
} | ||
|
||
export const ShortcodeQuote: FC<ShortcodeQuoteProps> = ({ children }) => { | ||
// Remove leading <br>s and empty strings until we find content. | ||
let isLeadingWhitespace = true; | ||
const processedChildren = (Array.isArray(children) ? children : [children]).filter((node) => { | ||
if (isLeadingWhitespace) { | ||
const isObjectNode = typeof node === 'object' && node !== null; | ||
const isEmptyObject = isObjectNode && !Object.keys(node as object).length; | ||
const isBRElement = isObjectNode && 'type' in node && node.type === 'br'; | ||
const isEmptyString = typeof node === 'string' && node.trim() === ''; | ||
|
||
isLeadingWhitespace = isEmptyObject || isBRElement || isEmptyString; | ||
} | ||
|
||
// If it isn't leading whitespace, it can stay. | ||
// Otherwise, it's filtered out. | ||
return !isLeadingWhitespace; | ||
}); | ||
|
||
return <span className="quotedtext mb-3">{processedChildren}</span>; | ||
}; |
1 change: 1 addition & 0 deletions
1
resources/js/features/forums/components/ShortcodeRenderer/ShortcodeQuote/index.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ShortcodeQuote'; |
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
Oops, something went wrong.