Skip to content

Commit 3863261

Browse files
committed
Test fixes
1 parent 27bf5e0 commit 3863261

4 files changed

Lines changed: 107 additions & 18 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>AngularTS</title>
6+
<link rel="shortcut icon" type="image/png" href="images/favicon.ico" />
7+
<script type="module" src="../index.js"></script>
8+
<script>
9+
document.addEventListener("DOMContentLoaded", () => {
10+
window.angular
11+
.module("router", [])
12+
.controller(
13+
"Demo",
14+
class {
15+
constructor($location, $scope) {
16+
window.$location = this.$location = $location;
17+
this.routes = {
18+
"/admin/users/hello": { templateUrl: "/mock/hello" },
19+
"/admin/users/hello2": { templateUrl: "/mock/hello2" },
20+
};
21+
22+
window.addEventListener("popstate", () => {
23+
debugger;
24+
$scope.$ctrl.selectedRoute =
25+
$scope.$ctrl.routes[$location.$$hash];
26+
});
27+
window.addEventListener("hashchange", () => {
28+
$scope.$ctrl.selectedRoute =
29+
$scope.$ctrl.routes[$location.$$hash];
30+
});
31+
}
32+
33+
go() {
34+
this.$location.search({ a: "b", c: true });
35+
}
36+
},
37+
)
38+
.config([
39+
"$stateProvider",
40+
"$locationProvider",
41+
($stateProvider, $locationProvider) => {
42+
$locationProvider.html5ModeConf = {
43+
enabled: false,
44+
requireBase: false,
45+
rewriteLinks: false,
46+
};
47+
$stateProvider
48+
.state({
49+
name: "home",
50+
url: "",
51+
template: `
52+
<h1>Home</h1>
53+
<a ng-sref="page1">Page 1</a>
54+
<a ng-sref="page2">Page 2</a>
55+
`,
56+
})
57+
.state({
58+
name: "page1",
59+
url: "/page1",
60+
template: "<h3>Its the NG-Router hello world app!</h3>",
61+
})
62+
.state({
63+
name: "page2",
64+
url: "/page2",
65+
template: "This is another template",
66+
});
67+
},
68+
]);
69+
});
70+
</script>
71+
</head>
72+
<body ng-app="router">
73+
<div ng-controller="Demo as $ctrl">
74+
<button ng-click="$ctrl.go()">Go 1</button>
75+
<div class="navbar-inner">
76+
<ul class="nav">
77+
<li><a href="#/admin/users/hello">Hello</a></li>
78+
<li><a href="#/admin/users/hello2">Hello 2</a></li>
79+
</ul>
80+
</div>
81+
{{$ctrl.selectedRoute.templateUrl}}
82+
<div ng-include="$ctrl.selectedRoute.templateUrl">
83+
<!-- Route-dependent content goes here -->
84+
</div>
85+
</div>
86+
87+
<ng-view></ng-view>
88+
</body>
89+
</html>

