NNBD preview: Nav tree hrefs should always use forward slashes

Change-Id: I64cfb42f8623649707b153fbefa3a6cccf343a5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134788
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Sam Rawlins 2020-02-07 00:21:34 +00:00 committed by commit-bot@chromium.org
parent d47391ec41
commit af7b5fa4c6
4 changed files with 12 additions and 18 deletions

View file

@ -69,15 +69,14 @@ class MigrationInfo {
for (UnitInfo unit in units) {
int count = unit.fixRegions.length;
links.add(UnitLink(
_pathTo(target: unit), path.split(computeName(unit)), count));
_pathTo(target: unit), pathContext.split(computeName(unit)), count));
}
return links;
}
/// The path to [target], relative to [from].
String _pathTo({@required UnitInfo target}) {
return target.path;
}
/// The path to [target], as an HTTP URI path, using forward slash separators.
String _pathTo({@required UnitInfo target}) =>
'/' + pathContext.split(target.path).skip(1).join('/');
}
/// A location from or to which a user might want to navigate.

View file

@ -47,7 +47,7 @@ class NavigationTreeRenderer {
{
'type': 'file',
'name': link.fileName,
'path': link.relativePath,
'path': pathContext.joinAll(link.pathParts),
'href': link.url,
'editCount': link.editCount,
},

View file

@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:path/path.dart' as path;
/// Information about a link to a compilation unit.
class UnitLink {
/// The relative URL of this compilation unit on the preview server.
@ -19,7 +17,5 @@ class UnitLink {
UnitLink(this.url, this.pathParts, this.editCount)
: depth = pathParts.length - 1;
String get relativePath => path.joinAll(pathParts);
String get fileName => pathParts.last;
}

View file

@ -134,16 +134,15 @@ class NavigationTreeRendererTest extends NnbdMigrationTestBase {
isJsonMap.containing({
'name': 'src',
'subtree': [
isJsonMap.containing(
{'href': convertPath('/project/lib/src/b.dart')})
isJsonMap.containing({'href': '/project/lib/src/b.dart'})
]
}),
isJsonMap.containing({'href': convertPath('/project/lib/a.dart')})
isJsonMap.containing({'href': '/project/lib/a.dart'})
]
}));
var toolNode = response[1];
expect(toolNode['href'], convertPath('/project/tool.dart'));
expect(toolNode['href'], '/project/tool.dart');
}
Future<void> test_containsMultipleLinks_multipleDepths() async {
@ -208,12 +207,12 @@ class NavigationTreeRendererTest extends NnbdMigrationTestBase {
isJsonMap.containing({
'name': 'a.dart',
'path': convertPath('lib/a.dart'),
'href': convertPath('/project/lib/a.dart')
'href': '/project/lib/a.dart'
}),
isJsonMap.containing({
'name': 'b.dart',
'path': convertPath('lib/b.dart'),
'href': convertPath('/project/lib/b.dart')
'href': '/project/lib/b.dart'
})
]
}));
@ -264,7 +263,7 @@ class NavigationTreeRendererTest extends NnbdMigrationTestBase {
isJsonMap.containing({
'name': 'a.dart',
'path': convertPath('lib/src/a.dart'),
'href': convertPath('/project/lib/src/a.dart')
'href': '/project/lib/src/a.dart'
})
]
})
@ -281,7 +280,7 @@ class NavigationTreeRendererTest extends NnbdMigrationTestBase {
var aNode = response[0];
expect(aNode['name'], 'a.dart');
expect(aNode['path'], 'a.dart');
expect(aNode['href'], convertPath('/project/a.dart'));
expect(aNode['href'], '/project/a.dart');
}
}