11import { describe , it , expect } from 'vitest'
22import { mount } from '@vue/test-utils'
33import RepositorySnippet from './RepositorySnippet.vue'
4+ import MdCopyableCode from '../md/MdCopyableCode.vue'
45import type { RepositorySnippetData } from './snippetTypes'
56
67const data : RepositorySnippetData = {
@@ -12,9 +13,11 @@ const data: RepositorySnippetData = {
1213
1314const render = ( lang : string ) => mount ( RepositorySnippet , { props : { configuration : { name : 'Maven' , lang } , data } } )
1415
16+ const codeText = ( wrapper : ReturnType < typeof render > ) => wrapper . find ( 'pre' ) . element . textContent
17+
1518describe ( 'RepositorySnippet Maven text' , ( ) => {
1619 it ( 'copies the snippet exactly as written: one element per line, no blank line between them' , ( ) => {
17- const text = render ( 'xml' ) . find ( 'pre' ) . element . textContent
20+ const text = codeText ( render ( 'xml' ) )
1821
1922 expect ( text ) . toBe (
2023 '<repository>\n' +
@@ -24,59 +27,33 @@ describe('RepositorySnippet Maven text', () => {
2427 '</repository>'
2528 )
2629 } )
27-
28- it ( 'keeps the url on one line, without break opportunities inside it' , ( ) => {
29- const pre = render ( 'xml' ) . find ( 'pre' ) . element
30-
31- expect ( pre . querySelectorAll ( 'wbr' ) , 'the url is not split into pieces' ) . toHaveLength ( 0 )
32- expect ( pre . textContent ) . toContain ( ' <url>http://localhost/releases</url>\n' )
33- } )
3430} )
3531
3632describe ( 'RepositorySnippet url' , ( ) => {
37- it . each ( [ 'xml' , 'groovy' , 'kotlin' , 'scala' ] ) ( 'marks the url of the %s snippet as its own element, never broken ' , ( lang ) => {
38- const url = render ( lang ) . find ( 'pre' ) . element . querySelector ( '.snippet-url' ) !
33+ it . each ( [ 'xml' , 'groovy' , 'kotlin' , 'scala' ] ) ( 'keeps the url of the %s snippet whole on one line ' , ( lang ) => {
34+ const text = codeText ( render ( lang ) )
3935
40- expect ( url , 'the url is wrapped in its own element' ) . not . toBeNull ( )
41- expect ( url . textContent , 'the wrapped element holds the url and nothing else' ) . toBe ( 'http://localhost/releases' )
42- expect ( url . classList , 'the url is not allowed to break at any character' ) . not . toContain ( 'wrap-anywhere' )
43- expect ( url . classList , 'the url is not allowed to wrap' ) . not . toContain ( 'whitespace-normal' )
44- } )
45-
46- it ( 'wraps only the url, so the rest of the snippet keeps its line structure' , ( ) => {
47- const pre = render ( 'kotlin' ) . find ( 'pre' ) . element
48-
49- expect ( pre . querySelectorAll ( '.snippet-url' ) , 'exactly one wrapped part for one url' ) . toHaveLength ( 1 )
50- expect ( pre . textContent , 'the wrapper adds no character to the copied text' ) . toContain ( 'url = uri("http://localhost/releases")' )
36+ expect ( text , 'the url is in the text as written' ) . toContain ( 'http://localhost/releases' )
37+ expect ( text , 'no zero-width space is copied with the url' ) . not . toMatch ( / \u200b / )
5138 } )
5239
53- it ( 'adds no zero-width space and no line break to the copied text' , ( ) => {
54- const text = render ( 'xml' ) . find ( 'pre' ) . element . textContent
55-
56- expect ( text , 'no zero-width space is copied with the url' ) . not . toMatch ( / \u200b / )
57- expect ( text ) . toBe (
58- '<repository>\n' +
59- ' <id>releases-x</id>\n' +
60- ' <name>Ingot Repository</name>\n' +
61- ' <url>http://localhost/releases</url>\n' +
62- '</repository>'
63- )
40+ it ( 'writes the Gradle Kotlin url as one call on one line' , ( ) => {
41+ expect ( codeText ( render ( 'kotlin' ) ) ) . toContain ( 'url = uri("http://localhost/releases")' )
6442 } )
6543} )
6644
6745describe ( 'RepositorySnippet block' , ( ) => {
68- // A token is never broken across lines: the block keeps every line whole and the card scrolls sideways instead.
69- it . each ( [ 'xml' , 'groovy' , 'kotlin' , 'scala' ] ) ( 'keeps the %s block on whole lines, so long tokens scroll sideways' , ( lang ) => {
70- const pre = render ( lang ) . find ( 'pre' ) . element
46+ it . each ( [ 'xml' , 'groovy' , 'kotlin' , 'scala' ] ) ( 'draws the %s snippet as one copyable code block under the snippet anchor' , ( lang ) => {
47+ const wrapper = render ( lang )
7148
72- expect ( pre . classList , 'no token may break at any character ' ) . not . toContain ( 'wrap-anywhere ')
73- expect ( pre . classList , 'the block keeps its lines as they are ' ) . toContain ( 'whitespace-pre' )
49+ expect ( wrapper . attributes ( 'data-ingot-component' ) , 'the anchor stays on the root ' ) . toBe ( 'repository-snippet ')
50+ expect ( wrapper . findAllComponents ( MdCopyableCode ) , 'one copyable code block per snippet ' ) . toHaveLength ( 1 )
7451 } )
7552} )
7653
7754describe ( 'RepositorySnippet Gradle and SBT text' , ( ) => {
7855 it ( 'indents the Gradle Groovy block by four spaces and keeps its url whole' , ( ) => {
79- const text = render ( 'groovy' ) . find ( 'pre' ) . element . textContent
56+ const text = codeText ( render ( 'groovy' ) )
8057
8158 expect ( text ) . toBe (
8259 'maven {\n' +
@@ -87,7 +64,7 @@ describe('RepositorySnippet Gradle and SBT text', () => {
8764 } )
8865
8966 it ( 'writes the SBT resolver as one line, the way it is pasted into build.sbt' , ( ) => {
90- const text = render ( 'scala' ) . find ( 'pre' ) . element . textContent
67+ const text = codeText ( render ( 'scala' ) )
9168
9269 expect ( text ) . toBe ( 'resolvers += "releases-x" at "http://localhost/releases"' )
9370 } )
0 commit comments