src/router/state/state.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ describe("$state", () => {
457457
}).forEach(([k, v]) => {
458458
expect($stateParams[k]).toEqual(v);
459459
});
460-
expect($location.getBrowserUrl()).toEqual(
460+
expect($location.getUrl()).toEqual(
461461
"/dynstate/p1/pd1?search=s1&searchDyn=sd1",
462462
);
463463
});
@@ -841,7 +841,7 @@ describe("$state", () => {
841841
await $state.go(".", { term: "goodbye" });
842842

843843
expect($stateParams.term).toEqual("goodbye");
844-
expect($location.getBrowserUrl()).toEqual("/search?term=goodbye");
844+
expect($location.getUrl()).toEqual("/search?term=goodbye");
845845
expect(entered).toBeFalsy();
846846
});
847847
});
@@ -976,7 +976,7 @@ describe("$state", () => {
976976

977977
it("updates the location #fragment", async () => {
978978
await $state.transitionTo("home.item", { id: "world", "#": "frag" });
979-
expect($location.getBrowserUrl()).toBe("/front/world#frag");
979+
expect($location.getUrl()).toBe("/front/world#frag");
980980
expect($location.getHash()).toBe("frag");
981981
});
982982

src/router/url/url-service.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ describe("UrlMatcher", () => {
610610
expect(m.exec("/foo/")).toEqual({ param1: undefined });
611611
expect(m.exec("/foo/bar")).toEqual({ param1: ["bar"] });
612612
$url.url("/foo/bar-baz");
613-
expect(m.exec($location.getBrowserUrl())).toEqual({
613+
expect(m.exec($location.getUrl())).toEqual({
614614
param1: ["bar", "baz"],
615615
});
616616

src/services/location/location.spec.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,9 +3012,9 @@ describe("$location", () => {
30123012
// $log.info("after", newUrl, oldUrl, $browser.url());
30133013
// });
30143014

3015-
// expect($location.getBrowserUrl()).toEqual("");
3015+
// expect($location.getUrl()).toEqual("");
30163016
// $location.setUrl("/somePath");
3017-
// expect($location.getBrowserUrl()).toEqual("/somePath");
3017+
// expect($location.getUrl()).toEqual("/somePath");
30183018
// expect($browser.url()).toEqual("http://server/");
30193019
// expect($log.info.logs).toEqual([]);
30203020

@@ -3032,7 +3032,7 @@ describe("$location", () => {
30323032
// "http://server/",
30333033
// "http://server/#!/somePath",
30343034
// ]);
3035-
// expect($location.getBrowserUrl()).toEqual("/somePath");
3035+
// expect($location.getUrl()).toEqual("/somePath");
30363036
// expect($browser.url()).toEqual("http://server/#!/somePath");
30373037
// }));
30383038

@@ -3043,7 +3043,7 @@ describe("$location", () => {
30433043
// $log,
30443044
// ) => {
30453045
// expect($browser.url()).toEqual("http://server/");
3046-
// expect($location.getBrowserUrl()).toEqual("");
3046+
// expect($location.getUrl()).toEqual("");
30473047

30483048
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
30493049
// $log.info("before", newUrl, oldUrl, $browser.url());
@@ -3053,9 +3053,9 @@ describe("$location", () => {
30533053
// throw new Error("location should have been canceled");
30543054
// });
30553055

3056-
// expect($location.getBrowserUrl()).toEqual("");
3056+
// expect($location.getUrl()).toEqual("");
30573057
// $location.setUrl("/somePath");
3058-
// expect($location.getBrowserUrl()).toEqual("/somePath");
3058+
// expect($location.getUrl()).toEqual("/somePath");
30593059
// expect($browser.url()).toEqual("http://server/");
30603060
// expect($log.info.logs).toEqual([]);
30613061

@@ -3068,7 +3068,7 @@ describe("$location", () => {
30683068
// "http://server/",
30693069
// ]);
30703070
// expect($log.info.logs[1]).toBeUndefined();
3071-
// expect($location.getBrowserUrl()).toEqual("");
3071+
// expect($location.getUrl()).toEqual("");
30723072
// expect($browser.url()).toEqual("http://server/");
30733073
// }));
30743074

@@ -3110,7 +3110,7 @@ describe("$location", () => {
31103110
// "http://server/#!/redirectPath",
31113111
// ]);
31123112

3113-
// expect($location.getBrowserUrl()).toEqual("/redirectPath");
3113+
// expect($location.getUrl()).toEqual("/redirectPath");
31143114
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
31153115
// }));
31163116

@@ -3153,7 +3153,7 @@ describe("$location", () => {
31533153
// "http://server/#!/redirectPath",
31543154
// ]);
31553155

3156-
// expect($location.getBrowserUrl()).toEqual("/redirectPath");
3156+
// expect($location.getUrl()).toEqual("/redirectPath");
31573157
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
31583158
// }));
31593159

@@ -3203,7 +3203,7 @@ describe("$location", () => {
32033203
// "http://server/#!/redirectPath2",
32043204
// ]);
32053205

3206-
// expect($location.getBrowserUrl()).toEqual("/redirectPath2");
3206+
// expect($location.getUrl()).toEqual("/redirectPath2");
32073207
// expect($browser.url()).toEqual("http://server/#!/redirectPath2");
32083208
// }));
32093209

@@ -3216,7 +3216,7 @@ describe("$location", () => {
32163216
// $rootScope.$apply(); // clear initial $locationChangeStart
32173217

32183218
// expect($browser.url()).toEqual("http://server/");
3219-
// expect($location.getBrowserUrl()).toEqual("");
3219+
// expect($location.getUrl()).toEqual("");
32203220

32213221
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
32223222
// $log.info("start", newUrl, oldUrl);
@@ -3250,7 +3250,7 @@ describe("$location", () => {
32503250
// $rootScope.$apply();
32513251

32523252
// expect($browser.url()).toEqual("http://server/#!/somepath");
3253-
// expect($location.getBrowserUrl()).toEqual("/somepath");
3253+
// expect($location.getUrl()).toEqual("/somepath");
32543254

32553255
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
32563256
// $log.info("start", newUrl, oldUrl);
@@ -3312,7 +3312,7 @@ describe("$location", () => {
33123312
// "http://server/#!/redirectPath",
33133313
// ]);
33143314

3315-
// expect($location.getBrowserUrl()).toEqual("/redirectPath");
3315+
// expect($location.getUrl()).toEqual("/redirectPath");
33163316
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
33173317
// }));
33183318

@@ -3355,7 +3355,7 @@ describe("$location", () => {
33553355
// "http://server/#!/redirectPath",
33563356
// ]);
33573357

3358-
// expect($location.getBrowserUrl()).toEqual("/redirectPath");
3358+
// expect($location.getUrl()).toEqual("/redirectPath");
33593359
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
33603360
// }));
33613361

0 commit comments

Comments
 (0)