33 * Copyright (C) 2020 by RStudio, PBC
44 *
55 */
6+ import { posix , win32 } from "path/mod.ts" ;
67import { unitTest } from "../test.ts" ;
78import { assertEquals , assertThrows } from "testing/asserts.ts" ;
89
@@ -2833,7 +2834,7 @@ const runUpdateLinks = () => {
28332834 check ( expected , changes , fileMetadataTable ) ;
28342835 } ) ;
28352836
2836- otest ( suiteLabel ( "one_update_link_nested_absolute" ) , async ( ) => {
2837+ test ( suiteLabel ( "one_update_link_nested_absolute" ) , async ( ) => {
28372838 const changes : ConfluenceSpaceChange [ ] = [ UPDATE_LINKS_ONE_NESTED_ABS ] ;
28382839 const rootURL = "fake-server/wiki/spaces/QUARTOCONF/pages" ;
28392840 const expectedUpdate : ContentUpdate = {
@@ -2960,7 +2961,7 @@ const runFindAttachments = () => {
29602961 const bodyValue : string =
29612962 '<ri:attachment ri:filename="elephant.png" ri:version-at-save="1" />' ;
29622963 const filePaths : string [ ] = [ "fake-path/elephant.png" ] ;
2963- const expected : string [ ] = [ "fake-path/ elephant.png" ] ;
2964+ const expected : string [ ] = [ "elephant.png" ] ;
29642965 check ( expected , bodyValue , filePaths ) ;
29652966 } ) ;
29662967
@@ -2973,7 +2974,55 @@ const runFindAttachments = () => {
29732974 const expected : string [ ] = [
29742975 "computations/r/computations-r_files/figure-publish/fig-airquality-1.png" ,
29752976 ] ;
2976- check ( expected , bodyValue , filePaths ) ;
2977+ check ( expected , bodyValue , filePaths , "computations/r/index.xml" ) ;
2978+ } ) ;
2979+
2980+ test ( suiteLabel ( "single_image_lookup_full_path_win" ) , async ( ) => {
2981+ const bodyValue : string =
2982+ '<ri:attachment ri:filename="computations-r_files/figure-publish/fig-airquality-1.png" ri:version-at-save="1" />' ;
2983+ const filePaths : string [ ] = [
2984+ "computations\\r\\computations-r_files\\figure-publish\\fig-airquality-1.png" ,
2985+ ] ;
2986+ const expected : string [ ] = [
2987+ "computations\\r\\computations-r_files\\figure-publish\\fig-airquality-1.png" ,
2988+ ] ;
2989+ check ( expected , bodyValue , filePaths , "computations\\r\\index.xml" ) ;
2990+ } ) ;
2991+
2992+ test ( suiteLabel ( "single_with_same_name_nested_win" ) , async ( ) => {
2993+ const filePaths : string [ ] = [
2994+ "folder\\images\\elephant.png" ,
2995+ "images\\elephant.png" ,
2996+ ] ;
2997+ const bodyValue : string =
2998+ '<ri:attachment ri:filename="images/elephant.png" />' ;
2999+ const expected : string [ ] = [ "images\\elephant.png" ] ;
3000+ const path = "index.xml" ;
3001+ check ( expected , bodyValue , filePaths , path ) ;
3002+ } ) ;
3003+
3004+ test ( suiteLabel ( "single_with_same_name_nested_win2" ) , async ( ) => {
3005+ const filePaths : string [ ] = [
3006+ "folder\\images\\elephant.png" ,
3007+ "images\\elephant.png" ,
3008+ ] ;
3009+ const bodyValue : string =
3010+ '<ri:attachment ri:filename="images/elephant.png" />' ;
3011+ const expected : string [ ] = [ "folder\\images\\elephant.png" ] ;
3012+ const path = "folder\\index.xml" ;
3013+ check ( expected , bodyValue , filePaths , path ) ;
3014+ } ) ;
3015+
3016+ test ( suiteLabel ( "single_with_same_name_nested" ) , async ( ) => {
3017+ const filePaths : string [ ] = [
3018+ "images/elephant.png" ,
3019+ "folder/images/elephant.png" ,
3020+ ] ;
3021+ const bodyValue : string =
3022+ '<ri:attachment ri:filename="images/elephant.png" />' ;
3023+ const expected : string [ ] = [ "images/elephant.png" ] ;
3024+ const path = "index.xml" ;
3025+ check ( expected , bodyValue , filePaths , path ) ;
29773026 } ) ;
29783027
29793028 test ( suiteLabel ( "single_image_lookup_relative_path" ) , async ( ) => {
@@ -2988,6 +3037,18 @@ const runFindAttachments = () => {
29883037 check ( expected , bodyValue , filePaths , path ) ;
29893038 } ) ;
29903039
3040+ test ( suiteLabel ( "single_image_lookup_relative_path_win" ) , async ( ) => {
3041+ const bodyValue : string =
3042+ '<ri:attachment ri:filename="elephant.png" ri:version-at-save="1" />' ;
3043+ const filePaths : string [ ] = [
3044+ "images\\elephant.png" ,
3045+ "parent\\inner-parent\\elephant.png" ,
3046+ ] ;
3047+ const path = "parent\\inner-parent\\hello-world3.xml" ;
3048+ const expected : string [ ] = [ "parent\\inner-parent\\elephant.png" ] ;
3049+ check ( expected , bodyValue , filePaths , path ) ;
3050+ } ) ;
3051+
29913052 test ( suiteLabel ( "single_image_lookup_dupe_name" ) , async ( ) => {
29923053 const bodyValue : string =
29933054 '<ri:attachment ri:filename="elephant.png" ri:version-at-save="1" />' ;
@@ -3070,13 +3131,26 @@ const runGetAttachmentsDirectory = () => {
30703131 check ( expected , baseDirectory , "" , "file-name.png" ) ;
30713132 } ) ;
30723133
3134+ test ( suiteLabel ( "empty_to_upload_windows" ) , async ( ) => {
3135+ const expected = "" ;
3136+ const baseDirectory = win32 . fromFileUrl ( "file:///Users/fake-base" ) ;
3137+ check ( expected , baseDirectory , "" , "file-name.png" ) ;
3138+ } ) ;
3139+
30733140 test ( suiteLabel ( "empty_fileName" ) , async ( ) => {
30743141 const expected = "" ;
30753142 const attachmentPath = "file1.png" ;
30763143 const baseDirectory = "/Users/fake-base" ;
30773144 check ( expected , baseDirectory , attachmentPath , "" ) ;
30783145 } ) ;
30793146
3147+ test ( suiteLabel ( "empty_fileName_windows" ) , async ( ) => {
3148+ const expected = "" ;
3149+ const attachmentPath = "file1.png" ;
3150+ const baseDirectory = win32 . fromFileUrl ( "file:///Users/fake-base" ) ;
3151+ check ( expected , baseDirectory , attachmentPath , "" ) ;
3152+ } ) ;
3153+
30803154 test ( suiteLabel ( "simple" ) , async ( ) => {
30813155 const expected = "/Users/fake-base" ;
30823156
@@ -3087,6 +3161,18 @@ const runGetAttachmentsDirectory = () => {
30873161 check ( expected , baseDirectory , attachmentPath , fileName ) ;
30883162 } ) ;
30893163
3164+ test ( suiteLabel ( "simple_windows" ) , async ( ) => {
3165+ const expected = String . raw `c:\Users\fake-base` ;
3166+ const baseDirectory = String . raw `c:\Users\fake-base` ;
3167+
3168+ console . log ( "baseDirectory" , baseDirectory ) ;
3169+
3170+ const attachmentPath = "file1.png" ;
3171+ const fileName = "fake-file.xml" ;
3172+
3173+ check ( expected , baseDirectory , attachmentPath , fileName ) ;
3174+ } ) ;
3175+
30903176 test ( suiteLabel ( "site_in_root" ) , async ( ) => {
30913177 const expected = "/Users/fake-base" ;
30923178
@@ -3132,7 +3218,7 @@ const runGetAttachmentsDirectory = () => {
31323218 check ( expected , baseDirectory , attachmentPath , fileName ) ;
31333219 } ) ;
31343220
3135- otest ( suiteLabel ( "site_nested_relative_dotslash" ) , async ( ) => {
3221+ test ( suiteLabel ( "site_nested_relative_dotslash" ) , async ( ) => {
31363222 const expected = "/Users/fake-base/fake-parent" ;
31373223
31383224 const baseDirectory = "/Users/fake-base/_site" ;
@@ -3251,5 +3337,39 @@ if (RUN_ALL_TESTS) {
32513337 runUpdateImagePathsForContentBody ( ) ;
32523338 runCapFirstLetter ( ) ;
32533339} else {
3254- runCapFirstLetter ( ) ;
3340+ runFindAttachments ( ) ;
32553341}
3342+
3343+ // WINDOWS
3344+ // publishFiles: {
3345+ // baseDir: "C:\\Users\\Megaport\\Documents\\dev\\quarto-confluence-test-main\\simple-site2\\_site",
3346+ // rootFile: "index.html",
3347+ // files: [
3348+ // "folder\\images\\elephant.png",
3349+ // "folder\\index.xml",
3350+ // "images\\elephant.png",
3351+ // "index.html",
3352+ // "index.xml",
3353+ // "search.json",
3354+ // "site_libs\\bootstrap\\bootstrap-icons.css",
3355+ // "site_libs\\bootstrap\\bootstrap-icons.woff",
3356+ // "site_libs\\bootstrap\\bootstrap.min.css",
3357+ // "site_libs\\bootstrap\\bootstrap.min.js",
3358+ // "site_libs\\clipboard\\clipboard.min.js",
3359+ // "site_libs\\quarto-html\\anchor.min.js",
3360+ // "site_libs\\quarto-html\\popper.min.js",
3361+ // "site_libs\\quarto-html\\quarto-syntax-highlighting.css",
3362+ // "site_libs\\quarto-html\\quarto.js",
3363+ // "site_libs\\quarto-html\\tippy.css",
3364+ // "site_libs\\quarto-html\\tippy.umd.min.js",
3365+ // "site_libs\\quarto-nav\\headroom.min.js",
3366+ // "site_libs\\quarto-nav\\quarto-nav.js",
3367+ // "site_libs\\quarto-search\\autocomplete.umd.js",
3368+ // "site_libs\\quarto-search\\fuse.min.js",
3369+ // "site_libs\\quarto-search\\quarto-search.js"
3370+ // ],
3371+ // metadataByInput: {
3372+ // "folder\\index.qmd": { title: "Page 2", author: undefined, date: undefined },
3373+ // "index.qmd": { title: "Page 1", author: undefined, date: undefined }
3374+ // }
3375+ // },
0 commit comments