Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/code-view/__tests__/code-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ describe("CodeView", () => {
cleanup();
});
test("correctly renders simple content", () => {
render(<CodeView content={"Hello World"}></CodeView>);
const wrapper = createWrapper()!.findCodeView();
expect(wrapper!.findContent().getElement()).toHaveTextContent("Hello World");
const input = "Hello World";
render(<CodeView content={input}></CodeView>);
const wrapper = createWrapper()!.findCodeView()!;
expect(wrapper.findContent().getElement().textContent).toBe(input);
});

test("correctly renders multi line content", () => {
render(<CodeView content={`# Hello World\n\nThis is a markdown example.`}></CodeView>);
const input = `# Hello World\n\nThis is a markdown example.`;
render(<CodeView content={input}></CodeView>);
const wrapper = createWrapper()!.findCodeView()!;
const content = wrapper.findContent();
expect(content.getElement()).toHaveTextContent("# Hello World This is a markdown example.");
expect(wrapper.findContent().getElement().textContent).toBe(input);
});

test("preserves a trailing newline when present in the input", () => {
const input = "a\nb\n";
render(<CodeView content={input}></CodeView>);
const wrapper = createWrapper()!.findCodeView()!;
expect(wrapper.findContent().getElement().textContent).toBe(input);
});

test("correctly renders table markup with line numbers", () => {
Expand Down Expand Up @@ -102,6 +110,13 @@ describe("CodeView", () => {
expect(getByText(element, '"world"')).toHaveClass("ace_string");
});

test("renders highlighted content without trailing newline", () => {
const input = 'const hello: string = "world";';
render(<CodeView content={input} highlight={typescriptHighlightRules}></CodeView>);
const wrapper = createWrapper()!.findCodeView()!;
expect(wrapper.findContent().getElement().textContent).toBe(input);
});

test("sets nowrap class to line if linesWrapping undefined", () => {
render(<CodeView content={"Hello World"}></CodeView>);
const wrapper = createWrapper().findCodeView()!;
Expand Down
2 changes: 1 addition & 1 deletion src/code-view/highlight/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function createHighlight(rules: Ace.HighlightRules): CreateHighlightType
token.value
);
})}
{"\n"}
{lineIndex < tokens.length - 1 ? "\n" : ""}
</Fragment>
))}
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/code-view/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const textHighlight = (code: string) => {
{lines.map((line, lineIndex) => (
<span key={lineIndex}>
{line}
{"\n"}
{lineIndex < lines.length - 1 ? "\n" : ""}
</span>
))}
</span>
Expand Down
Loading