|
1 | 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | | -import { cleanup, render } from "@testing-library/react"; |
| 3 | +import { cleanup, getByText, render } from "@testing-library/react"; |
4 | 4 | import { afterEach, describe, expect, test } from "vitest"; |
5 | 5 | import CodeView from "../../../lib/components/code-view"; |
| 6 | +import typescriptHighlightRules from "../../../lib/components/code-view/highlight/typescript"; |
6 | 7 | import styles from "../../../lib/components/code-view/styles.css.js"; |
7 | 8 | import createWrapper from "../../../lib/components/test-utils/dom"; |
8 | 9 |
|
@@ -58,4 +59,16 @@ describe("CodeView", () => { |
58 | 59 | const wrapper = createWrapper().findCodeView()!; |
59 | 60 | expect(wrapper!.findContent().getElement().innerHTML).toContain('class="tokenized"'); |
60 | 61 | }); |
| 62 | + |
| 63 | + test("correctly tokenizes content if highlight is set to language rules", () => { |
| 64 | + render(<CodeView content={'const hello: string = "world";'} highlight={typescriptHighlightRules}></CodeView>); |
| 65 | + const wrapper = createWrapper().findCodeView()!; |
| 66 | + const element = wrapper!.findContent().getElement(); |
| 67 | + |
| 68 | + // Check that the content is tokenized following typescript rules. |
| 69 | + expect(getByText(element, "const")).toHaveClass("ace_type"); |
| 70 | + expect(getByText(element, "hello")).toHaveClass("ace_identifier"); |
| 71 | + expect(getByText(element, "string")).toHaveClass("ace_type"); |
| 72 | + expect(getByText(element, '"world"')).toHaveClass("ace_string"); |
| 73 | + }); |
61 | 74 | }); |
0 commit comments