@@ -5,6 +5,62 @@ import '../../milo.js';
55const { default : getPathDetails } = await import ( '../../../../blocks/shared/pathDetails.js' ) ;
66
77describe ( 'Path details' , ( ) => {
8+ describe ( 'Edit with trailing slash' , ( ) => {
9+ it ( 'Strips trailing slash from org-only path and treats as HTML' , ( ) => {
10+ const loc = { pathname : '/edit' , hash : '#/adobe/' } ;
11+ const details = getPathDetails ( loc ) ;
12+ expect ( details . fullpath ) . to . equal ( '/adobe.html' ) ;
13+ expect ( details . depth ) . to . equal ( 1 ) ;
14+ expect ( details . view ) . to . equal ( 'edit' ) ;
15+ } ) ;
16+
17+ it ( 'Strips trailing slash from org+repo path and treats as HTML' , ( ) => {
18+ const loc = { pathname : '/edit' , hash : '#/adobe/geometrixx/' } ;
19+ const details = getPathDetails ( loc ) ;
20+ expect ( details . fullpath ) . to . equal ( '/adobe/geometrixx.html' ) ;
21+ expect ( details . depth ) . to . equal ( 2 ) ;
22+ } ) ;
23+
24+ it ( 'Strips trailing slash from org+repo+path and treats as HTML' , ( ) => {
25+ const loc = { pathname : '/edit' , hash : '#/adobe/geometrixx/testing-123/' } ;
26+ const details = getPathDetails ( loc ) ;
27+ expect ( details . fullpath ) . to . equal ( '/adobe/geometrixx/testing-123.html' ) ;
28+ expect ( details . depth ) . to . equal ( 3 ) ;
29+ } ) ;
30+
31+ it ( 'Does not strip trailing slash in browse view at org+repo depth' , ( ) => {
32+ const loc = { pathname : '/' , hash : '#/adobe/geometrixx/' } ;
33+ const details = getPathDetails ( loc ) ;
34+ expect ( details . fullpath ) . to . equal ( '/adobe/geometrixx/' ) ;
35+ } ) ;
36+
37+ it ( 'Does not strip trailing slash in browse view at org+repo+path depth' , ( ) => {
38+ const loc = { pathname : '/' , hash : '#/adobe/geometrixx/testing-123/' } ;
39+ const details = getPathDetails ( loc ) ;
40+ expect ( details . fullpath ) . to . equal ( '/adobe/geometrixx/testing-123/' ) ;
41+ } ) ;
42+
43+ it ( 'Calls history.replaceState to remove trailing slash when no loc provided' , ( ) => {
44+ const originalUrl = window . location . href ;
45+ const replaceStateCalls = [ ] ;
46+ const originalReplaceState = history . replaceState ;
47+ history . replaceState = ( ...args ) => { replaceStateCalls . push ( args ) ; } ;
48+
49+ // Use pushState to set pathname to /edit with a unique trailing-slash hash
50+ history . pushState ( null , '' , '/edit#/adobe/geometrixx/replacestate-trail-test/' ) ;
51+
52+ try {
53+ getPathDetails ( ) ;
54+ expect ( replaceStateCalls . length ) . to . equal ( 1 ) ;
55+ expect ( replaceStateCalls [ 0 ] [ 2 ] ) . to . include ( '#/adobe/geometrixx/replacestate-trail-test' ) ;
56+ expect ( replaceStateCalls [ 0 ] [ 2 ] ) . to . not . include ( '#/adobe/geometrixx/replacestate-trail-test/' ) ;
57+ } finally {
58+ history . replaceState = originalReplaceState ;
59+ history . pushState ( null , '' , originalUrl ) ;
60+ }
61+ } ) ;
62+ } ) ;
63+
864 describe ( 'Org only' , ( ) => {
965 describe ( 'Config' , ( ) => {
1066 it ( 'Handles folder config (/)' , ( ) => {
0 commit comments