@@ -6,101 +6,13 @@ import * as Host from '../../../core/host/host.js';
66import * as Root from '../../../core/root/root.js' ;
77import { renderElementIntoDOM } from '../../../testing/DOMHelpers.js' ;
88import { describeWithEnvironment } from '../../../testing/EnvironmentHelpers.js' ;
9- import * as Marked from '../../../third_party/marked/marked.js' ;
10- import * as MarkdownView from '../../../ui/components/markdown_view/markdown_view.js' ;
11- import * as Freestyler from '../ai_assistance.js' ;
12-
13- const { MarkdownRendererWithCodeBlock} = Freestyler . FOR_TEST ;
9+ import * as AiAssistance from '../ai_assistance.js' ;
1410
1511describeWithEnvironment ( 'ChatView' , ( ) => {
16- describe ( 'MarkdownRendererWithCodeBlock' , ( ) => {
17- it ( 'should transform code token for multiline code blocks with `css` language written in the first line' , ( ) => {
18- const renderer = new MarkdownRendererWithCodeBlock ( ) ;
19- const templateForTokenStub =
20- sinon . stub ( MarkdownView . MarkdownView . MarkdownInsightRenderer . prototype , 'templateForToken' ) ;
21- const codeBlock = `\`\`\`
22- css
23- * {
24- color: red;
25- }
26- \`\`\`` ;
27- const codeToken = Marked . Marked . lexer ( codeBlock ) [ 0 ] as Marked . Marked . Tokens . Code ;
28- assert . isEmpty ( codeToken . lang ) ;
29- renderer . renderToken ( codeToken ) ;
30-
31- sinon . assert . calledWith ( templateForTokenStub , sinon . match ( {
32- lang : 'css' ,
33- text : `* {
34- color: red;
35- }` ,
36- } ) ) ;
37- } ) ;
38-
39- describe ( 'link/image stripping' , ( ) => {
40- const linkCases = [
41- '[link text](https://z.com)' ,
42- 'A response with [link text](https://z.com).' ,
43- '[*link text*](https://z.com)' ,
44- '[**text** `with code`](https://z.com).' ,
45- 'plain link https://z.com .' ,
46- 'link in quotes \'https://z.com\' .' ,
47- ] ;
48-
49- const renderToElem = ( string : string , renderer : MarkdownView . MarkdownView . MarkdownLitRenderer ) : Element => {
50- const component = new MarkdownView . MarkdownView . MarkdownView ( ) ;
51- renderElementIntoDOM ( component , { allowMultipleChildren : true } ) ;
52- component . data = { tokens : Marked . Marked . lexer ( string ) , renderer} ;
53- assert . exists ( component . shadowRoot ?. firstElementChild ) ;
54- return component . shadowRoot . firstElementChild ;
55- } ;
56-
57- it ( 'strips links if stripLinks true' , ( ) => {
58- const linklessRenderer = new MarkdownRendererWithCodeBlock ( { stripLinks : true } ) ;
59- for ( const linkCase of linkCases ) {
60- const elem = renderToElem ( linkCase , linklessRenderer ) ;
61- assert . lengthOf ( elem . querySelectorAll ( 'a, x-link, devtools-link' ) , 0 ) ;
62- assert . isFalse ( [ '<a' , '<x-link' , '<devtools-link' ] . some ( tagName => elem . outerHTML . includes ( tagName ) ) ) ;
63- assert . isOk ( elem . textContent ?. includes ( '( https://z.com )' ) , linkCase ) ;
64- }
65- } ) ;
66-
67- it ( 'leaves links intact by default' , ( ) => {
68- const linkfulRenderer = new MarkdownRendererWithCodeBlock ( ) ;
69- for ( const linkCase of linkCases ) {
70- const elem = renderToElem ( linkCase , linkfulRenderer ) ;
71- assert . lengthOf ( elem . querySelectorAll ( 'a, x-link, devtools-link' ) , 1 ) ;
72- assert . isTrue ( [ '<a' , '<x-link' , '<devtools-link' ] . some ( tagName => elem . outerHTML . includes ( tagName ) ) ) ;
73- assert . isFalse ( elem . textContent ?. includes ( '( https://z.com )' ) ) ;
74- }
75- } ) ;
76-
77- const imageCases = [
78- '' ,
79- 'A response with .' ,
80- '' ,
81- '.' ,
82- 'plain image href https://z.com/i.png .' ,
83- 'link in quotes \'https://z.com/i.png\' .' ,
84- ] ;
85-
86- it ( 'strips images if stripLinks true' , ( ) => {
87- const linklessRenderer = new MarkdownRendererWithCodeBlock ( { stripLinks : true } ) ;
88- for ( const imageCase of imageCases ) {
89- const elem = renderToElem ( imageCase , linklessRenderer ) ;
90- assert . lengthOf ( elem . querySelectorAll ( 'a, x-link, devtools-link, img, devtools-markdown-image' ) , 0 ) ;
91- assert . isFalse ( [ '<a' , '<x-link' , '<devtools-link' , '<img' , '<devtools-markdown-image' ] . some (
92- tagName => elem . outerHTML . includes ( tagName ) ) ) ;
93-
94- assert . isOk ( elem . textContent ?. includes ( '( https://z.com/i.png )' ) , imageCase ) ;
95- }
96- } ) ;
97- } ) ;
98- } ) ;
99-
100- function getProp ( options : Partial < Freestyler . Props > ) : Freestyler . Props {
12+ function getProp ( options : Partial < AiAssistance . Props > ) : AiAssistance . Props {
10113 const noop = ( ) => { } ;
102- const messages : Freestyler . ChatMessage [ ] = options . messages ?? [ ] ;
103- const selectedContext = sinon . createStubInstance ( Freestyler . NodeContext ) ;
14+ const messages : AiAssistance . ChatMessage [ ] = options . messages ?? [ ] ;
15+ const selectedContext = sinon . createStubInstance ( AiAssistance . NodeContext ) ;
10416 selectedContext . getTitle . returns ( '' ) ;
10517 return {
10618 onTextSubmit : noop ,
11022 onContextClick : noop ,
11123 onNewConversation : noop ,
11224 inspectElementToggled : false ,
113- state : Freestyler . State . CHAT_VIEW ,
114- agentType : Freestyler . AgentType . STYLING ,
25+ state : AiAssistance . State . CHAT_VIEW ,
26+ agentType : AiAssistance . AgentType . STYLING ,
11527 aidaAvailability : Host . AidaClient . AidaAccessPreconditions . AVAILABLE ,
11628 messages,
11729 selectedContext,
13042 const props = getProp ( {
13143 messages : [
13244 {
133- entity : Freestyler . ChatMessageEntity . MODEL ,
45+ entity : AiAssistance . ChatMessageEntity . MODEL ,
13446 steps : [
13547 {
13648 isLoading : false ,
14557 } ,
14658 ] ,
14759 } ) ;
148- const chat = new Freestyler . ChatView ( props ) ;
60+ const chat = new AiAssistance . ChatView ( props ) ;
14961 renderElementIntoDOM ( chat ) ;
15062
15163 const sideEffect = chat . shadowRoot ! . querySelector ( '.side-effect-confirmation' ) ;
15466
15567 it ( 'shows the disabled view when the state is CONSENT_VIEW' , async ( ) => {
15668 const props = getProp ( {
157- state : Freestyler . State . CONSENT_VIEW ,
69+ state : AiAssistance . State . CONSENT_VIEW ,
15870 } ) ;
159- const chat = new Freestyler . ChatView ( props ) ;
71+ const chat = new AiAssistance . ChatView ( props ) ;
16072 renderElementIntoDOM ( chat ) ;
16173
16274 const optIn = chat . shadowRoot ?. querySelector ( '.disabled-view' ) ;
16981
17082 it ( 'shows the disabled view when the AIDA is not available' , async ( ) => {
17183 const props = getProp ( {
172- state : Freestyler . State . CHAT_VIEW ,
84+ state : AiAssistance . State . CHAT_VIEW ,
17385 aidaAvailability : Host . AidaClient . AidaAccessPreconditions . NO_INTERNET ,
17486 } ) ;
175- const chat = new Freestyler . ChatView ( props ) ;
87+ const chat = new AiAssistance . ChatView ( props ) ;
17688 renderElementIntoDOM ( chat ) ;
17789
17890 const optIn = chat . shadowRoot ?. querySelector ( '.disabled-view' ) ;
201113 const props = getProp ( {
202114 agentType : undefined ,
203115 } ) ;
204- const chat = new Freestyler . ChatView ( props ) ;
116+ const chat = new AiAssistance . ChatView ( props ) ;
205117 renderElementIntoDOM ( chat ) ;
206118 const featureCards = chat . shadowRoot ?. querySelectorAll ( '.feature-card' ) ;
207119 assert . isDefined ( featureCards ) ;
230142 const props = getProp ( {
231143 agentType : undefined ,
232144 } ) ;
233- const chat = new Freestyler . ChatView ( props ) ;
145+ const chat = new AiAssistance . ChatView ( props ) ;
234146 renderElementIntoDOM ( chat ) ;
235147 const featureCards = chat . shadowRoot ?. querySelectorAll ( '.feature-card' ) ;
236148 assert . isDefined ( featureCards ) ;
0 commit comments