@angular-wave/angular.ts 0.7.8 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/{loader.d.ts → angular.d.ts} +3 -3
- package/@types/core/di/ng-module.d.ts +61 -25
- package/@types/core/parse/parse.d.ts +6 -7
- package/@types/directive/bind/bind.d.ts +2 -1
- package/@types/index.d.ts +1 -1
- package/@types/interface.d.ts +4 -2
- package/@types/{public.d.ts → ng.d.ts} +2 -2
- package/@types/router/directives/state-directives.d.ts +2 -2
- package/@types/router/directives/view-directive.d.ts +1 -1
- package/@types/router/params/param-type.d.ts +0 -1
- package/@types/router/path/path-utils.d.ts +8 -11
- package/@types/router/{globals.d.ts → router.d.ts} +2 -2
- package/@types/router/state/interface.d.ts +1 -1
- package/@types/router/state/state-object.d.ts +1 -1
- package/@types/router/state/state-registry.d.ts +2 -2
- package/@types/router/state/state-service.d.ts +14 -16
- package/@types/router/state-filters.d.ts +24 -2
- package/@types/router/transition/transition-service.d.ts +3 -3
- package/@types/router/transition/transition.d.ts +16 -19
- package/@types/router/url/url-matcher.d.ts +3 -4
- package/@types/router/url/url-rule.d.ts +14 -4
- package/@types/router/url/url-rules.d.ts +26 -6
- package/@types/router/url/url-service.d.ts +28 -38
- package/@types/services/http/http.d.ts +48 -1
- package/@types/services/http-backend/http-backend.d.ts +48 -35
- package/@types/services/location/interface.d.ts +55 -0
- package/@types/services/location/location.d.ts +225 -252
- package/@types/shared/common.d.ts +0 -2
- package/@types/shared/hof.d.ts +0 -6
- package/@types/shared/interface.d.ts +0 -4
- package/@types/{router/common → shared}/queue.d.ts +2 -2
- package/@types/shared/url-utils/interface.d.ts +0 -1
- package/@types/shared/url-utils/url-utils.d.ts +0 -5
- package/@types/shared/utils.d.ts +29 -6
- package/CHANGELOG.md +0 -72
- package/CONTRIBUTING.md +0 -1
- package/DEVELOPERS.md +0 -1
- package/Makefile +6 -3
- package/TRIAGING.md +0 -1
- package/dist/angular-ts.esm.js +1048 -1150
- package/dist/angular-ts.umd.js +1048 -1150
- package/dist/angular-ts.umd.min.js +1 -1
- package/docs/assets/scss/index.scss +23 -0
- package/docs/content/_index.md +9 -8
- package/docs/content/docs/_index.md +1 -1
- package/docs/content/docs/directive/app.md +1 -1
- package/docs/content/docs/directive/bind.md +1 -1
- package/docs/content/docs/directive/blur.md +1 -1
- package/docs/content/docs/directive/channel.md +2 -2
- package/docs/content/docs/directive/class-even.md +1 -1
- package/docs/content/docs/directive/class-odd.md +1 -1
- package/docs/content/docs/directive/class.md +1 -1
- package/docs/content/docs/directive/click.md +1 -1
- package/docs/content/docs/directive/copy.md +1 -1
- package/docs/content/docs/directive/cut.md +1 -1
- package/docs/content/docs/directive/dblclick.md +1 -1
- package/docs/content/docs/directive/focus.md +1 -1
- package/docs/content/docs/directive/get.md +3 -3
- package/docs/content/docs/directive/keydown.md +1 -1
- package/docs/content/docs/directive/keyup.md +1 -1
- package/docs/content/docs/directive/load.md +1 -1
- package/docs/content/docs/directive/mousedown.md +1 -1
- package/docs/content/docs/directive/mouseenter.md +1 -1
- package/docs/content/docs/directive/mouseleave.md +1 -1
- package/docs/content/docs/directive/mousemove.md +1 -1
- package/docs/content/docs/directive/mouseout.md +1 -1
- package/docs/content/docs/directive/mouseover.md +1 -1
- package/docs/content/docs/directive/mouseup.md +1 -1
- package/docs/content/docs/directive/non-bindable.md +28 -0
- package/docs/content/docs/provider/locationProvider.md +26 -0
- package/docs/content/docs/provider/templateCacheProvider.md +2 -2
- package/docs/content/docs/service/location.md +57 -0
- package/docs/content/docs/service/url.md +5 -0
- package/docs/layouts/partials/hooks/head-end.html +1 -1
- package/docs/layouts/shortcodes/version.html +1 -0
- package/docs/static/examples/counter/counter-test.html +0 -4
- package/docs/static/examples/eventbus/eventbus-test.html +0 -4
- package/docs/static/examples/ng-non-bindable/ng-non-bindable-test.html +13 -0
- package/docs/static/examples/ng-non-bindable/ng-non-bindable.html +3 -0
- package/docs/static/examples/ng-non-bindable/ng-non-bindable.test.js +11 -0
- package/docs/static/typedoc/assets/hierarchy.js +1 -1
- package/docs/static/typedoc/assets/highlight.css +6 -6
- package/docs/static/typedoc/assets/navigation.js +1 -1
- package/docs/static/typedoc/assets/search.js +1 -1
- package/docs/static/typedoc/classes/Location.html +55 -0
- package/docs/static/typedoc/classes/LocationProvider.html +20 -0
- package/docs/static/typedoc/classes/NgModule.html +3 -3
- package/docs/static/typedoc/index.html +1 -1
- package/docs/static/typedoc/interfaces/DefaultPorts.html +5 -0
- package/docs/static/typedoc/interfaces/Html5Mode.html +23 -0
- package/docs/static/typedoc/interfaces/Provider.html +2 -1
- package/docs/static/typedoc/interfaces/UrlParts.html +9 -0
- package/docs/static/typedoc/types/AnnotatedFactory.html +1 -1
- package/docs/static/typedoc/types/Expression.html +1 -1
- package/docs/static/typedoc/types/Injectable.html +4 -1
- package/docs/static/typedoc/types/InjectableFactory.html +1 -4
- package/docs/static/typedoc/types/UrlChangeListener.html +5 -0
- package/docs/static/version.js +13 -0
- package/docs/test-results/.last-run.json +4 -0
- package/docs/test-results/static-examples-counter-counter-counter-example/error-context.md +50 -0
- package/package.json +2 -2
- package/src/{loader.js → angular.js} +11 -11
- package/src/angular.spec.js +189 -21
- package/src/animations/animate-css.js +17 -18
- package/src/animations/animate.spec.js +1 -1
- package/src/animations/shared.js +2 -3
- package/src/binding.spec.js +1 -1
- package/src/core/compile/compile.js +4 -7
- package/src/core/compile/compile.spec.js +1 -1
- package/src/core/controller/controller.spec.js +1 -1
- package/src/core/controller/controller.test.js +1 -0
- package/src/core/di/injector.js +7 -8
- package/src/core/di/injector.spec.js +2 -2
- package/src/core/di/injector.test.js +2 -2
- package/src/core/di/internal-injector.js +3 -6
- package/src/core/di/ng-module.js +26 -21
- package/src/core/filter/filter.js +1 -1
- package/src/core/filter/filter.spec.js +1 -1
- package/src/core/filter/filter.test.js +1 -0
- package/src/core/interpolate/interpolate.js +4 -6
- package/src/core/interpolate/interpolate.spec.js +1 -1
- package/src/core/interpolate/interpolate.test.js +1 -0
- package/src/core/parse/ast/ast.spec.js +1 -1
- package/src/core/parse/ast/ast.test.js +1 -1
- package/src/core/parse/lexer/lexer.spec.js +1 -1
- package/src/core/parse/parse.js +150 -146
- package/src/core/parse/parse.spec.js +46 -46
- package/src/core/prop.spec.js +1 -1
- package/src/core/root-element.spec.js +1 -1
- package/src/core/scope/scope.js +10 -11
- package/src/core/scope/scope.spec.js +3 -4
- package/src/directive/aria/aria.spec.js +1 -1
- package/src/directive/aria/aria.test.js +1 -0
- package/src/directive/attrs/attrs.spec.js +1 -1
- package/src/directive/attrs/attrs.test.js +1 -0
- package/src/directive/attrs/boolean.spec.js +1 -1
- package/src/directive/attrs/boolean.test.js +1 -0
- package/src/directive/attrs/element-style.spec.js +1 -1
- package/src/directive/attrs/element-style.test.js +1 -0
- package/src/directive/attrs/src.spec.js +1 -1
- package/src/directive/attrs/src.test.js +1 -0
- package/src/directive/bind/bind-html.spec.js +1 -1
- package/src/directive/bind/bind.js +1 -0
- package/src/directive/bind/bind.spec.js +1 -1
- package/src/directive/bind/bind.test.js +1 -0
- package/src/directive/channel/channel.spec.js +1 -1
- package/src/directive/channel/channel.test.js +1 -0
- package/src/directive/class/class.spec.js +1 -1
- package/src/directive/class/class.test.js +1 -0
- package/src/directive/cloak/cloak.spec.js +1 -1
- package/src/directive/cloak/cloak.test.js +1 -0
- package/src/directive/controller/controller.spec.js +1 -1
- package/src/directive/controller/controller.test.js +1 -0
- package/src/directive/events/click.spec.js +1 -1
- package/src/directive/events/event.spec.js +6 -6
- package/src/directive/events/events.test.js +1 -0
- package/src/directive/form/form.js +8 -5
- package/src/directive/form/form.spec.js +1 -1
- package/src/directive/form/form.test.js +1 -0
- package/src/directive/http/delete.spec.js +1 -1
- package/src/directive/http/form-test.html +18 -0
- package/src/directive/http/get.spec.js +1 -1
- package/src/directive/http/http.js +12 -3
- package/src/directive/http/post.spec.js +504 -9
- package/src/directive/http/put.spec.js +1 -1
- package/src/directive/if/if.spec.js +1 -1
- package/src/directive/include/include.spec.js +1 -1
- package/src/directive/init/init.spec.js +1 -1
- package/src/directive/init/init.test.js +1 -0
- package/src/directive/input/input.js +13 -15
- package/src/directive/input/input.spec.js +1 -2
- package/src/directive/input/input.test.js +1 -0
- package/src/directive/messages/messages.md +0 -4
- package/src/directive/messages/messages.spec.js +1 -1
- package/src/directive/messages/messages.test.js +1 -0
- package/src/directive/model/model.js +13 -13
- package/src/directive/model/model.spec.js +1 -1
- package/src/directive/model/model.test.js +1 -0
- package/src/directive/model-options/model-option.test.js +1 -0
- package/src/directive/model-options/model-options.js +1 -1
- package/src/directive/model-options/model-options.spec.js +1 -1
- package/src/directive/non-bindable/non-bindable.spec.js +1 -1
- package/src/directive/non-bindable/non-bindable.test.js +1 -0
- package/src/directive/observe/observe.spec.js +1 -1
- package/src/directive/observe/observe.test.js +1 -0
- package/src/directive/on/on.spec.js +1 -1
- package/src/directive/on/on.test.js +1 -0
- package/src/directive/options/options.spec.js +1 -1
- package/src/directive/options/options.test.js +1 -0
- package/src/directive/ref/href.spec.js +1 -1
- package/src/directive/ref/href.test.js +2 -0
- package/src/directive/ref/ref.spec.js +1 -1
- package/src/directive/repeat/repeat.js +1 -1
- package/src/directive/repeat/repeat.spec.js +2 -3
- package/src/directive/repeat/repeat.test.js +1 -0
- package/src/directive/script/script.spec.js +1 -1
- package/src/directive/script/script.test.js +1 -0
- package/src/directive/select/select.js +1 -1
- package/src/directive/select/select.spec.js +1 -1
- package/src/directive/select/select.test.js +1 -0
- package/src/directive/setter/setter.spec.js +1 -1
- package/src/directive/setter/setter.test.js +1 -0
- package/src/directive/show-hide/show-hide.spec.js +1 -1
- package/src/directive/show-hide/show-hide.test.js +1 -0
- package/src/directive/style/style.spec.js +1 -1
- package/src/directive/style/style.test.js +1 -0
- package/src/directive/switch/switch.spec.js +1 -1
- package/src/directive/switch/switch.test.js +1 -0
- package/src/directive/validators/validators.js +82 -84
- package/src/directive/validators/validators.spec.js +5 -4
- package/src/directive/validators/validators.test.js +1 -0
- package/src/filters/filter.spec.js +1 -1
- package/src/filters/filters.spec.js +1 -1
- package/src/filters/limit-to.js +2 -3
- package/src/filters/limit-to.spec.js +1 -1
- package/src/filters/order-by.spec.js +1 -1
- package/src/index.js +1 -1
- package/src/injection-tokens.js +7 -3
- package/src/interface.ts +4 -3
- package/src/loader.md +0 -155
- package/src/{public.js → ng.js} +11 -12
- package/src/{public.spec.js → ng.spec.js} +2 -2
- package/src/router/directives/state-directives.js +5 -5
- package/src/router/directives/state-directives.spec.js +8 -7
- package/src/router/directives/view-directive.js +7 -13
- package/src/router/directives/view-directive.spec.js +22 -23
- package/src/router/{common/common.html → glob/glob.html} +2 -3
- package/src/router/{common/common.test.js → glob/glob.test.js} +2 -1
- package/src/router/params/param-type.js +0 -1
- package/src/router/params/param.js +1 -1
- package/src/router/path/path-utils.js +5 -0
- package/src/router/router-test-hashbang.html +45 -0
- package/src/router/{globals.js → router.js} +2 -2
- package/src/router/services.spec.js +8 -9
- package/src/router/state/interface.ts +1 -1
- package/src/router/state/state-builder.js +3 -3
- package/src/router/state/state-builder.spec.js +1 -1
- package/src/router/state/state-object.js +1 -1
- package/src/router/state/state-registry.js +4 -4
- package/src/router/state/state-service.js +14 -14
- package/src/router/state/state.spec.js +23 -22
- package/src/router/state/state.test.js +1 -0
- package/src/router/state/views.js +1 -1
- package/src/router/state-filter.spec.js +1 -1
- package/src/router/state-filters.js +13 -9
- package/src/router/template-factory.js +5 -4
- package/src/router/template-factory.spec.js +7 -7
- package/src/router/transition/hook-registry.js +1 -1
- package/src/router/transition/transition-service.js +7 -6
- package/src/router/transition/transition.js +6 -6
- package/src/router/url/url-matcher.js +12 -14
- package/src/router/url/url-rule.js +8 -2
- package/src/router/url/url-rules.js +8 -5
- package/src/router/url/url-service.js +80 -76
- package/src/router/url/url-service.spec.js +61 -78
- package/src/router/url/url.test.js +1 -0
- package/src/router/view/view.js +4 -5
- package/src/router/view/view.spec.js +10 -12
- package/src/router/view/view.test.js +1 -0
- package/src/router/view-hook.spec.js +1 -1
- package/src/router/view-scroll.js +3 -1
- package/src/router/view-scroll.spec.js +12 -12
- package/src/services/anchor-scroll.html +2 -2
- package/src/services/anchor-scroll.js +5 -4
- package/src/services/http/http.js +9 -4
- package/src/services/http/http.spec.js +2 -7
- package/src/services/http/template-request.spec.js +1 -1
- package/src/services/http-backend/http-backend.js +51 -77
- package/src/services/http-backend/http-backend.spec.js +1 -2
- package/src/services/http-backend/http-backend.test.js +1 -0
- package/src/services/location/interface.ts +62 -0
- package/src/services/location/location.js +439 -519
- package/src/services/location/location.spec.js +915 -530
- package/src/services/location/location.test.js +2 -2
- package/src/services/log/log.spec.js +1 -1
- package/src/services/log/log.test.js +1 -0
- package/src/services/pubsub/pubsub.spec.js +1 -1
- package/src/services/sce/sce.js +5 -7
- package/src/services/sce/sce.md +2 -2
- package/src/services/sce/sce.spec.js +1 -1
- package/src/services/template-cache/template-cache.spec.js +1 -1
- package/src/services/template-cache/template-cache.test.js +1 -0
- package/src/shared/common.js +5 -10
- package/src/shared/common.spec.js +1 -1
- package/src/shared/hof.js +0 -14
- package/src/shared/interface.ts +0 -4
- package/src/{router/common → shared}/queue.js +7 -7
- package/src/shared/shared.html +1 -0
- package/src/shared/shared.test.js +1 -0
- package/src/shared/url-utils/interface.ts +0 -2
- package/src/shared/url-utils/url-utils.js +6 -30
- package/src/shared/url-utils/url-utils.spec.js +10 -9
- package/src/shared/utils.js +32 -9
- package/src/shared/utils.spec.js +35 -1
- package/src/src.html +1 -2
- package/typedoc.json +0 -1
- package/utils/express.js +27 -1
- package/utils/version.cjs +23 -0
- package/@types/router/state-provider.d.ts +0 -123
- package/src/directive/non-bindable/non-bindable.md +0 -17
- package/src/loader.spec.js +0 -169
- package/src/router/state-provider.js +0 -146
- package/src/services/location/location.md +0 -114
- package/src/shared/url-utils/url-utils.md +0 -46
- /package/@types/router/{common → glob}/glob.d.ts +0 -0
- /package/src/router/{common → glob}/glob.js +0 -0
- /package/src/router/{common → glob}/glob.spec.js +0 -0
- /package/src/{router/common → shared}/queue.spec.js +0 -0
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
decodePath,
|
|
3
|
+
encodePath,
|
|
4
|
+
normalizePath,
|
|
5
|
+
Location,
|
|
4
6
|
LocationProvider,
|
|
7
|
+
parseAppUrl,
|
|
8
|
+
stripBaseUrl,
|
|
9
|
+
stripHash,
|
|
10
|
+
stripFile,
|
|
11
|
+
serverBase,
|
|
12
|
+
urlsEqual,
|
|
5
13
|
} from "./location.js";
|
|
6
|
-
import { Angular } from "../../
|
|
14
|
+
import { Angular } from "../../angular.js";
|
|
7
15
|
import { createInjector } from "../../core/di/injector.js";
|
|
8
16
|
|
|
9
17
|
describe("$location", () => {
|
|
@@ -24,12 +32,14 @@ describe("$location", () => {
|
|
|
24
32
|
describe("defaults", () => {
|
|
25
33
|
it('should have hashPrefix of "!"', () => {
|
|
26
34
|
let provider = new LocationProvider();
|
|
27
|
-
expect(provider.
|
|
35
|
+
expect(provider.hashPrefixConf).toBe("!");
|
|
28
36
|
});
|
|
29
37
|
|
|
30
|
-
it("should
|
|
38
|
+
it("should default to html5 mode with no base and rewrite links", () => {
|
|
31
39
|
let provider = new LocationProvider();
|
|
32
|
-
expect(provider.
|
|
40
|
+
expect(provider.html5ModeConf.enabled).toBeTrue();
|
|
41
|
+
expect(provider.html5ModeConf.requireBase).toBeFalse();
|
|
42
|
+
expect(provider.html5ModeConf.rewriteLinks).toBeTrue();
|
|
33
43
|
});
|
|
34
44
|
});
|
|
35
45
|
|
|
@@ -61,35 +71,28 @@ describe("$location", () => {
|
|
|
61
71
|
|
|
62
72
|
it("should not include the drive name in path() on WIN", () => {
|
|
63
73
|
// See issue #4680 for details
|
|
64
|
-
const locationUrl = new
|
|
65
|
-
|
|
66
|
-
"file:///",
|
|
67
|
-
"#!",
|
|
68
|
-
);
|
|
69
|
-
locationUrl.$$parse("file:///base#!/foo?a=b&c#hash");
|
|
74
|
+
const locationUrl = new Location("file:///base", "file:///", false, "#!");
|
|
75
|
+
locationUrl.parse("file:///base#!/foo?a=b&c#hash");
|
|
70
76
|
|
|
71
|
-
expect(locationUrl.
|
|
77
|
+
expect(locationUrl.getPath()).toBe("/foo");
|
|
72
78
|
});
|
|
73
79
|
|
|
74
80
|
it("should include the drive name if it was provided in the input url", () => {
|
|
75
|
-
const locationUrl = new
|
|
76
|
-
|
|
77
|
-
"file:///",
|
|
78
|
-
"#!",
|
|
79
|
-
);
|
|
80
|
-
locationUrl.$$parse("file:///base#!/C:/foo?a=b&c#hash");
|
|
81
|
+
const locationUrl = new Location("file:///base", "file:///", false, "#!");
|
|
82
|
+
locationUrl.parse("file:///base#!/C:/foo?a=b&c#hash");
|
|
81
83
|
|
|
82
|
-
expect(locationUrl.
|
|
84
|
+
expect(locationUrl.getPath()).toBe("/C:/foo");
|
|
83
85
|
});
|
|
84
86
|
});
|
|
85
87
|
|
|
86
88
|
describe("NewUrl", () => {
|
|
87
89
|
function createLocationHtml5Url() {
|
|
88
|
-
const locationUrl = new
|
|
90
|
+
const locationUrl = new Location(
|
|
89
91
|
"http://www.domain.com:9877/",
|
|
90
92
|
"http://www.domain.com:9877/",
|
|
93
|
+
true,
|
|
91
94
|
);
|
|
92
|
-
locationUrl
|
|
95
|
+
locationUrl.parse(
|
|
93
96
|
"http://www.domain.com:9877/path/b?search=a&b=c&d#hash",
|
|
94
97
|
);
|
|
95
98
|
return locationUrl;
|
|
@@ -97,67 +100,64 @@ describe("$location", () => {
|
|
|
97
100
|
|
|
98
101
|
it("should provide common getters", () => {
|
|
99
102
|
const locationUrl = createLocationHtml5Url();
|
|
100
|
-
expect(locationUrl.absUrl
|
|
103
|
+
expect(locationUrl.absUrl).toBe(
|
|
101
104
|
"http://www.domain.com:9877/path/b?search=a&b=c&d#hash",
|
|
102
105
|
);
|
|
103
|
-
expect(locationUrl.
|
|
104
|
-
expect(locationUrl.
|
|
105
|
-
expect(locationUrl.
|
|
106
|
-
expect(locationUrl.
|
|
107
|
-
expect(locationUrl.search()).toEqual({ search: "a", b: "c", d: true });
|
|
108
|
-
expect(locationUrl.hash()).toBe("hash");
|
|
109
|
-
expect(locationUrl.url()).toBe("/path/b?search=a&b=c&d#hash");
|
|
106
|
+
expect(locationUrl.getPath()).toBe("/path/b");
|
|
107
|
+
expect(locationUrl.getSearch()).toEqual({ search: "a", b: "c", d: true });
|
|
108
|
+
expect(locationUrl.getHash()).toBe("hash");
|
|
109
|
+
expect(locationUrl.getUrl()).toBe("/path/b?search=a&b=c&d#hash");
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
it("path() should change path", () => {
|
|
113
113
|
const locationUrl = createLocationHtml5Url();
|
|
114
|
-
locationUrl.
|
|
115
|
-
expect(locationUrl.
|
|
116
|
-
expect(locationUrl.absUrl
|
|
114
|
+
locationUrl.setPath("/new/path");
|
|
115
|
+
expect(locationUrl.getPath()).toBe("/new/path");
|
|
116
|
+
expect(locationUrl.absUrl).toBe(
|
|
117
117
|
"http://www.domain.com:9877/new/path?search=a&b=c&d#hash",
|
|
118
118
|
);
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
it("path() should not break on numeric values", () => {
|
|
122
122
|
const locationUrl = createLocationHtml5Url();
|
|
123
|
-
locationUrl.
|
|
124
|
-
expect(locationUrl.
|
|
125
|
-
expect(locationUrl.absUrl
|
|
123
|
+
locationUrl.setPath(1);
|
|
124
|
+
expect(locationUrl.getPath()).toBe("/1");
|
|
125
|
+
expect(locationUrl.absUrl).toBe(
|
|
126
126
|
"http://www.domain.com:9877/1?search=a&b=c&d#hash",
|
|
127
127
|
);
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
it("path() should allow using 0 as path", () => {
|
|
131
131
|
const locationUrl = createLocationHtml5Url();
|
|
132
|
-
locationUrl.
|
|
133
|
-
expect(locationUrl.
|
|
134
|
-
expect(locationUrl.absUrl
|
|
132
|
+
locationUrl.setPath(0);
|
|
133
|
+
expect(locationUrl.getPath()).toBe("/0");
|
|
134
|
+
expect(locationUrl.absUrl).toBe(
|
|
135
135
|
"http://www.domain.com:9877/0?search=a&b=c&d#hash",
|
|
136
136
|
);
|
|
137
137
|
});
|
|
138
138
|
|
|
139
139
|
it("path() should set to empty path on null value", () => {
|
|
140
140
|
const locationUrl = createLocationHtml5Url();
|
|
141
|
-
locationUrl.
|
|
142
|
-
expect(locationUrl.
|
|
143
|
-
locationUrl.
|
|
144
|
-
expect(locationUrl.
|
|
141
|
+
locationUrl.setPath("/foo");
|
|
142
|
+
expect(locationUrl.getPath()).toBe("/foo");
|
|
143
|
+
locationUrl.setPath(null);
|
|
144
|
+
expect(locationUrl.getPath()).toBe("/");
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
it("search() should accept string", () => {
|
|
148
148
|
const locationUrl = createLocationHtml5Url();
|
|
149
|
-
locationUrl.
|
|
150
|
-
expect(locationUrl.
|
|
151
|
-
expect(locationUrl.absUrl
|
|
149
|
+
locationUrl.setSearch("x=y&c");
|
|
150
|
+
expect(locationUrl.getSearch()).toEqual({ x: "y", c: true });
|
|
151
|
+
expect(locationUrl.absUrl).toBe(
|
|
152
152
|
"http://www.domain.com:9877/path/b?x=y&c#hash",
|
|
153
153
|
);
|
|
154
154
|
});
|
|
155
155
|
|
|
156
156
|
it("search() should accept object", () => {
|
|
157
157
|
const locationUrl = createLocationHtml5Url();
|
|
158
|
-
locationUrl.
|
|
159
|
-
expect(locationUrl.
|
|
160
|
-
expect(locationUrl.absUrl
|
|
158
|
+
locationUrl.setSearch({ one: 1, two: true });
|
|
159
|
+
expect(locationUrl.getSearch()).toEqual({ one: 1, two: true });
|
|
160
|
+
expect(locationUrl.absUrl).toBe(
|
|
161
161
|
"http://www.domain.com:9877/path/b?one=1&two#hash",
|
|
162
162
|
);
|
|
163
163
|
});
|
|
@@ -165,270 +165,258 @@ describe("$location", () => {
|
|
|
165
165
|
it("search() should copy object", () => {
|
|
166
166
|
const locationUrl = createLocationHtml5Url();
|
|
167
167
|
const obj = { one: 1, two: true, three: null };
|
|
168
|
-
locationUrl.
|
|
168
|
+
locationUrl.setSearch(obj);
|
|
169
169
|
expect(obj).toEqual({ one: 1, two: true, three: null });
|
|
170
170
|
obj.one = "changed";
|
|
171
|
-
expect(locationUrl.
|
|
172
|
-
expect(locationUrl.absUrl
|
|
171
|
+
expect(locationUrl.getSearch()).toEqual({ one: 1, two: true });
|
|
172
|
+
expect(locationUrl.absUrl).toBe(
|
|
173
173
|
"http://www.domain.com:9877/path/b?one=1&two#hash",
|
|
174
174
|
);
|
|
175
175
|
});
|
|
176
176
|
|
|
177
177
|
it("search() should change single parameter", () => {
|
|
178
178
|
const locationUrl = createLocationHtml5Url();
|
|
179
|
-
locationUrl.
|
|
180
|
-
locationUrl.
|
|
179
|
+
locationUrl.setSearch({ id: "old", preserved: true });
|
|
180
|
+
locationUrl.setSearch("id", "new");
|
|
181
181
|
|
|
182
|
-
expect(locationUrl.
|
|
182
|
+
expect(locationUrl.getSearch()).toEqual({ id: "new", preserved: true });
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
it("search() should remove single parameter", () => {
|
|
186
186
|
const locationUrl = createLocationHtml5Url();
|
|
187
|
-
locationUrl.
|
|
188
|
-
locationUrl.
|
|
187
|
+
locationUrl.setSearch({ id: "old", preserved: true });
|
|
188
|
+
locationUrl.setSearch("id", null);
|
|
189
189
|
|
|
190
|
-
expect(locationUrl.
|
|
190
|
+
expect(locationUrl.getSearch()).toEqual({ preserved: true });
|
|
191
191
|
});
|
|
192
192
|
|
|
193
193
|
it("search() should remove multiple parameters", () => {
|
|
194
194
|
const locationUrl = createLocationHtml5Url();
|
|
195
|
-
locationUrl.
|
|
196
|
-
expect(locationUrl.
|
|
197
|
-
locationUrl.
|
|
198
|
-
expect(locationUrl.
|
|
199
|
-
expect(locationUrl.absUrl
|
|
200
|
-
"http://www.domain.com:9877/path/b#hash",
|
|
201
|
-
);
|
|
195
|
+
locationUrl.setSearch({ one: 1, two: true });
|
|
196
|
+
expect(locationUrl.getSearch()).toEqual({ one: 1, two: true });
|
|
197
|
+
locationUrl.setSearch({ one: null, two: null });
|
|
198
|
+
expect(locationUrl.getSearch()).toEqual({});
|
|
199
|
+
expect(locationUrl.absUrl).toBe("http://www.domain.com:9877/path/b#hash");
|
|
202
200
|
});
|
|
203
201
|
|
|
204
202
|
it("search() should accept numeric keys", () => {
|
|
205
203
|
const locationUrl = createLocationHtml5Url();
|
|
206
|
-
locationUrl.
|
|
207
|
-
expect(locationUrl.
|
|
208
|
-
expect(locationUrl.absUrl
|
|
204
|
+
locationUrl.setSearch({ 1: "one", 2: "two" });
|
|
205
|
+
expect(locationUrl.getSearch()).toEqual({ 1: "one", 2: "two" });
|
|
206
|
+
expect(locationUrl.absUrl).toBe(
|
|
209
207
|
"http://www.domain.com:9877/path/b?1=one&2=two#hash",
|
|
210
208
|
);
|
|
211
209
|
});
|
|
212
210
|
|
|
213
211
|
it("search() should handle multiple value", () => {
|
|
214
212
|
const locationUrl = createLocationHtml5Url();
|
|
215
|
-
locationUrl.
|
|
216
|
-
expect(locationUrl.
|
|
213
|
+
locationUrl.setSearch("a&b");
|
|
214
|
+
expect(locationUrl.getSearch()).toEqual({ a: true, b: true });
|
|
217
215
|
|
|
218
|
-
locationUrl.
|
|
216
|
+
locationUrl.setSearch("a", null);
|
|
219
217
|
|
|
220
|
-
expect(locationUrl.
|
|
218
|
+
expect(locationUrl.getSearch()).toEqual({ b: true });
|
|
221
219
|
|
|
222
|
-
locationUrl.
|
|
223
|
-
expect(locationUrl.
|
|
220
|
+
locationUrl.setSearch("b", undefined);
|
|
221
|
+
expect(locationUrl.getSearch()).toEqual({});
|
|
224
222
|
});
|
|
225
223
|
|
|
226
224
|
it("search() should handle single value", () => {
|
|
227
225
|
const locationUrl = createLocationHtml5Url();
|
|
228
|
-
locationUrl.
|
|
229
|
-
expect(locationUrl.
|
|
230
|
-
locationUrl.
|
|
231
|
-
expect(locationUrl.
|
|
226
|
+
locationUrl.setSearch("ignore");
|
|
227
|
+
expect(locationUrl.getSearch()).toEqual({ ignore: true });
|
|
228
|
+
locationUrl.setSearch(1);
|
|
229
|
+
expect(locationUrl.getSearch()).toEqual({ 1: true });
|
|
232
230
|
});
|
|
233
231
|
|
|
234
232
|
it("search() should throw error an incorrect argument", () => {
|
|
235
233
|
const locationUrl = createLocationHtml5Url();
|
|
236
234
|
expect(() => {
|
|
237
|
-
locationUrl.
|
|
235
|
+
locationUrl.setSearch(null);
|
|
238
236
|
}).toThrowError(/isrcharg/);
|
|
239
237
|
expect(() => {
|
|
240
|
-
locationUrl.
|
|
238
|
+
locationUrl.setSearch(undefined);
|
|
241
239
|
}).toThrowError(/isrcharg/);
|
|
242
240
|
});
|
|
243
241
|
|
|
244
242
|
it("hash() should change hash fragment", () => {
|
|
245
243
|
const locationUrl = createLocationHtml5Url();
|
|
246
|
-
locationUrl.
|
|
247
|
-
expect(locationUrl.
|
|
248
|
-
expect(locationUrl.absUrl
|
|
244
|
+
locationUrl.setHash("new-hash");
|
|
245
|
+
expect(locationUrl.getHash()).toBe("new-hash");
|
|
246
|
+
expect(locationUrl.absUrl).toBe(
|
|
249
247
|
"http://www.domain.com:9877/path/b?search=a&b=c&d#new-hash",
|
|
250
248
|
);
|
|
251
249
|
});
|
|
252
250
|
|
|
253
251
|
it("hash() should accept numeric parameter", () => {
|
|
254
252
|
const locationUrl = createLocationHtml5Url();
|
|
255
|
-
locationUrl.
|
|
256
|
-
expect(locationUrl.
|
|
257
|
-
expect(locationUrl.absUrl
|
|
253
|
+
locationUrl.setHash(5);
|
|
254
|
+
expect(locationUrl.getHash()).toBe("5");
|
|
255
|
+
expect(locationUrl.absUrl).toBe(
|
|
258
256
|
"http://www.domain.com:9877/path/b?search=a&b=c&d#5",
|
|
259
257
|
);
|
|
260
258
|
});
|
|
261
259
|
|
|
262
260
|
it("hash() should allow using 0", () => {
|
|
263
261
|
const locationUrl = createLocationHtml5Url();
|
|
264
|
-
locationUrl.
|
|
265
|
-
expect(locationUrl.
|
|
266
|
-
expect(locationUrl.absUrl
|
|
262
|
+
locationUrl.setHash(0);
|
|
263
|
+
expect(locationUrl.getHash()).toBe("0");
|
|
264
|
+
expect(locationUrl.absUrl).toBe(
|
|
267
265
|
"http://www.domain.com:9877/path/b?search=a&b=c&d#0",
|
|
268
266
|
);
|
|
269
267
|
});
|
|
270
268
|
|
|
271
269
|
it("hash() should accept null parameter", () => {
|
|
272
270
|
const locationUrl = createLocationHtml5Url();
|
|
273
|
-
locationUrl.
|
|
274
|
-
expect(locationUrl.
|
|
275
|
-
expect(locationUrl.absUrl
|
|
271
|
+
locationUrl.setHash(null);
|
|
272
|
+
expect(locationUrl.getHash()).toBe("");
|
|
273
|
+
expect(locationUrl.absUrl).toBe(
|
|
276
274
|
"http://www.domain.com:9877/path/b?search=a&b=c&d",
|
|
277
275
|
);
|
|
278
276
|
});
|
|
279
277
|
|
|
280
|
-
it("url
|
|
278
|
+
it("url getter/setter should change the path, search and hash", () => {
|
|
281
279
|
const locationUrl = createLocationHtml5Url();
|
|
282
|
-
locationUrl.
|
|
283
|
-
expect(locationUrl.
|
|
284
|
-
expect(locationUrl.absUrl
|
|
280
|
+
locationUrl.setUrl("/some/path?a=b&c=d#hhh");
|
|
281
|
+
expect(locationUrl.getUrl()).toBe("/some/path?a=b&c=d#hhh");
|
|
282
|
+
expect(locationUrl.absUrl).toBe(
|
|
285
283
|
"http://www.domain.com:9877/some/path?a=b&c=d#hhh",
|
|
286
284
|
);
|
|
287
|
-
expect(locationUrl.
|
|
288
|
-
expect(locationUrl.
|
|
289
|
-
expect(locationUrl.
|
|
285
|
+
expect(locationUrl.getPath()).toBe("/some/path");
|
|
286
|
+
expect(locationUrl.getSearch()).toEqual({ a: "b", c: "d" });
|
|
287
|
+
expect(locationUrl.getHash()).toBe("hhh");
|
|
290
288
|
});
|
|
291
289
|
|
|
292
|
-
it("url
|
|
290
|
+
it("url getter/setter should change only hash when no search and path specified", () => {
|
|
293
291
|
const locationUrl = createLocationHtml5Url();
|
|
294
|
-
locationUrl.
|
|
292
|
+
locationUrl.setUrl("#some-hash");
|
|
295
293
|
|
|
296
|
-
expect(locationUrl.
|
|
297
|
-
expect(locationUrl.
|
|
298
|
-
expect(locationUrl.absUrl
|
|
294
|
+
expect(locationUrl.getHash()).toBe("some-hash");
|
|
295
|
+
expect(locationUrl.getUrl()).toBe("/path/b?search=a&b=c&d#some-hash");
|
|
296
|
+
expect(locationUrl.absUrl).toBe(
|
|
299
297
|
"http://www.domain.com:9877/path/b?search=a&b=c&d#some-hash",
|
|
300
298
|
);
|
|
301
299
|
});
|
|
302
300
|
|
|
303
|
-
it("
|
|
301
|
+
it("setUrl() should change only search and hash when no path specified", () => {
|
|
304
302
|
const locationUrl = createLocationHtml5Url();
|
|
305
|
-
locationUrl.
|
|
303
|
+
locationUrl.setUrl("?a=b");
|
|
306
304
|
|
|
307
|
-
expect(locationUrl.
|
|
308
|
-
expect(locationUrl.
|
|
309
|
-
expect(locationUrl.
|
|
305
|
+
expect(locationUrl.getSearch()).toEqual({ a: "b" });
|
|
306
|
+
expect(locationUrl.getHash()).toBe("");
|
|
307
|
+
expect(locationUrl.getPath()).toBe("/path/b");
|
|
310
308
|
});
|
|
311
309
|
|
|
312
|
-
it("
|
|
310
|
+
it("setUrl() should reset search and hash when only path specified", () => {
|
|
313
311
|
const locationUrl = createLocationHtml5Url();
|
|
314
|
-
locationUrl.
|
|
312
|
+
locationUrl.setUrl("/new/path");
|
|
315
313
|
|
|
316
|
-
expect(locationUrl.
|
|
317
|
-
expect(locationUrl.
|
|
318
|
-
expect(locationUrl.
|
|
314
|
+
expect(locationUrl.getPath()).toBe("/new/path");
|
|
315
|
+
expect(locationUrl.getSearch()).toEqual({});
|
|
316
|
+
expect(locationUrl.getHash()).toBe("");
|
|
319
317
|
});
|
|
320
318
|
|
|
321
|
-
it("
|
|
319
|
+
it("setUrl() should change path when empty string specified", () => {
|
|
322
320
|
const locationUrl = createLocationHtml5Url();
|
|
323
|
-
locationUrl.
|
|
321
|
+
locationUrl.setUrl("");
|
|
324
322
|
|
|
325
|
-
expect(locationUrl.
|
|
326
|
-
expect(locationUrl.
|
|
327
|
-
expect(locationUrl.
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
it("replace should set $$replace flag and return itself", () => {
|
|
331
|
-
const locationUrl = createLocationHtml5Url();
|
|
332
|
-
expect(locationUrl.$$replace).toBe(false);
|
|
333
|
-
|
|
334
|
-
locationUrl.replace();
|
|
335
|
-
expect(locationUrl.$$replace).toBe(true);
|
|
336
|
-
expect(locationUrl.replace()).toBe(locationUrl);
|
|
323
|
+
expect(locationUrl.getPath()).toBe("/");
|
|
324
|
+
expect(locationUrl.getSearch()).toEqual({});
|
|
325
|
+
expect(locationUrl.getHash()).toBe("");
|
|
337
326
|
});
|
|
338
327
|
|
|
339
328
|
it("should parse new url", () => {
|
|
340
|
-
let locationUrl = new
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
);
|
|
344
|
-
locationUrl.$$parse("http://host.com/base");
|
|
345
|
-
expect(locationUrl.path()).toBe("/base");
|
|
329
|
+
let locationUrl = new Location("http://host.com/", "http://host.com/");
|
|
330
|
+
locationUrl.parse("http://host.com/base");
|
|
331
|
+
expect(locationUrl.getPath()).toBe("/base");
|
|
346
332
|
|
|
347
|
-
locationUrl = new
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
);
|
|
351
|
-
locationUrl.$$parse("http://host.com/base#");
|
|
352
|
-
expect(locationUrl.path()).toBe("/base");
|
|
333
|
+
locationUrl = new Location("http://host.com/", "http://host.com/", true);
|
|
334
|
+
locationUrl.parse("http://host.com/base#");
|
|
335
|
+
expect(locationUrl.getPath()).toBe("/base");
|
|
353
336
|
});
|
|
354
337
|
|
|
355
338
|
it("should prefix path with forward-slash", () => {
|
|
356
|
-
const locationUrl = new
|
|
339
|
+
const locationUrl = new Location(
|
|
357
340
|
"http://server/",
|
|
358
341
|
"http://server/",
|
|
342
|
+
true,
|
|
359
343
|
);
|
|
360
|
-
locationUrl.
|
|
344
|
+
locationUrl.setPath("b");
|
|
361
345
|
|
|
362
|
-
expect(locationUrl.
|
|
363
|
-
expect(locationUrl.absUrl
|
|
346
|
+
expect(locationUrl.getPath()).toBe("/b");
|
|
347
|
+
expect(locationUrl.absUrl).toBe("http://server/b");
|
|
364
348
|
});
|
|
365
349
|
|
|
366
350
|
it("should set path to forward-slash when empty", () => {
|
|
367
|
-
const locationUrl = new
|
|
351
|
+
const locationUrl = new Location(
|
|
368
352
|
"http://server/",
|
|
369
353
|
"http://server/",
|
|
354
|
+
true,
|
|
370
355
|
);
|
|
371
|
-
locationUrl
|
|
372
|
-
expect(locationUrl.
|
|
373
|
-
expect(locationUrl.absUrl
|
|
356
|
+
locationUrl.parse("http://server/");
|
|
357
|
+
expect(locationUrl.getPath()).toBe("/");
|
|
358
|
+
expect(locationUrl.absUrl).toBe("http://server/");
|
|
374
359
|
});
|
|
375
360
|
|
|
376
361
|
it("setters should return Url object to allow chaining", () => {
|
|
377
362
|
const locationUrl = createLocationHtml5Url();
|
|
378
|
-
expect(locationUrl.
|
|
379
|
-
expect(locationUrl.
|
|
380
|
-
expect(locationUrl.
|
|
381
|
-
expect(locationUrl.
|
|
363
|
+
expect(locationUrl.setPath("/any")).toBe(locationUrl);
|
|
364
|
+
expect(locationUrl.setSearch("")).toBe(locationUrl);
|
|
365
|
+
expect(locationUrl.setHash("aaa")).toBe(locationUrl);
|
|
366
|
+
expect(locationUrl.setUrl("/some")).toBe(locationUrl);
|
|
382
367
|
});
|
|
383
368
|
|
|
384
369
|
it("should not preserve old properties when parsing new url", () => {
|
|
385
370
|
const locationUrl = createLocationHtml5Url();
|
|
386
|
-
locationUrl
|
|
371
|
+
locationUrl.parse("http://www.domain.com:9877/a");
|
|
387
372
|
|
|
388
|
-
expect(locationUrl.
|
|
389
|
-
expect(locationUrl.
|
|
390
|
-
expect(locationUrl.
|
|
391
|
-
expect(locationUrl.absUrl
|
|
373
|
+
expect(locationUrl.getPath()).toBe("/a");
|
|
374
|
+
expect(locationUrl.getSearch()).toEqual({});
|
|
375
|
+
expect(locationUrl.getHash()).toBe("");
|
|
376
|
+
expect(locationUrl.absUrl).toBe("http://www.domain.com:9877/a");
|
|
392
377
|
});
|
|
393
378
|
|
|
394
379
|
// it("should not rewrite when hashbang url is not given", () => {
|
|
395
380
|
// initService({ html5Mode: true, hashPrefix: "!", supportHistory: true });
|
|
396
381
|
// initBrowser({ url: "http://domain.com/base/a/b", basePath: "/base" });
|
|
397
|
-
// expect($browser.
|
|
382
|
+
// expect($browser.getUrl()).toBe("http://domain.com/base/a/b");
|
|
398
383
|
// });
|
|
399
384
|
|
|
400
385
|
it("should prepend path with basePath", () => {
|
|
401
|
-
const locationUrl = new
|
|
386
|
+
const locationUrl = new Location(
|
|
402
387
|
"http://server/base/",
|
|
403
388
|
"http://server/base/",
|
|
389
|
+
true,
|
|
404
390
|
);
|
|
405
|
-
locationUrl
|
|
406
|
-
expect(locationUrl.
|
|
407
|
-
expect(locationUrl.
|
|
391
|
+
locationUrl.parse("http://server/base/abc?a");
|
|
392
|
+
expect(locationUrl.getPath()).toBe("/abc");
|
|
393
|
+
expect(locationUrl.getSearch()).toEqual({ a: true });
|
|
408
394
|
|
|
409
|
-
locationUrl.
|
|
410
|
-
expect(locationUrl.absUrl
|
|
395
|
+
locationUrl.setPath("/new/path");
|
|
396
|
+
expect(locationUrl.absUrl).toBe("http://server/base/new/path?a");
|
|
411
397
|
});
|
|
412
398
|
|
|
413
399
|
it("should throw error when invalid server url given", () => {
|
|
414
|
-
const locationUrl = new
|
|
400
|
+
const locationUrl = new Location(
|
|
415
401
|
"http://server.org/base/abc",
|
|
416
402
|
"http://server.org/base/",
|
|
403
|
+
true,
|
|
417
404
|
);
|
|
418
405
|
|
|
419
406
|
expect(() => {
|
|
420
|
-
locationUrl
|
|
407
|
+
locationUrl.parse("http://other.server.org/path#/path");
|
|
421
408
|
}).toThrowError(/ipthprfx/);
|
|
422
409
|
});
|
|
423
410
|
|
|
424
411
|
it("should throw error when invalid base url given", () => {
|
|
425
|
-
const locationUrl = new
|
|
412
|
+
const locationUrl = new Location(
|
|
426
413
|
"http://server.org/base/abc",
|
|
427
414
|
"http://server.org/base/",
|
|
415
|
+
true,
|
|
428
416
|
);
|
|
429
417
|
|
|
430
418
|
expect(() => {
|
|
431
|
-
locationUrl
|
|
419
|
+
locationUrl.parse("http://server.org/path#/path");
|
|
432
420
|
}).toThrowError(/ipthprfx/);
|
|
433
421
|
});
|
|
434
422
|
|
|
@@ -437,343 +425,806 @@ describe("$location", () => {
|
|
|
437
425
|
const locationUrl = createLocationHtml5Url();
|
|
438
426
|
expect(locationUrl.$$state).toEqual(undefined);
|
|
439
427
|
|
|
440
|
-
const returned = locationUrl.
|
|
428
|
+
const returned = locationUrl.setState({ a: 2 });
|
|
441
429
|
expect(locationUrl.$$state).toEqual({ a: 2 });
|
|
442
430
|
expect(returned).toBe(locationUrl);
|
|
443
431
|
});
|
|
444
432
|
|
|
445
433
|
it("should set state", () => {
|
|
446
434
|
const locationUrl = createLocationHtml5Url();
|
|
447
|
-
locationUrl.
|
|
448
|
-
expect(locationUrl.
|
|
435
|
+
locationUrl.setState({ a: 2 });
|
|
436
|
+
expect(locationUrl.getState()).toEqual({ a: 2 });
|
|
449
437
|
});
|
|
450
438
|
|
|
451
439
|
it("should allow to set both URL and state", () => {
|
|
452
440
|
const locationUrl = createLocationHtml5Url();
|
|
453
|
-
locationUrl.
|
|
454
|
-
expect(locationUrl.
|
|
455
|
-
expect(locationUrl.
|
|
441
|
+
locationUrl.setUrl("/foo").setState({ a: 2 });
|
|
442
|
+
expect(locationUrl.getUrl()).toEqual("/foo");
|
|
443
|
+
expect(locationUrl.getState()).toEqual({ a: 2 });
|
|
456
444
|
});
|
|
457
445
|
|
|
458
446
|
it("should allow to mix state and various URL functions", () => {
|
|
459
447
|
const locationUrl = createLocationHtml5Url();
|
|
460
448
|
locationUrl
|
|
461
|
-
.
|
|
462
|
-
.
|
|
463
|
-
.
|
|
464
|
-
.
|
|
465
|
-
|
|
466
|
-
expect(locationUrl.
|
|
467
|
-
expect(locationUrl.
|
|
468
|
-
expect(locationUrl.
|
|
469
|
-
|
|
449
|
+
.setPath("/foo")
|
|
450
|
+
.setHash("abcd")
|
|
451
|
+
.setState({ a: 2 })
|
|
452
|
+
.setSearch("bar", "baz");
|
|
453
|
+
|
|
454
|
+
expect(locationUrl.getPath()).toEqual("/foo");
|
|
455
|
+
expect(locationUrl.getState()).toEqual({ a: 2 });
|
|
456
|
+
expect(locationUrl.getSearch() && locationUrl.getSearch().bar).toBe(
|
|
457
|
+
"baz",
|
|
458
|
+
);
|
|
459
|
+
expect(locationUrl.getHash()).toEqual("abcd");
|
|
470
460
|
});
|
|
471
461
|
});
|
|
472
462
|
|
|
473
463
|
describe("encoding", () => {
|
|
474
464
|
it("should encode special characters", () => {
|
|
475
465
|
const locationUrl = createLocationHtml5Url();
|
|
476
|
-
locationUrl.
|
|
477
|
-
locationUrl.
|
|
478
|
-
locationUrl.
|
|
479
|
-
|
|
480
|
-
expect(locationUrl.
|
|
481
|
-
expect(locationUrl.
|
|
482
|
-
expect(locationUrl.
|
|
483
|
-
expect(locationUrl.absUrl
|
|
466
|
+
locationUrl.setPath("/a <>#");
|
|
467
|
+
locationUrl.setSearch({ "i j": "<>#" });
|
|
468
|
+
locationUrl.setHash("<>#");
|
|
469
|
+
|
|
470
|
+
expect(locationUrl.getPath()).toBe("/a <>#");
|
|
471
|
+
expect(locationUrl.getSearch()).toEqual({ "i j": "<>#" });
|
|
472
|
+
expect(locationUrl.getHash()).toBe("<>#");
|
|
473
|
+
expect(locationUrl.absUrl).toBe(
|
|
484
474
|
"http://www.domain.com:9877/a%20%3C%3E%23?i%20j=%3C%3E%23#%3C%3E%23",
|
|
485
475
|
);
|
|
486
476
|
});
|
|
487
477
|
|
|
488
478
|
it("should not encode !$:@", () => {
|
|
489
479
|
const locationUrl = createLocationHtml5Url();
|
|
490
|
-
locationUrl.
|
|
491
|
-
locationUrl.
|
|
492
|
-
locationUrl.
|
|
480
|
+
locationUrl.setPath("/!$:@");
|
|
481
|
+
locationUrl.setSearch("");
|
|
482
|
+
locationUrl.setHash("!$:@");
|
|
493
483
|
|
|
494
|
-
expect(locationUrl.absUrl
|
|
495
|
-
"http://www.domain.com:9877/!$:@#!$:@",
|
|
496
|
-
);
|
|
484
|
+
expect(locationUrl.absUrl).toBe("http://www.domain.com:9877/!$:@#!$:@");
|
|
497
485
|
});
|
|
498
486
|
|
|
499
487
|
it("should decode special characters", () => {
|
|
500
|
-
const locationUrl = new
|
|
488
|
+
const locationUrl = new Location(
|
|
501
489
|
"http://host.com/",
|
|
502
490
|
"http://host.com/",
|
|
491
|
+
true,
|
|
503
492
|
);
|
|
504
|
-
locationUrl
|
|
493
|
+
locationUrl.parse(
|
|
505
494
|
"http://host.com/a%20%3C%3E%23?i%20j=%3C%3E%23#x%20%3C%3E%23",
|
|
506
495
|
);
|
|
507
|
-
expect(locationUrl.
|
|
508
|
-
expect(locationUrl.
|
|
509
|
-
expect(locationUrl.
|
|
496
|
+
expect(locationUrl.getPath()).toBe("/a <>#");
|
|
497
|
+
expect(locationUrl.getSearch()).toEqual({ "i j": "<>#" });
|
|
498
|
+
expect(locationUrl.getHash()).toBe("x <>#");
|
|
510
499
|
});
|
|
511
500
|
|
|
512
501
|
it("should not decode encoded forward slashes in the path", () => {
|
|
513
|
-
const locationUrl = new
|
|
502
|
+
const locationUrl = new Location(
|
|
514
503
|
"http://host.com/base/",
|
|
515
504
|
"http://host.com/base/",
|
|
505
|
+
true,
|
|
516
506
|
);
|
|
517
|
-
locationUrl
|
|
518
|
-
expect(locationUrl.
|
|
519
|
-
expect(locationUrl.
|
|
520
|
-
expect(locationUrl.
|
|
521
|
-
expect(locationUrl.
|
|
522
|
-
expect(locationUrl.absUrl
|
|
507
|
+
locationUrl.parse("http://host.com/base/a/ng2;path=%2Fsome%2Fpath");
|
|
508
|
+
expect(locationUrl.getPath()).toBe("/a/ng2;path=%2Fsome%2Fpath");
|
|
509
|
+
expect(locationUrl.getSearch()).toEqual({});
|
|
510
|
+
expect(locationUrl.getHash()).toBe("");
|
|
511
|
+
expect(locationUrl.getUrl()).toBe("/a/ng2;path=%2Fsome%2Fpath");
|
|
512
|
+
expect(locationUrl.absUrl).toBe(
|
|
523
513
|
"http://host.com/base/a/ng2;path=%2Fsome%2Fpath",
|
|
524
514
|
);
|
|
525
515
|
});
|
|
526
516
|
|
|
527
517
|
it("should decode pluses as spaces in urls", () => {
|
|
528
|
-
const locationUrl = new
|
|
518
|
+
const locationUrl = new Location(
|
|
529
519
|
"http://host.com/",
|
|
530
520
|
"http://host.com/",
|
|
521
|
+
true,
|
|
531
522
|
);
|
|
532
|
-
locationUrl
|
|
533
|
-
expect(locationUrl.
|
|
523
|
+
locationUrl.parse("http://host.com/?a+b=c+d");
|
|
524
|
+
expect(locationUrl.getSearch()).toEqual({ "a b": "c d" });
|
|
534
525
|
});
|
|
535
526
|
|
|
536
527
|
it("should retain pluses when setting search queries", () => {
|
|
537
528
|
const locationUrl = createLocationHtml5Url();
|
|
538
|
-
locationUrl.
|
|
539
|
-
expect(locationUrl.
|
|
529
|
+
locationUrl.setSearch({ "a+b": "c+d" });
|
|
530
|
+
expect(locationUrl.getSearch()).toEqual({ "a+b": "c+d" });
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
fit("should not drop encodings on already enconded params", () => {
|
|
534
|
+
const locationUrl = createLocationHtml5Url();
|
|
535
|
+
locationUrl.setUrl("/path/foo%2Fbar/baz%2Fqux");
|
|
536
|
+
expect(locationUrl.getPath()).toEqual("/path/foo%2Fbar/baz%2Fqux");
|
|
540
537
|
});
|
|
541
538
|
});
|
|
542
539
|
});
|
|
543
540
|
|
|
544
541
|
describe("HashbangUrl", () => {
|
|
545
542
|
function createHashbangUrl() {
|
|
546
|
-
const locationUrl = new
|
|
543
|
+
const locationUrl = new Location(
|
|
547
544
|
"http://www.server.org:1234/base",
|
|
548
545
|
"http://www.server.org:1234/",
|
|
546
|
+
false,
|
|
549
547
|
"#!",
|
|
550
548
|
);
|
|
551
|
-
locationUrl
|
|
549
|
+
locationUrl.parse("http://www.server.org:1234/base#!/path?a=b&c#hash");
|
|
552
550
|
return locationUrl;
|
|
553
551
|
}
|
|
554
552
|
|
|
555
553
|
it("should parse hashbang url into path and search", () => {
|
|
556
554
|
const locationUrl = createHashbangUrl();
|
|
557
|
-
expect(locationUrl.
|
|
558
|
-
expect(locationUrl.
|
|
559
|
-
expect(locationUrl.
|
|
560
|
-
expect(locationUrl.path()).toBe("/path");
|
|
561
|
-
expect(locationUrl.search()).toEqual({ a: "b", c: true });
|
|
562
|
-
expect(locationUrl.hash()).toBe("hash");
|
|
555
|
+
expect(locationUrl.getPath()).toBe("/path");
|
|
556
|
+
expect(locationUrl.getSearch()).toEqual({ a: "b", c: true });
|
|
557
|
+
expect(locationUrl.getHash()).toBe("hash");
|
|
563
558
|
});
|
|
564
559
|
|
|
565
|
-
it("absUrl
|
|
560
|
+
it("absUrl should return hashbang url", () => {
|
|
566
561
|
const locationUrl = createHashbangUrl();
|
|
567
|
-
expect(locationUrl.absUrl
|
|
562
|
+
expect(locationUrl.absUrl).toBe(
|
|
568
563
|
"http://www.server.org:1234/base#!/path?a=b&c#hash",
|
|
569
564
|
);
|
|
570
565
|
|
|
571
|
-
locationUrl.
|
|
572
|
-
locationUrl.
|
|
573
|
-
locationUrl.
|
|
574
|
-
expect(locationUrl.absUrl
|
|
566
|
+
locationUrl.setPath("/new/path");
|
|
567
|
+
locationUrl.setSearch({ one: 1 });
|
|
568
|
+
locationUrl.setHash("hhh");
|
|
569
|
+
expect(locationUrl.absUrl).toBe(
|
|
575
570
|
"http://www.server.org:1234/base#!/new/path?one=1#hhh",
|
|
576
571
|
);
|
|
577
572
|
});
|
|
578
573
|
|
|
579
574
|
it("should preserve query params in base", () => {
|
|
580
|
-
const locationUrl = new
|
|
575
|
+
const locationUrl = new Location(
|
|
581
576
|
"http://www.server.org:1234/base?base=param",
|
|
582
577
|
"http://www.server.org:1234/",
|
|
578
|
+
false,
|
|
583
579
|
"#",
|
|
584
580
|
);
|
|
585
|
-
locationUrl
|
|
581
|
+
locationUrl.parse(
|
|
586
582
|
"http://www.server.org:1234/base?base=param#/path?a=b&c#hash",
|
|
587
583
|
);
|
|
588
|
-
expect(locationUrl.absUrl
|
|
584
|
+
expect(locationUrl.absUrl).toBe(
|
|
589
585
|
"http://www.server.org:1234/base?base=param#/path?a=b&c#hash",
|
|
590
586
|
);
|
|
591
587
|
|
|
592
|
-
locationUrl.
|
|
593
|
-
locationUrl.
|
|
594
|
-
locationUrl.
|
|
595
|
-
expect(locationUrl.absUrl
|
|
588
|
+
locationUrl.setPath("/new/path");
|
|
589
|
+
locationUrl.setSearch({ one: 1 });
|
|
590
|
+
locationUrl.setHash("hhh");
|
|
591
|
+
expect(locationUrl.absUrl).toBe(
|
|
596
592
|
"http://www.server.org:1234/base?base=param#/new/path?one=1#hhh",
|
|
597
593
|
);
|
|
598
594
|
});
|
|
599
595
|
|
|
600
596
|
it("should prefix path with forward-slash", () => {
|
|
601
|
-
const locationUrl = new
|
|
597
|
+
const locationUrl = new Location(
|
|
602
598
|
"http://host.com/base",
|
|
603
599
|
"http://host.com/",
|
|
600
|
+
false,
|
|
604
601
|
"#",
|
|
605
602
|
);
|
|
606
|
-
locationUrl
|
|
607
|
-
expect(locationUrl.
|
|
608
|
-
expect(locationUrl.absUrl
|
|
603
|
+
locationUrl.parse("http://host.com/base#path");
|
|
604
|
+
expect(locationUrl.getPath()).toBe("/path");
|
|
605
|
+
expect(locationUrl.absUrl).toBe("http://host.com/base#/path");
|
|
609
606
|
|
|
610
|
-
locationUrl.
|
|
611
|
-
expect(locationUrl.
|
|
612
|
-
expect(locationUrl.absUrl
|
|
607
|
+
locationUrl.setPath("wrong");
|
|
608
|
+
expect(locationUrl.getPath()).toBe("/wrong");
|
|
609
|
+
expect(locationUrl.absUrl).toBe("http://host.com/base#/wrong");
|
|
613
610
|
});
|
|
614
611
|
|
|
615
612
|
it("should set path to forward-slash when empty", () => {
|
|
616
|
-
const locationUrl = new
|
|
613
|
+
const locationUrl = new Location(
|
|
617
614
|
"http://server/base",
|
|
618
615
|
"http://server/",
|
|
616
|
+
false,
|
|
619
617
|
"#!",
|
|
620
618
|
);
|
|
621
|
-
locationUrl
|
|
622
|
-
locationUrl.
|
|
619
|
+
locationUrl.parse("http://server/base");
|
|
620
|
+
locationUrl.setPath("aaa");
|
|
623
621
|
|
|
624
|
-
expect(locationUrl.
|
|
625
|
-
expect(locationUrl.absUrl
|
|
622
|
+
expect(locationUrl.getPath()).toBe("/aaa");
|
|
623
|
+
expect(locationUrl.absUrl).toBe("http://server/base#!/aaa");
|
|
626
624
|
});
|
|
627
625
|
|
|
628
626
|
it("should not preserve old properties when parsing new url", () => {
|
|
629
627
|
const locationUrl = createHashbangUrl();
|
|
630
|
-
locationUrl
|
|
628
|
+
locationUrl.parse("http://www.server.org:1234/base#!/");
|
|
631
629
|
|
|
632
|
-
expect(locationUrl.
|
|
633
|
-
expect(locationUrl.
|
|
634
|
-
expect(locationUrl.
|
|
635
|
-
expect(locationUrl.absUrl
|
|
630
|
+
expect(locationUrl.getPath()).toBe("/");
|
|
631
|
+
expect(locationUrl.getSearch()).toEqual({});
|
|
632
|
+
expect(locationUrl.getHash()).toBe("");
|
|
633
|
+
expect(locationUrl.absUrl).toBe("http://www.server.org:1234/base#!/");
|
|
636
634
|
});
|
|
637
635
|
|
|
638
636
|
it("should insert default hashbang if a hash is given with no hashbang prefix", () => {
|
|
639
637
|
const locationUrl = createHashbangUrl();
|
|
640
638
|
|
|
641
|
-
locationUrl
|
|
642
|
-
expect(locationUrl.absUrl
|
|
639
|
+
locationUrl.parse("http://www.server.org:1234/base#/path");
|
|
640
|
+
expect(locationUrl.absUrl).toBe(
|
|
643
641
|
"http://www.server.org:1234/base#!#%2Fpath",
|
|
644
642
|
);
|
|
645
|
-
expect(locationUrl.
|
|
646
|
-
expect(locationUrl.
|
|
643
|
+
expect(locationUrl.getHash()).toBe("/path");
|
|
644
|
+
expect(locationUrl.getPath()).toBe("");
|
|
647
645
|
|
|
648
|
-
locationUrl
|
|
649
|
-
expect(locationUrl.absUrl
|
|
650
|
-
expect(locationUrl.
|
|
651
|
-
expect(locationUrl.
|
|
646
|
+
locationUrl.parse("http://www.server.org:1234/base#");
|
|
647
|
+
expect(locationUrl.absUrl).toBe("http://www.server.org:1234/base");
|
|
648
|
+
expect(locationUrl.getHash()).toBe("");
|
|
649
|
+
expect(locationUrl.getPath()).toBe("");
|
|
652
650
|
});
|
|
653
651
|
|
|
654
652
|
it("should ignore extra path segments if no hashbang is given", () => {
|
|
655
653
|
const locationUrl = createHashbangUrl();
|
|
656
|
-
locationUrl
|
|
657
|
-
expect(locationUrl.absUrl
|
|
658
|
-
expect(locationUrl.
|
|
659
|
-
expect(locationUrl.
|
|
654
|
+
locationUrl.parse("http://www.server.org:1234/base/extra/path");
|
|
655
|
+
expect(locationUrl.absUrl).toBe("http://www.server.org:1234/base");
|
|
656
|
+
expect(locationUrl.getPath()).toBe("");
|
|
657
|
+
expect(locationUrl.getHash()).toBe("");
|
|
660
658
|
});
|
|
661
659
|
|
|
662
660
|
describe("encoding", () => {
|
|
663
661
|
it("should encode special characters", () => {
|
|
664
662
|
const locationUrl = createHashbangUrl();
|
|
665
|
-
locationUrl.
|
|
666
|
-
locationUrl.
|
|
667
|
-
locationUrl.
|
|
668
|
-
|
|
669
|
-
expect(locationUrl.
|
|
670
|
-
expect(locationUrl.
|
|
671
|
-
expect(locationUrl.
|
|
672
|
-
expect(locationUrl.absUrl
|
|
663
|
+
locationUrl.setPath("/a <>#");
|
|
664
|
+
locationUrl.setSearch({ "i j": "<>#" });
|
|
665
|
+
locationUrl.setHash("<>#");
|
|
666
|
+
|
|
667
|
+
expect(locationUrl.getPath()).toBe("/a <>#");
|
|
668
|
+
expect(locationUrl.getSearch()).toEqual({ "i j": "<>#" });
|
|
669
|
+
expect(locationUrl.getHash()).toBe("<>#");
|
|
670
|
+
expect(locationUrl.absUrl).toBe(
|
|
673
671
|
"http://www.server.org:1234/base#!/a%20%3C%3E%23?i%20j=%3C%3E%23#%3C%3E%23",
|
|
674
672
|
);
|
|
675
673
|
});
|
|
676
674
|
|
|
677
675
|
it("should not encode !$:@", () => {
|
|
678
676
|
const locationUrl = createHashbangUrl();
|
|
679
|
-
locationUrl.
|
|
680
|
-
locationUrl.
|
|
681
|
-
locationUrl.
|
|
677
|
+
locationUrl.setPath("/!$:@");
|
|
678
|
+
locationUrl.setSearch("");
|
|
679
|
+
locationUrl.setHash("!$:@");
|
|
682
680
|
|
|
683
|
-
expect(locationUrl.absUrl
|
|
681
|
+
expect(locationUrl.absUrl).toBe(
|
|
684
682
|
"http://www.server.org:1234/base#!/!$:@#!$:@",
|
|
685
683
|
);
|
|
686
684
|
});
|
|
687
685
|
|
|
688
686
|
it("should decode special characters", () => {
|
|
689
|
-
const locationUrl = new
|
|
687
|
+
const locationUrl = new Location(
|
|
690
688
|
"http://host.com/a",
|
|
691
689
|
"http://host.com/",
|
|
690
|
+
false,
|
|
692
691
|
"#",
|
|
693
692
|
);
|
|
694
|
-
locationUrl
|
|
693
|
+
locationUrl.parse(
|
|
695
694
|
"http://host.com/a#/%20%3C%3E%23?i%20j=%3C%3E%23#x%20%3C%3E%23",
|
|
696
695
|
);
|
|
697
|
-
expect(locationUrl.
|
|
698
|
-
expect(locationUrl.
|
|
699
|
-
expect(locationUrl.
|
|
696
|
+
expect(locationUrl.getPath()).toBe("/ <>#");
|
|
697
|
+
expect(locationUrl.getSearch()).toEqual({ "i j": "<>#" });
|
|
698
|
+
expect(locationUrl.getHash()).toBe("x <>#");
|
|
700
699
|
});
|
|
701
700
|
|
|
702
701
|
it("should return decoded characters for search specified in URL", () => {
|
|
703
|
-
const locationUrl = new
|
|
702
|
+
const locationUrl = new Location(
|
|
704
703
|
"http://host.com/",
|
|
705
704
|
"http://host.com/",
|
|
705
|
+
true,
|
|
706
706
|
);
|
|
707
|
-
locationUrl
|
|
708
|
-
expect(locationUrl.
|
|
707
|
+
locationUrl.parse("http://host.com/?q=1%2F2%203");
|
|
708
|
+
expect(locationUrl.getSearch()).toEqual({ q: "1/2 3" });
|
|
709
709
|
});
|
|
710
710
|
|
|
711
711
|
it("should return decoded characters for search specified with setter", () => {
|
|
712
|
-
const locationUrl = new
|
|
712
|
+
const locationUrl = new Location(
|
|
713
713
|
"http://host.com/",
|
|
714
714
|
"http://host.com/",
|
|
715
|
+
true,
|
|
715
716
|
);
|
|
716
|
-
locationUrl
|
|
717
|
-
locationUrl.
|
|
718
|
-
expect(locationUrl.
|
|
717
|
+
locationUrl.parse("http://host.com/");
|
|
718
|
+
locationUrl.setSearch("q", "1/2 3");
|
|
719
|
+
expect(locationUrl.getSearch()).toEqual({ q: "1/2 3" });
|
|
719
720
|
});
|
|
720
721
|
|
|
721
722
|
it("should return an array for duplicate params", () => {
|
|
722
|
-
const locationUrl = new
|
|
723
|
+
const locationUrl = new Location(
|
|
723
724
|
"http://host.com",
|
|
724
725
|
"http://host.com",
|
|
726
|
+
true,
|
|
725
727
|
);
|
|
726
|
-
locationUrl
|
|
727
|
-
locationUrl.
|
|
728
|
-
expect(locationUrl.
|
|
728
|
+
locationUrl.parse("http://host.com");
|
|
729
|
+
locationUrl.setSearch("q", ["1/2 3", "4/5 6"]);
|
|
730
|
+
expect(locationUrl.getSearch()).toEqual({ q: ["1/2 3", "4/5 6"] });
|
|
729
731
|
});
|
|
730
732
|
|
|
731
733
|
it("should encode an array correctly from search and add to url", () => {
|
|
732
|
-
const locationUrl = new
|
|
734
|
+
const locationUrl = new Location(
|
|
733
735
|
"http://host.com",
|
|
734
736
|
"http://host.com",
|
|
737
|
+
true,
|
|
735
738
|
);
|
|
736
|
-
locationUrl
|
|
737
|
-
locationUrl.
|
|
738
|
-
expect(locationUrl.absUrl
|
|
739
|
+
locationUrl.parse("http://host.com");
|
|
740
|
+
locationUrl.setSearch({ q: ["1/2 3", "4/5 6"] });
|
|
741
|
+
expect(locationUrl.absUrl).toEqual(
|
|
739
742
|
"http://host.com?q=1%2F2%203&q=4%2F5%206",
|
|
740
743
|
);
|
|
741
744
|
});
|
|
742
745
|
|
|
743
746
|
it("should rewrite params when specifying a single param in search", () => {
|
|
744
|
-
const locationUrl = new
|
|
747
|
+
const locationUrl = new Location(
|
|
745
748
|
"http://host.com",
|
|
746
749
|
"http://host.com",
|
|
750
|
+
true,
|
|
747
751
|
);
|
|
748
|
-
locationUrl
|
|
749
|
-
locationUrl.
|
|
750
|
-
expect(locationUrl.absUrl
|
|
751
|
-
locationUrl.
|
|
752
|
-
expect(locationUrl.absUrl
|
|
752
|
+
locationUrl.parse("http://host.com");
|
|
753
|
+
locationUrl.setSearch({ q: "1/2 3" });
|
|
754
|
+
expect(locationUrl.absUrl).toEqual("http://host.com?q=1%2F2%203");
|
|
755
|
+
locationUrl.setSearch({ q: "4/5 6" });
|
|
756
|
+
expect(locationUrl.absUrl).toEqual("http://host.com?q=4%2F5%206");
|
|
753
757
|
});
|
|
754
758
|
|
|
755
|
-
it("url
|
|
756
|
-
const locationUrl = new
|
|
759
|
+
it("url getter/setter should decode non-component special characters in hashbang mode", () => {
|
|
760
|
+
const locationUrl = new Location(
|
|
757
761
|
"http://host.com",
|
|
758
762
|
"http://host.com",
|
|
763
|
+
false,
|
|
759
764
|
);
|
|
760
|
-
locationUrl
|
|
761
|
-
locationUrl.
|
|
762
|
-
expect(locationUrl.
|
|
765
|
+
locationUrl.parse("http://host.com");
|
|
766
|
+
locationUrl.setUrl("/foo%3Abar");
|
|
767
|
+
expect(locationUrl.getPath()).toEqual("/foo:bar");
|
|
763
768
|
});
|
|
764
769
|
|
|
765
|
-
it("url
|
|
766
|
-
const locationUrl = new
|
|
770
|
+
it("url getter/setter should decode non-component special characters in html5 mode", () => {
|
|
771
|
+
const locationUrl = new Location(
|
|
767
772
|
"http://host.com",
|
|
768
773
|
"http://host.com",
|
|
774
|
+
true,
|
|
769
775
|
);
|
|
770
|
-
locationUrl
|
|
771
|
-
locationUrl.
|
|
772
|
-
expect(locationUrl.
|
|
776
|
+
locationUrl.parse("http://host.com");
|
|
777
|
+
locationUrl.setUrl("/foo%3Abar");
|
|
778
|
+
expect(locationUrl.getPath()).toEqual("/foo:bar");
|
|
773
779
|
});
|
|
774
780
|
});
|
|
775
781
|
});
|
|
776
782
|
|
|
783
|
+
describe("encodePath", () => {
|
|
784
|
+
it("should encode each segment but preserve slashes", () => {
|
|
785
|
+
const input = "user profile/images/pic 1.jpg";
|
|
786
|
+
const result = encodePath(input);
|
|
787
|
+
expect(result).toBe("user%20profile/images/pic%201.jpg");
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
it("should re-encode previously encoded forward slashes as literal slashes", () => {
|
|
791
|
+
const input = "folder1%2Fsub/folder2";
|
|
792
|
+
const result = encodePath(input);
|
|
793
|
+
expect(result).toBe("folder1%2Fsub/folder2");
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
it("should handle special characters properly", () => {
|
|
797
|
+
const input = "a$bc/def@gh";
|
|
798
|
+
const result = encodePath(input);
|
|
799
|
+
expect(result).toBe("a$bc/def@gh");
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
it("should return empty string for empty path", () => {
|
|
803
|
+
const input = "";
|
|
804
|
+
const result = encodePath(input);
|
|
805
|
+
expect(result).toBe("");
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
it("should handle single segment", () => {
|
|
809
|
+
const input = "hello world";
|
|
810
|
+
const result = encodePath(input);
|
|
811
|
+
expect(result).toBe("hello%20world");
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
it("should not double encode already encoded segments except slashes", () => {
|
|
815
|
+
const input = "one%20two/three%2Ffour";
|
|
816
|
+
const result = encodePath(input);
|
|
817
|
+
expect(result).toBe("one%20two/three%2Ffour");
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
it("should not double encode already encoded segments", () => {
|
|
821
|
+
const input = "double%20encoded";
|
|
822
|
+
const result = encodePath(input);
|
|
823
|
+
expect(result).toBe("double%20encoded");
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
it("should preserve double encoded segments as-is (single decode only)", () => {
|
|
827
|
+
const input = "double%2520encoded";
|
|
828
|
+
const result = encodePath(input);
|
|
829
|
+
expect(result).toBe("double%2520encoded"); // double % stays double encoded
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
it("should preserve leading and trailing slashes", () => {
|
|
833
|
+
const input = "/a b/c d/";
|
|
834
|
+
const result = encodePath(input);
|
|
835
|
+
expect(result).toBe("/a%20b/c%20d/");
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
it("should preserve multiple consecutive slashes as empty segments", () => {
|
|
839
|
+
const input = "foo//bar///baz";
|
|
840
|
+
const result = encodePath(input);
|
|
841
|
+
expect(result).toBe("foo//bar///baz");
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
it("should not encode RFC 3986 reserved characters in segments", () => {
|
|
845
|
+
const input = "key=value/param+test";
|
|
846
|
+
const result = encodePath(input);
|
|
847
|
+
expect(result).toBe("key=value/param+test");
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
it("should encode unicode characters properly", () => {
|
|
851
|
+
const input = "café/naïve";
|
|
852
|
+
const result = encodePath(input);
|
|
853
|
+
expect(result).toBe("caf%C3%A9/na%C3%AFve");
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
it("should handle input with only slashes", () => {
|
|
857
|
+
const input = "///";
|
|
858
|
+
const result = encodePath(input);
|
|
859
|
+
expect(result).toBe("///");
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
it("should treat encoded slashes as literal and decoded slashes as separators", () => {
|
|
863
|
+
const input = "part1%2Fsub/part2";
|
|
864
|
+
const result = encodePath(input);
|
|
865
|
+
expect(result).toBe("part1%2Fsub/part2");
|
|
866
|
+
});
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
describe("decodePath", () => {
|
|
870
|
+
it("should decode percent-encoded segments", () => {
|
|
871
|
+
const input = "hello%20world/abc%40def";
|
|
872
|
+
const result = decodePath(input, false);
|
|
873
|
+
expect(result).toBe("hello world/abc@def");
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
it("should encode slashes as %2F in html5Mode", () => {
|
|
877
|
+
const input = "section%2Fname/data";
|
|
878
|
+
const result = decodePath(input, true);
|
|
879
|
+
expect(result).toBe("section%2Fname/data");
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
it("should preserve decoded forward slashes in html5Mode", () => {
|
|
883
|
+
const input = "foo/bar%2Fbaz/qux";
|
|
884
|
+
const result = decodePath(input, true);
|
|
885
|
+
// 'bar/baz' becomes 'bar%2Fbaz'
|
|
886
|
+
expect(result).toBe("foo/bar%2Fbaz/qux");
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
it("should not change decoded slashes when html5Mode is false", () => {
|
|
890
|
+
const input = "foo/bar%2Fbaz/qux";
|
|
891
|
+
const result = decodePath(input, false);
|
|
892
|
+
expect(result).toBe("foo/bar/baz/qux");
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
it("should handle empty segments correctly", () => {
|
|
896
|
+
const input = "a//b";
|
|
897
|
+
const result = decodePath(input, false);
|
|
898
|
+
expect(result).toBe("a//b"); // empty segment remains
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
it("should decode already decoded values without errors", () => {
|
|
902
|
+
const input = "simple/path";
|
|
903
|
+
const result = decodePath(input, false);
|
|
904
|
+
expect(result).toBe("simple/path");
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
it("should decode and re-encode all forward slashes in segments when html5Mode is true", () => {
|
|
908
|
+
const input = "a%2Fb/c%2Fd";
|
|
909
|
+
const result = decodePath(input, true);
|
|
910
|
+
expect(result).toBe("a%2Fb/c%2Fd");
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
it("should return an empty string if given an empty string", () => {
|
|
914
|
+
expect(decodePath("", false)).toBe("");
|
|
915
|
+
expect(decodePath("", true)).toBe("");
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
it("should decode double-encoded segments only once", () => {
|
|
919
|
+
const input = "double%2520encoded"; // '%2520' = '%20'
|
|
920
|
+
const result = decodePath(input, false);
|
|
921
|
+
expect(result).toBe("double%20encoded"); // Only decode once
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
it("should correctly decode reserved URI characters", () => {
|
|
925
|
+
const input = "%3A%3B%26%3D";
|
|
926
|
+
const result = decodePath(input, false);
|
|
927
|
+
expect(result).toBe(":;&=");
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
it("should throw URIError for malformed percent encodings", () => {
|
|
931
|
+
const input = "bad%encoding";
|
|
932
|
+
expect(() => decodePath(input, false)).toThrowError(URIError);
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
it("should preserve leading and trailing empty segments", () => {
|
|
936
|
+
const input = "/path/with/trailing/";
|
|
937
|
+
const result = decodePath(input, false);
|
|
938
|
+
expect(result).toBe("/path/with/trailing/");
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
it("should re-encode slashes inside segments when html5Mode is true", () => {
|
|
942
|
+
const input = "path%2Fsegment/next";
|
|
943
|
+
const result = decodePath(input, true);
|
|
944
|
+
expect(result).toBe("path%2Fsegment/next");
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
it("should handle completely empty segments (multiple slashes)", () => {
|
|
948
|
+
const input = "///";
|
|
949
|
+
const result = decodePath(input, false);
|
|
950
|
+
expect(result).toBe("///");
|
|
951
|
+
});
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
describe("normalizePath", () => {
|
|
955
|
+
it("should encode the path, append search and hash correctly", () => {
|
|
956
|
+
const path = "folder name/file name";
|
|
957
|
+
const search = { q: "test", page: "1" };
|
|
958
|
+
const hash = "section 2";
|
|
959
|
+
|
|
960
|
+
const result = normalizePath(path, search, hash);
|
|
961
|
+
expect(result).toBe(
|
|
962
|
+
"folder%20name/file%20name?q=test&page=1#section%202",
|
|
963
|
+
);
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
it("should return path only if no search and no hash", () => {
|
|
967
|
+
const path = "simple/path";
|
|
968
|
+
const result = normalizePath(path, null, null);
|
|
969
|
+
expect(result).toBe("simple/path");
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
it("should correctly encode search params from object", () => {
|
|
973
|
+
const search = { a: "1", b: "2" };
|
|
974
|
+
const result = normalizePath("path", search, null);
|
|
975
|
+
expect(result).toBe("path?a=1&b=2");
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
it("should correctly encode array values in search", () => {
|
|
979
|
+
const search = { a: ["1", "2"] };
|
|
980
|
+
const result = normalizePath("path", search, null);
|
|
981
|
+
// Expected: a=1&a=2 (both keys repeated)
|
|
982
|
+
expect(result).toBe("path?a=1&a=2");
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
it("should handle boolean true values", () => {
|
|
986
|
+
const search = { flag: true };
|
|
987
|
+
const result = normalizePath("path", search, null);
|
|
988
|
+
expect(result).toBe("path?flag");
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
it("should encode hash value properly", () => {
|
|
992
|
+
const path = "path";
|
|
993
|
+
const hash = "hello world";
|
|
994
|
+
const result = normalizePath(path, null, hash);
|
|
995
|
+
expect(result).toBe("path#hello%20world");
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
it("should not append ? if search is empty string or empty object", () => {
|
|
999
|
+
expect(normalizePath("path", "", "hash")).toBe("path#hash");
|
|
1000
|
+
expect(normalizePath("path", {}, "hash")).toBe("path#hash");
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
it("should handle empty path gracefully", () => {
|
|
1004
|
+
const result = normalizePath("", { a: "1" }, "h");
|
|
1005
|
+
expect(result).toBe("?a=1#h");
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
describe("parseAppUrl", () => {
|
|
1010
|
+
let locationObj;
|
|
1011
|
+
|
|
1012
|
+
beforeEach(() => {
|
|
1013
|
+
locationObj = new Location(
|
|
1014
|
+
"http://www.domain.com:9877/",
|
|
1015
|
+
"http://www.domain.com:9877/",
|
|
1016
|
+
);
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
it("should throw error on url starting with // or \\\\", () => {
|
|
1020
|
+
expect(() => parseAppUrl("//invalid/path", false)).toThrowError(
|
|
1021
|
+
/Invalid url/,
|
|
1022
|
+
);
|
|
1023
|
+
expect(() => parseAppUrl("\\\\invalid\\path", false)).toThrowError(
|
|
1024
|
+
/Invalid url/,
|
|
1025
|
+
);
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
it("should add leading slash if missing and parse url correctly", () => {
|
|
1029
|
+
parseAppUrl("some/path?foo=bar#hashValue", false);
|
|
1030
|
+
expect(locationObj.getPath()).toBe("/some/path");
|
|
1031
|
+
expect(locationObj.getSearch()).toEqual(
|
|
1032
|
+
jasmine.objectContaining({ foo: "bar" }),
|
|
1033
|
+
);
|
|
1034
|
+
expect(locationObj.getHash()).toBe("hashValue");
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
it("should keep leading slash if present", () => {
|
|
1038
|
+
parseAppUrl("/already/slashed?x=1#abc", locationObj, false);
|
|
1039
|
+
expect(locationObj.getPath()).toBe("/already/slashed");
|
|
1040
|
+
expect(locationObj.getSearch()).toEqual(
|
|
1041
|
+
jasmine.objectContaining({ x: "1" }),
|
|
1042
|
+
);
|
|
1043
|
+
expect(locationObj.getHash()).toBe("abc");
|
|
1044
|
+
});
|
|
1045
|
+
|
|
1046
|
+
it("should remove leading slash from path if prefixed and path starts with slash", () => {
|
|
1047
|
+
parseAppUrl("foo/bar", locationObj, false);
|
|
1048
|
+
expect(locationObj.getPath().charAt(0)).toBe("/");
|
|
1049
|
+
expect(locationObj.getPath()).toBe("/foo/bar");
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
it("should set empty $$search when no query params", () => {
|
|
1053
|
+
parseAppUrl("/pathOnly", locationObj, false);
|
|
1054
|
+
expect(locationObj.getSearch()).toEqual({});
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
it("should decode hash correctly", () => {
|
|
1058
|
+
parseAppUrl("/path#%23encoded", locationObj, false);
|
|
1059
|
+
expect(locationObj.getHash()).toBe("#encoded");
|
|
1060
|
+
});
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
describe("stripBaseUrl", () => {
|
|
1064
|
+
it("should return substring after base if url starts with base", () => {
|
|
1065
|
+
expect(stripBaseUrl("/base", "/base/some/path")).toBe("/some/path");
|
|
1066
|
+
expect(
|
|
1067
|
+
stripBaseUrl("http://example.com", "http://example.com/page"),
|
|
1068
|
+
).toBe("/page");
|
|
1069
|
+
expect(stripBaseUrl("", "/anything")).toBe("/anything"); // empty base returns full url
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
it("should return empty string if url equals base", () => {
|
|
1073
|
+
expect(stripBaseUrl("/base", "/base")).toBe("");
|
|
1074
|
+
});
|
|
1075
|
+
|
|
1076
|
+
it("should return undefined if url does not start with base", () => {
|
|
1077
|
+
expect(stripBaseUrl("/base", "/notbase/something")).toBeUndefined();
|
|
1078
|
+
expect(
|
|
1079
|
+
stripBaseUrl("http://example.com", "https://example.com/page"),
|
|
1080
|
+
).toBeUndefined();
|
|
1081
|
+
});
|
|
1082
|
+
|
|
1083
|
+
it("should handle base being longer than url", () => {
|
|
1084
|
+
expect(stripBaseUrl("/longer/base", "/short")).toBeUndefined();
|
|
1085
|
+
});
|
|
1086
|
+
|
|
1087
|
+
it("should be case sensitive", () => {
|
|
1088
|
+
expect(stripBaseUrl("/Base", "/base/something")).toBeUndefined();
|
|
1089
|
+
});
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
describe("stripHash", () => {
|
|
1093
|
+
it("should return the same URL if there is no hash", () => {
|
|
1094
|
+
expect(stripHash("http://example.com/path")).toBe(
|
|
1095
|
+
"http://example.com/path",
|
|
1096
|
+
);
|
|
1097
|
+
expect(stripHash("/some/path")).toBe("/some/path");
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
it("should remove the hash and everything after it", () => {
|
|
1101
|
+
expect(stripHash("http://example.com/path#section1")).toBe(
|
|
1102
|
+
"http://example.com/path",
|
|
1103
|
+
);
|
|
1104
|
+
expect(stripHash("/path/to/resource#hashvalue")).toBe(
|
|
1105
|
+
"/path/to/resource",
|
|
1106
|
+
);
|
|
1107
|
+
});
|
|
1108
|
+
|
|
1109
|
+
it("should remove hash even if it is at the very end", () => {
|
|
1110
|
+
expect(stripHash("http://example.com/#")).toBe("http://example.com/");
|
|
1111
|
+
});
|
|
1112
|
+
|
|
1113
|
+
it("should handle empty string input", () => {
|
|
1114
|
+
expect(stripHash("")).toBe("");
|
|
1115
|
+
});
|
|
1116
|
+
|
|
1117
|
+
it("should handle hash only string", () => {
|
|
1118
|
+
expect(stripHash("#hashonly")).toBe("");
|
|
1119
|
+
});
|
|
1120
|
+
});
|
|
1121
|
+
|
|
1122
|
+
describe("stripFile", () => {
|
|
1123
|
+
it("removes filename from URL without hash", () => {
|
|
1124
|
+
const input = "https://example.com/path/to/file.js";
|
|
1125
|
+
const expected = "https://example.com/path/to/";
|
|
1126
|
+
expect(stripFile(input)).toBe(expected);
|
|
1127
|
+
});
|
|
1128
|
+
|
|
1129
|
+
it("removes filename and hash from URL", () => {
|
|
1130
|
+
const input = "https://example.com/path/to/file.js#section";
|
|
1131
|
+
const expected = "https://example.com/path/to/";
|
|
1132
|
+
expect(stripFile(input)).toBe(expected);
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
it("handles root URL with file", () => {
|
|
1136
|
+
const input = "https://example.com/file.js";
|
|
1137
|
+
const expected = "https://example.com/";
|
|
1138
|
+
expect(stripFile(input)).toBe(expected);
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
it("handles URL with no file", () => {
|
|
1142
|
+
const input = "https://example.com/path/to/";
|
|
1143
|
+
const expected = "https://example.com/path/to/";
|
|
1144
|
+
expect(stripFile(input)).toBe(expected);
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
it("handles relative URL with file and hash", () => {
|
|
1148
|
+
const input = "docs/static/app.js#v1";
|
|
1149
|
+
const expected = "docs/static/";
|
|
1150
|
+
expect(stripFile(input)).toBe(expected);
|
|
1151
|
+
});
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
describe("serverBase", () => {
|
|
1155
|
+
it("returns server base for https URL without port", () => {
|
|
1156
|
+
const input = "https://example.com/path/to/resource";
|
|
1157
|
+
const expected = "https://example.com";
|
|
1158
|
+
expect(serverBase(input)).toBe(expected);
|
|
1159
|
+
});
|
|
1160
|
+
|
|
1161
|
+
it("returns server base for http URL with port", () => {
|
|
1162
|
+
const input = "http://localhost:8080/api/data";
|
|
1163
|
+
const expected = "http://localhost:8080";
|
|
1164
|
+
expect(serverBase(input)).toBe(expected);
|
|
1165
|
+
});
|
|
1166
|
+
|
|
1167
|
+
it("returns server base for URL with subdomain", () => {
|
|
1168
|
+
const input = "https://api.example.com/v1/query";
|
|
1169
|
+
const expected = "https://api.example.com";
|
|
1170
|
+
expect(serverBase(input)).toBe(expected);
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
it("returns full URL if no path is present", () => {
|
|
1174
|
+
const input = "https://example.com";
|
|
1175
|
+
const expected = "https://example.com";
|
|
1176
|
+
expect(serverBase(input)).toBe(expected);
|
|
1177
|
+
});
|
|
1178
|
+
|
|
1179
|
+
it("handles trailing slash after host", () => {
|
|
1180
|
+
const input = "https://example.com/";
|
|
1181
|
+
const expected = "https://example.com";
|
|
1182
|
+
expect(serverBase(input)).toBe(expected);
|
|
1183
|
+
});
|
|
1184
|
+
});
|
|
1185
|
+
|
|
1186
|
+
describe("urlsEqual", () => {
|
|
1187
|
+
it("matches same URL", () => {
|
|
1188
|
+
expect(
|
|
1189
|
+
urlsEqual("http://example.com/foo", "http://example.com/foo"),
|
|
1190
|
+
).toBe(true);
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1193
|
+
it("ignores trailing slash", () => {
|
|
1194
|
+
expect(
|
|
1195
|
+
urlsEqual("http://example.com/foo/", "http://example.com/foo"),
|
|
1196
|
+
).toBe(true);
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
it("ignores encoded spaces", () => {
|
|
1200
|
+
expect(
|
|
1201
|
+
urlsEqual("http://example.com/foo%20bar", "http://example.com/foo bar"),
|
|
1202
|
+
).toBe(true);
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
it("ignores empty hash", () => {
|
|
1206
|
+
expect(
|
|
1207
|
+
urlsEqual("http://example.com/foo#", "http://example.com/foo"),
|
|
1208
|
+
).toBe(true);
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
it("resolves relative to base href", () => {
|
|
1212
|
+
const base = document.createElement("base");
|
|
1213
|
+
base.href = "http://localhost/";
|
|
1214
|
+
document.head.appendChild(base);
|
|
1215
|
+
|
|
1216
|
+
expect(urlsEqual("/bar", "http://localhost/bar")).toBe(true);
|
|
1217
|
+
|
|
1218
|
+
document.head.removeChild(base); // cleanup
|
|
1219
|
+
});
|
|
1220
|
+
|
|
1221
|
+
it("returns false for different paths", () => {
|
|
1222
|
+
expect(
|
|
1223
|
+
urlsEqual("http://example.com/foo", "http://example.com/bar"),
|
|
1224
|
+
).toBe(false);
|
|
1225
|
+
});
|
|
1226
|
+
});
|
|
1227
|
+
|
|
777
1228
|
// describe("location watch", () => {
|
|
778
1229
|
// it("should not update browser if only the empty hash fragment is cleared", () => {
|
|
779
1230
|
// initService({ supportHistory: true });
|
|
@@ -794,7 +1245,7 @@ describe("$location", () => {
|
|
|
794
1245
|
// mockUpBrowser({ initialUrl: "http://new.com/#", baseHref: "/" });
|
|
795
1246
|
// inject(($browser, $location, $window) => {
|
|
796
1247
|
// expect($browser.url()).toBe("http://new.com/");
|
|
797
|
-
// expect($location.absUrl
|
|
1248
|
+
// expect($location.absUrl).toBe("http://new.com/");
|
|
798
1249
|
// expect($window.location.href).toBe("http://new.com/#");
|
|
799
1250
|
// });
|
|
800
1251
|
// });
|
|
@@ -809,8 +1260,8 @@ describe("$location", () => {
|
|
|
809
1260
|
// let handlerCalled = false;
|
|
810
1261
|
// $rootScope.$on("$locationChangeSuccess", () => {
|
|
811
1262
|
// handlerCalled = true;
|
|
812
|
-
// if ($location.
|
|
813
|
-
// $location.
|
|
1263
|
+
// if ($location.getPath() !== "/") {
|
|
1264
|
+
// $location.setPath("/").replace();
|
|
814
1265
|
// }
|
|
815
1266
|
// });
|
|
816
1267
|
// expect($browser.url()).toEqual("http://server/base/#!/home");
|
|
@@ -899,7 +1350,7 @@ describe("$location", () => {
|
|
|
899
1350
|
// $rootScope,
|
|
900
1351
|
// $window,
|
|
901
1352
|
// ) => {
|
|
902
|
-
// $location.
|
|
1353
|
+
// $location.setUrl("baz");
|
|
903
1354
|
// $rootScope.$digest();
|
|
904
1355
|
|
|
905
1356
|
// const originalUrl = $window.location.href;
|
|
@@ -911,7 +1362,7 @@ describe("$location", () => {
|
|
|
911
1362
|
// });
|
|
912
1363
|
|
|
913
1364
|
// expect($browser.url()).toBe("http://foo.bar/#!/baz/qux");
|
|
914
|
-
// expect($location.absUrl
|
|
1365
|
+
// expect($location.absUrl).toBe("http://foo.bar/#!/baz/qux");
|
|
915
1366
|
|
|
916
1367
|
// $rootScope.$apply(() => {
|
|
917
1368
|
// $rootScope.$evalAsync(() => {
|
|
@@ -920,7 +1371,7 @@ describe("$location", () => {
|
|
|
920
1371
|
// });
|
|
921
1372
|
|
|
922
1373
|
// expect($browser.url()).toBe("http://foo.bar/#!/baz/quux");
|
|
923
|
-
// expect($location.absUrl
|
|
1374
|
+
// expect($location.absUrl).toBe("http://foo.bar/#!/baz/quux");
|
|
924
1375
|
// }));
|
|
925
1376
|
|
|
926
1377
|
// it("should correctly update `$location` from URL and not digest infinitely", inject((
|
|
@@ -929,7 +1380,7 @@ describe("$location", () => {
|
|
|
929
1380
|
// $rootScope,
|
|
930
1381
|
// $window,
|
|
931
1382
|
// ) => {
|
|
932
|
-
// $location.
|
|
1383
|
+
// $location.setUrl("baz");
|
|
933
1384
|
// $rootScope.$digest();
|
|
934
1385
|
|
|
935
1386
|
// $rootScope.$apply(() => {
|
|
@@ -941,16 +1392,16 @@ describe("$location", () => {
|
|
|
941
1392
|
// ($window).triggerHandler("hashchange");
|
|
942
1393
|
|
|
943
1394
|
// expect($browser.url()).toBe("http://foo.bar/#!/baz/qux");
|
|
944
|
-
// expect($location.absUrl
|
|
1395
|
+
// expect($location.absUrl).toBe("http://foo.bar/#!/baz/qux");
|
|
945
1396
|
// }));
|
|
946
1397
|
// });
|
|
947
1398
|
|
|
948
1399
|
// function updatePathOnLocationChangeSuccessTo(newPath, newParams) {
|
|
949
1400
|
// inject(($rootScope, $location) => {
|
|
950
1401
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
951
|
-
// $location.
|
|
1402
|
+
// $location.setPath(newPath);
|
|
952
1403
|
// if (newParams) {
|
|
953
|
-
// $location.
|
|
1404
|
+
// $location.setSearch(newParams);
|
|
954
1405
|
// }
|
|
955
1406
|
// });
|
|
956
1407
|
// });
|
|
@@ -971,7 +1422,7 @@ describe("$location", () => {
|
|
|
971
1422
|
// $rootScope.$digest();
|
|
972
1423
|
|
|
973
1424
|
// expect($browser.url()).toEqual("http://server/app/#!/Home");
|
|
974
|
-
// expect($location.
|
|
1425
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
975
1426
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
976
1427
|
// });
|
|
977
1428
|
// });
|
|
@@ -993,7 +1444,7 @@ describe("$location", () => {
|
|
|
993
1444
|
// $rootScope.$digest();
|
|
994
1445
|
|
|
995
1446
|
// expect($browser.url()).toEqual("http://server/app/#!/");
|
|
996
|
-
// expect($location.
|
|
1447
|
+
// expect($location.getPath()).toEqual("/");
|
|
997
1448
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
998
1449
|
// expect($browserUrl.calls.argsFor(0)).toEqual([
|
|
999
1450
|
// "http://server/app/#!/",
|
|
@@ -1016,7 +1467,7 @@ describe("$location", () => {
|
|
|
1016
1467
|
// $rootScope.$digest();
|
|
1017
1468
|
|
|
1018
1469
|
// expect($browser.url()).toEqual("http://server/app/#!/Home");
|
|
1019
|
-
// expect($location.
|
|
1470
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
1020
1471
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
1021
1472
|
// expect($browserUrl.calls.argsFor(0)).toEqual([
|
|
1022
1473
|
// "http://server/app/#!/Home",
|
|
@@ -1039,7 +1490,7 @@ describe("$location", () => {
|
|
|
1039
1490
|
// $rootScope.$digest();
|
|
1040
1491
|
|
|
1041
1492
|
// expect($browser.url()).toEqual("http://server/app/#!/");
|
|
1042
|
-
// expect($location.
|
|
1493
|
+
// expect($location.getPath()).toEqual("/");
|
|
1043
1494
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
1044
1495
|
// });
|
|
1045
1496
|
// });
|
|
@@ -1061,7 +1512,7 @@ describe("$location", () => {
|
|
|
1061
1512
|
// $rootScope.$digest();
|
|
1062
1513
|
|
|
1063
1514
|
// expect($browser.url()).toEqual("http://server/app/Home");
|
|
1064
|
-
// expect($location.
|
|
1515
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
1065
1516
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
1066
1517
|
// });
|
|
1067
1518
|
// });
|
|
@@ -1081,7 +1532,7 @@ describe("$location", () => {
|
|
|
1081
1532
|
// $rootScope.$digest();
|
|
1082
1533
|
|
|
1083
1534
|
// expect($browser.url()).toEqual("http://server/app/");
|
|
1084
|
-
// expect($location.
|
|
1535
|
+
// expect($location.getPath()).toEqual("/");
|
|
1085
1536
|
// expect($browserUrl).not.toHaveBeenCalled();
|
|
1086
1537
|
// });
|
|
1087
1538
|
// });
|
|
@@ -1101,7 +1552,7 @@ describe("$location", () => {
|
|
|
1101
1552
|
// $rootScope.$digest();
|
|
1102
1553
|
|
|
1103
1554
|
// expect($browser.url()).toEqual("http://server/app/Home");
|
|
1104
|
-
// expect($location.
|
|
1555
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
1105
1556
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
1106
1557
|
// });
|
|
1107
1558
|
// });
|
|
@@ -1121,7 +1572,7 @@ describe("$location", () => {
|
|
|
1121
1572
|
// $rootScope.$digest();
|
|
1122
1573
|
|
|
1123
1574
|
// expect($browser.url()).toEqual("http://server/app/");
|
|
1124
|
-
// expect($location.
|
|
1575
|
+
// expect($location.getPath()).toEqual("/");
|
|
1125
1576
|
// expect($browserUrl).not.toHaveBeenCalled();
|
|
1126
1577
|
// });
|
|
1127
1578
|
// });
|
|
@@ -1141,8 +1592,8 @@ describe("$location", () => {
|
|
|
1141
1592
|
|
|
1142
1593
|
// $rootScope.$digest();
|
|
1143
1594
|
|
|
1144
|
-
// expect($location.
|
|
1145
|
-
// expect($location.
|
|
1595
|
+
// expect($location.getPath()).toEqual("/");
|
|
1596
|
+
// expect($location.getSearch()).toEqual({ q: "'" });
|
|
1146
1597
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
1147
1598
|
// });
|
|
1148
1599
|
// });
|
|
@@ -1154,12 +1605,12 @@ describe("$location", () => {
|
|
|
1154
1605
|
// initService({ html5Mode: false, hashPrefix: "!", supportHistory: true });
|
|
1155
1606
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
|
|
1156
1607
|
// inject(($window, $browser, $location, $rootScope) => {
|
|
1157
|
-
// spyOn($location, "
|
|
1608
|
+
// spyOn($location, "parse").and.callThrough();
|
|
1158
1609
|
// $window.location.href = "http://new.com/a/b#!/aaa";
|
|
1159
1610
|
// $browser.$$checkUrlChange();
|
|
1160
|
-
// expect($location.absUrl
|
|
1161
|
-
// expect($location.
|
|
1162
|
-
// expect($location
|
|
1611
|
+
// expect($location.absUrl).toBe("http://new.com/a/b#!/aaa");
|
|
1612
|
+
// expect($location.getPath()).toBe("/aaa");
|
|
1613
|
+
// expect($location.parse).toHaveBeenCalled();
|
|
1163
1614
|
// });
|
|
1164
1615
|
// });
|
|
1165
1616
|
|
|
@@ -1174,10 +1625,10 @@ describe("$location", () => {
|
|
|
1174
1625
|
// $rootScope.$apply(() => {
|
|
1175
1626
|
// $window.location.href = NEW_URL;
|
|
1176
1627
|
// $browser.$$checkUrlChange(); // simulate firing event from browser
|
|
1177
|
-
// expect($location.absUrl
|
|
1628
|
+
// expect($location.absUrl).toBe(OLD_URL); // should be async
|
|
1178
1629
|
// });
|
|
1179
1630
|
|
|
1180
|
-
// expect($location.absUrl
|
|
1631
|
+
// expect($location.absUrl).toBe(NEW_URL);
|
|
1181
1632
|
// });
|
|
1182
1633
|
// });
|
|
1183
1634
|
|
|
@@ -1195,12 +1646,12 @@ describe("$location", () => {
|
|
|
1195
1646
|
// notRunYet = false;
|
|
1196
1647
|
// $window.location.href = NEW_URL;
|
|
1197
1648
|
// $browser.$$checkUrlChange(); // simulate firing event from browser
|
|
1198
|
-
// expect($location.absUrl
|
|
1649
|
+
// expect($location.absUrl).toBe(OLD_URL); // should be async
|
|
1199
1650
|
// }
|
|
1200
1651
|
// });
|
|
1201
1652
|
|
|
1202
1653
|
// $rootScope.$digest();
|
|
1203
|
-
// expect($location.absUrl
|
|
1654
|
+
// expect($location.absUrl).toBe(NEW_URL);
|
|
1204
1655
|
// });
|
|
1205
1656
|
// });
|
|
1206
1657
|
|
|
@@ -1212,7 +1663,7 @@ describe("$location", () => {
|
|
|
1212
1663
|
// $browser,
|
|
1213
1664
|
// "url",
|
|
1214
1665
|
// ).and.callThrough();
|
|
1215
|
-
// $location.
|
|
1666
|
+
// $location.setPath("/new/path");
|
|
1216
1667
|
// expect($browserUrl).not.toHaveBeenCalled();
|
|
1217
1668
|
// $rootScope.$apply();
|
|
1218
1669
|
|
|
@@ -1229,10 +1680,10 @@ describe("$location", () => {
|
|
|
1229
1680
|
// $browser,
|
|
1230
1681
|
// "url",
|
|
1231
1682
|
// ).and.callThrough();
|
|
1232
|
-
// $location.
|
|
1683
|
+
// $location.setPath("/new/path");
|
|
1233
1684
|
|
|
1234
1685
|
// $rootScope.$watch(() => {
|
|
1235
|
-
// $location.
|
|
1686
|
+
// $location.setSearch("a=b");
|
|
1236
1687
|
// });
|
|
1237
1688
|
|
|
1238
1689
|
// $rootScope.$apply();
|
|
@@ -1249,7 +1700,7 @@ describe("$location", () => {
|
|
|
1249
1700
|
// $browser,
|
|
1250
1701
|
// "url",
|
|
1251
1702
|
// ).and.callThrough();
|
|
1252
|
-
// $location.
|
|
1703
|
+
// $location.setPath("/n/url").replace();
|
|
1253
1704
|
// $rootScope.$apply();
|
|
1254
1705
|
|
|
1255
1706
|
// expect($browserUrl).toHaveBeenCalled();
|
|
@@ -1267,16 +1718,16 @@ describe("$location", () => {
|
|
|
1267
1718
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
|
|
1268
1719
|
// inject(($rootScope, $browser, $location) => {
|
|
1269
1720
|
// // init watches
|
|
1270
|
-
// $location.
|
|
1721
|
+
// $location.setUrl("/initUrl");
|
|
1271
1722
|
// $rootScope.$apply();
|
|
1272
1723
|
|
|
1273
1724
|
// // changes url but resets it before digest
|
|
1274
|
-
// $location.
|
|
1725
|
+
// $location.setUrl("/newUrl").replace().url("/initUrl");
|
|
1275
1726
|
// $rootScope.$apply();
|
|
1276
1727
|
// expect($location.$$replace).toBe(false);
|
|
1277
1728
|
|
|
1278
1729
|
// // set the url to the old value
|
|
1279
|
-
// $location.
|
|
1730
|
+
// $location.setUrl("/newUrl").replace();
|
|
1280
1731
|
// $rootScope.$apply();
|
|
1281
1732
|
// expect($location.$$replace).toBe(false);
|
|
1282
1733
|
|
|
@@ -1294,7 +1745,7 @@ describe("$location", () => {
|
|
|
1294
1745
|
// $rootScope.$watch(
|
|
1295
1746
|
// () => true,
|
|
1296
1747
|
// () => {
|
|
1297
|
-
// $location.
|
|
1748
|
+
// $location.setPath("/changed");
|
|
1298
1749
|
// },
|
|
1299
1750
|
// );
|
|
1300
1751
|
|
|
@@ -1307,7 +1758,7 @@ describe("$location", () => {
|
|
|
1307
1758
|
// initService({ html5Mode: false, hashPrefix: "", supportHistory: true });
|
|
1308
1759
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b", baseHref: "/a/b" });
|
|
1309
1760
|
// inject(($rootScope, $browser, $location) => {
|
|
1310
|
-
// $location.
|
|
1761
|
+
// $location.setHash("test");
|
|
1311
1762
|
|
|
1312
1763
|
// $rootScope.$digest();
|
|
1313
1764
|
// expect($browser.url()).toBe("http://new.com/a/b##test");
|
|
@@ -1324,7 +1775,7 @@ describe("$location", () => {
|
|
|
1324
1775
|
// state: { a: 2 },
|
|
1325
1776
|
// });
|
|
1326
1777
|
// inject(($location) => {
|
|
1327
|
-
// expect($location.
|
|
1778
|
+
// expect($location.getState()).toEqual({ a: 2 });
|
|
1328
1779
|
// });
|
|
1329
1780
|
// });
|
|
1330
1781
|
|
|
@@ -1335,7 +1786,7 @@ describe("$location", () => {
|
|
|
1335
1786
|
// $window.history.pushState({ b: 3 });
|
|
1336
1787
|
// $rootScope.$digest();
|
|
1337
1788
|
|
|
1338
|
-
// expect($location.
|
|
1789
|
+
// expect($location.getState()).toEqual({ b: 3 });
|
|
1339
1790
|
|
|
1340
1791
|
// $window.history.pushState(
|
|
1341
1792
|
// { b: 4 },
|
|
@@ -1344,10 +1795,10 @@ describe("$location", () => {
|
|
|
1344
1795
|
// );
|
|
1345
1796
|
// $rootScope.$digest();
|
|
1346
1797
|
|
|
1347
|
-
// expect($location.
|
|
1348
|
-
// expect($location.
|
|
1349
|
-
// expect($location.
|
|
1350
|
-
// expect($location.
|
|
1798
|
+
// expect($location.getPath()).toBe("/c");
|
|
1799
|
+
// expect($location.getSearch()).toEqual({ d: "e" });
|
|
1800
|
+
// expect($location.getHash()).toBe("f");
|
|
1801
|
+
// expect($location.getState()).toEqual({ b: 4 });
|
|
1351
1802
|
// });
|
|
1352
1803
|
// });
|
|
1353
1804
|
|
|
@@ -1362,9 +1813,9 @@ describe("$location", () => {
|
|
|
1362
1813
|
// $window.history.pushState({}, null, "http://server/app/Home?q='");
|
|
1363
1814
|
// $rootScope.$digest();
|
|
1364
1815
|
|
|
1365
|
-
// expect($location.absUrl
|
|
1366
|
-
// expect($location.
|
|
1367
|
-
// expect($location.
|
|
1816
|
+
// expect($location.absUrl).toEqual("http://server/app/Home?q='");
|
|
1817
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
1818
|
+
// expect($location.getSearch()).toEqual({ q: "'" });
|
|
1368
1819
|
// });
|
|
1369
1820
|
// });
|
|
1370
1821
|
|
|
@@ -1379,9 +1830,9 @@ describe("$location", () => {
|
|
|
1379
1830
|
// $window.location.href = "http://server/app/Home?q='";
|
|
1380
1831
|
// ($window).triggerHandler("popstate");
|
|
1381
1832
|
|
|
1382
|
-
// expect($location.absUrl
|
|
1383
|
-
// expect($location.
|
|
1384
|
-
// expect($location.
|
|
1833
|
+
// expect($location.absUrl).toEqual("http://server/app/Home?q='");
|
|
1834
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
1835
|
+
// expect($location.getSearch()).toEqual({ q: "'" });
|
|
1385
1836
|
// });
|
|
1386
1837
|
// });
|
|
1387
1838
|
|
|
@@ -1393,7 +1844,7 @@ describe("$location", () => {
|
|
|
1393
1844
|
// $browser,
|
|
1394
1845
|
// "url",
|
|
1395
1846
|
// ).and.callThrough();
|
|
1396
|
-
// $location.
|
|
1847
|
+
// $location.setPath("/n/url").state({ a: 2 }).replace();
|
|
1397
1848
|
// $rootScope.$apply();
|
|
1398
1849
|
|
|
1399
1850
|
// expect($browserUrl).toHaveBeenCalled();
|
|
@@ -1417,11 +1868,11 @@ describe("$location", () => {
|
|
|
1417
1868
|
// "url",
|
|
1418
1869
|
// ).and.callThrough();
|
|
1419
1870
|
// $location
|
|
1420
|
-
// .
|
|
1871
|
+
// .setPath("/n/url")
|
|
1421
1872
|
// .state({ a: 2 })
|
|
1422
1873
|
// .replace()
|
|
1423
1874
|
// .state({ b: 3 })
|
|
1424
|
-
// .
|
|
1875
|
+
// .setPath("/o/url");
|
|
1425
1876
|
// $rootScope.$apply();
|
|
1426
1877
|
|
|
1427
1878
|
// expect($browserUrl).toHaveBeenCalled();
|
|
@@ -1444,7 +1895,7 @@ describe("$location", () => {
|
|
|
1444
1895
|
// $browser,
|
|
1445
1896
|
// "url",
|
|
1446
1897
|
// ).and.callThrough();
|
|
1447
|
-
// $location.
|
|
1898
|
+
// $location.setState({ a: 2 }).replace().state({ b: 3 });
|
|
1448
1899
|
// $rootScope.$apply();
|
|
1449
1900
|
|
|
1450
1901
|
// expect($browserUrl).toHaveBeenCalled();
|
|
@@ -1464,7 +1915,7 @@ describe("$location", () => {
|
|
|
1464
1915
|
|
|
1465
1916
|
// inject(($rootScope, $location) => {
|
|
1466
1917
|
// // init watches
|
|
1467
|
-
// $location.
|
|
1918
|
+
// $location.setUrl("/initUrl").state({ a: 2 });
|
|
1468
1919
|
// $rootScope.$apply();
|
|
1469
1920
|
|
|
1470
1921
|
// // changes url & state but resets them before digest
|
|
@@ -1478,7 +1929,7 @@ describe("$location", () => {
|
|
|
1478
1929
|
// expect($location.$$replace).toBe(false);
|
|
1479
1930
|
|
|
1480
1931
|
// // set the url to the old value
|
|
1481
|
-
// $location.
|
|
1932
|
+
// $location.setUrl("/newUrl").state({ a: 2 }).replace();
|
|
1482
1933
|
// $rootScope.$apply();
|
|
1483
1934
|
// expect($location.$$replace).toBe(false);
|
|
1484
1935
|
|
|
@@ -1495,7 +1946,7 @@ describe("$location", () => {
|
|
|
1495
1946
|
|
|
1496
1947
|
// inject(($rootScope, $location, $browser) => {
|
|
1497
1948
|
// const o = { a: 2 };
|
|
1498
|
-
// $location.
|
|
1949
|
+
// $location.setState(o);
|
|
1499
1950
|
// o.a = 3;
|
|
1500
1951
|
// $rootScope.$apply();
|
|
1501
1952
|
// expect($browser.state()).toEqual({ a: 3 });
|
|
@@ -1506,14 +1957,14 @@ describe("$location", () => {
|
|
|
1506
1957
|
// });
|
|
1507
1958
|
// });
|
|
1508
1959
|
|
|
1509
|
-
// it("should make $location.
|
|
1960
|
+
// it("should make $location.getState() referencially identical with $browser.state() after digest", () => {
|
|
1510
1961
|
// initService({ html5Mode: true, supportHistory: true });
|
|
1511
1962
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
|
|
1512
1963
|
|
|
1513
1964
|
// inject(($rootScope, $location, $browser) => {
|
|
1514
|
-
// $location.
|
|
1965
|
+
// $location.setState({ a: 2 });
|
|
1515
1966
|
// $rootScope.$apply();
|
|
1516
|
-
// expect($location.
|
|
1967
|
+
// expect($location.getState()).toBe($browser.state());
|
|
1517
1968
|
// });
|
|
1518
1969
|
// });
|
|
1519
1970
|
|
|
@@ -1522,9 +1973,9 @@ describe("$location", () => {
|
|
|
1522
1973
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
|
|
1523
1974
|
|
|
1524
1975
|
// inject(($rootScope, $location) => {
|
|
1525
|
-
// $location.
|
|
1976
|
+
// $location.setUrl("/foo").state({ a: 2 });
|
|
1526
1977
|
// $rootScope.$apply();
|
|
1527
|
-
// expect($location.
|
|
1978
|
+
// expect($location.getState()).toEqual({ a: 2 });
|
|
1528
1979
|
// });
|
|
1529
1980
|
// });
|
|
1530
1981
|
|
|
@@ -1533,14 +1984,14 @@ describe("$location", () => {
|
|
|
1533
1984
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
|
|
1534
1985
|
|
|
1535
1986
|
// inject(($rootScope, $location, $browser) => {
|
|
1536
|
-
// $location.
|
|
1987
|
+
// $location.setUrl("/foo").state({ a: 2 });
|
|
1537
1988
|
// $rootScope.$apply();
|
|
1538
1989
|
|
|
1539
1990
|
// const $browserUrl = spyOnlyCallsWithArgs(
|
|
1540
1991
|
// $browser,
|
|
1541
1992
|
// "url",
|
|
1542
1993
|
// ).and.callThrough();
|
|
1543
|
-
// $location.
|
|
1994
|
+
// $location.setUrl("/bar");
|
|
1544
1995
|
// $rootScope.$apply();
|
|
1545
1996
|
|
|
1546
1997
|
// expect($browserUrl).toHaveBeenCalled();
|
|
@@ -1579,8 +2030,8 @@ describe("$location", () => {
|
|
|
1579
2030
|
// });
|
|
1580
2031
|
// inject(($rootScope, $location, $browser) => {
|
|
1581
2032
|
// expect($browser.url()).toBe("http://domain.com/base/index.html#!/a/b");
|
|
1582
|
-
// $location.
|
|
1583
|
-
// $location.
|
|
2033
|
+
// $location.setPath("/new");
|
|
2034
|
+
// $location.setSearch({ a: true });
|
|
1584
2035
|
// $rootScope.$apply();
|
|
1585
2036
|
// expect($browser.url()).toBe(
|
|
1586
2037
|
// "http://domain.com/base/index.html#!/new?a",
|
|
@@ -1596,8 +2047,8 @@ describe("$location", () => {
|
|
|
1596
2047
|
// });
|
|
1597
2048
|
// inject(($rootScope, $location, $browser) => {
|
|
1598
2049
|
// expect($browser.url()).toBe("http://domain.com/base/index.html#/a/b");
|
|
1599
|
-
// $location.
|
|
1600
|
-
// $location.
|
|
2050
|
+
// $location.setPath("/new");
|
|
2051
|
+
// $location.setSearch({ a: true });
|
|
1601
2052
|
// $rootScope.$apply();
|
|
1602
2053
|
// expect($browser.url()).toBe("http://domain.com/base/index.html#/new?a");
|
|
1603
2054
|
// });
|
|
@@ -1618,8 +2069,8 @@ describe("$location", () => {
|
|
|
1618
2069
|
// expect($browser.url()).toBe(
|
|
1619
2070
|
// "http://domain.com/base/index.html#!!/a/b",
|
|
1620
2071
|
// );
|
|
1621
|
-
// $location.
|
|
1622
|
-
// $location.
|
|
2072
|
+
// $location.setPath("/new");
|
|
2073
|
+
// $location.setSearch({ a: true });
|
|
1623
2074
|
// $rootScope.$apply();
|
|
1624
2075
|
// expect($browser.url()).toBe(
|
|
1625
2076
|
// "http://domain.com/base/index.html#!!/new?a",
|
|
@@ -1670,8 +2121,8 @@ describe("$location", () => {
|
|
|
1670
2121
|
// });
|
|
1671
2122
|
// inject(($rootScope, $location, $browser) => {
|
|
1672
2123
|
// expect($browser.url()).toBe("http://domain.com/base/old/index.html#a");
|
|
1673
|
-
// $location.
|
|
1674
|
-
// $location.
|
|
2124
|
+
// $location.setPath("/new");
|
|
2125
|
+
// $location.setSearch({ a: true });
|
|
1675
2126
|
// $rootScope.$apply();
|
|
1676
2127
|
// expect($browser.url()).toBe("http://domain.com/base/new?a#a");
|
|
1677
2128
|
// });
|
|
@@ -1685,11 +2136,11 @@ describe("$location", () => {
|
|
|
1685
2136
|
// });
|
|
1686
2137
|
// inject(($rootScope, $location, $browser) => {
|
|
1687
2138
|
// expect($browser.url()).toBe("http://domain.com/base/a/b");
|
|
1688
|
-
// $location.
|
|
1689
|
-
// $location.
|
|
2139
|
+
// $location.setPath("/new");
|
|
2140
|
+
// $location.setHash("abc");
|
|
1690
2141
|
// $rootScope.$apply();
|
|
1691
2142
|
// expect($browser.url()).toBe("http://domain.com/base/new#abc");
|
|
1692
|
-
// expect($location.
|
|
2143
|
+
// expect($location.getPath()).toBe("/new");
|
|
1693
2144
|
// });
|
|
1694
2145
|
// });
|
|
1695
2146
|
|
|
@@ -1701,7 +2152,7 @@ describe("$location", () => {
|
|
|
1701
2152
|
// });
|
|
1702
2153
|
// inject(($rootScope, $location, $browser) => {
|
|
1703
2154
|
// expect($browser.url()).toBe("http://domain.com/base/a/b");
|
|
1704
|
-
// expect($location.
|
|
2155
|
+
// expect($location.getPath()).toBe("/a/b");
|
|
1705
2156
|
// });
|
|
1706
2157
|
// });
|
|
1707
2158
|
// });
|
|
@@ -1898,7 +2349,7 @@ describe("$location", () => {
|
|
|
1898
2349
|
// );
|
|
1899
2350
|
// });
|
|
1900
2351
|
|
|
1901
|
-
// it('should produce relative paths correctly when $location.
|
|
2352
|
+
// it('should produce relative paths correctly when $location.getPath() is "/" when history enabled on old browser', () => {
|
|
1902
2353
|
// configureTestLink({ linkHref: "partial1" });
|
|
1903
2354
|
// initService({ html5Mode: true, supportHistory: false, hashPrefix: "!" });
|
|
1904
2355
|
// inject(
|
|
@@ -1909,7 +2360,7 @@ describe("$location", () => {
|
|
|
1909
2360
|
// setupRewriteChecks(),
|
|
1910
2361
|
// ($browser, $location, $rootScope) => {
|
|
1911
2362
|
// $rootScope.$apply(() => {
|
|
1912
|
-
// $location.
|
|
2363
|
+
// $location.setPath("/");
|
|
1913
2364
|
// });
|
|
1914
2365
|
// browserTrigger(link, "click");
|
|
1915
2366
|
// expectRewriteTo(
|
|
@@ -2226,11 +2677,11 @@ describe("$location", () => {
|
|
|
2226
2677
|
// setupRewriteChecks(),
|
|
2227
2678
|
// ($browser, $location, $rootScope) => {
|
|
2228
2679
|
// $rootScope.$apply(() => {
|
|
2229
|
-
// $location.
|
|
2230
|
-
// $location.
|
|
2680
|
+
// $location.setPath("/some");
|
|
2681
|
+
// $location.setHash("foo");
|
|
2231
2682
|
// });
|
|
2232
2683
|
// browserTrigger(link, "click");
|
|
2233
|
-
// expect($location.
|
|
2684
|
+
// expect($location.getHash()).toBe("link");
|
|
2234
2685
|
// expectRewriteTo(
|
|
2235
2686
|
// $browser,
|
|
2236
2687
|
// "http://host.com/base/index.html#!/some#link",
|
|
@@ -2250,11 +2701,11 @@ describe("$location", () => {
|
|
|
2250
2701
|
// setupRewriteChecks(),
|
|
2251
2702
|
// ($browser, $location, $rootScope) => {
|
|
2252
2703
|
// $rootScope.$apply(() => {
|
|
2253
|
-
// $location.
|
|
2254
|
-
// $location.
|
|
2704
|
+
// $location.setPath("/some");
|
|
2705
|
+
// $location.setHash("foo");
|
|
2255
2706
|
// });
|
|
2256
2707
|
// browserTrigger(link, "click");
|
|
2257
|
-
// expect($location.
|
|
2708
|
+
// expect($location.getHash()).toBe("link");
|
|
2258
2709
|
// expectRewriteTo($browser, "http://host.com/base/some#link");
|
|
2259
2710
|
// },
|
|
2260
2711
|
// );
|
|
@@ -2566,9 +3017,9 @@ describe("$location", () => {
|
|
|
2566
3017
|
// $log.info("after", newUrl, oldUrl, $browser.url());
|
|
2567
3018
|
// });
|
|
2568
3019
|
|
|
2569
|
-
// expect($location.
|
|
2570
|
-
// $location.
|
|
2571
|
-
// expect($location.
|
|
3020
|
+
// expect($location.getUrl()).toEqual("");
|
|
3021
|
+
// $location.setUrl("/somePath");
|
|
3022
|
+
// expect($location.getUrl()).toEqual("/somePath");
|
|
2572
3023
|
// expect($browser.url()).toEqual("http://server/");
|
|
2573
3024
|
// expect($log.info.logs).toEqual([]);
|
|
2574
3025
|
|
|
@@ -2586,7 +3037,7 @@ describe("$location", () => {
|
|
|
2586
3037
|
// "http://server/",
|
|
2587
3038
|
// "http://server/#!/somePath",
|
|
2588
3039
|
// ]);
|
|
2589
|
-
// expect($location.
|
|
3040
|
+
// expect($location.getUrl()).toEqual("/somePath");
|
|
2590
3041
|
// expect($browser.url()).toEqual("http://server/#!/somePath");
|
|
2591
3042
|
// }));
|
|
2592
3043
|
|
|
@@ -2597,7 +3048,7 @@ describe("$location", () => {
|
|
|
2597
3048
|
// $log,
|
|
2598
3049
|
// ) => {
|
|
2599
3050
|
// expect($browser.url()).toEqual("http://server/");
|
|
2600
|
-
// expect($location.
|
|
3051
|
+
// expect($location.getUrl()).toEqual("");
|
|
2601
3052
|
|
|
2602
3053
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2603
3054
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
@@ -2607,9 +3058,9 @@ describe("$location", () => {
|
|
|
2607
3058
|
// throw new Error("location should have been canceled");
|
|
2608
3059
|
// });
|
|
2609
3060
|
|
|
2610
|
-
// expect($location.
|
|
2611
|
-
// $location.
|
|
2612
|
-
// expect($location.
|
|
3061
|
+
// expect($location.getUrl()).toEqual("");
|
|
3062
|
+
// $location.setUrl("/somePath");
|
|
3063
|
+
// expect($location.getUrl()).toEqual("/somePath");
|
|
2613
3064
|
// expect($browser.url()).toEqual("http://server/");
|
|
2614
3065
|
// expect($log.info.logs).toEqual([]);
|
|
2615
3066
|
|
|
@@ -2622,7 +3073,7 @@ describe("$location", () => {
|
|
|
2622
3073
|
// "http://server/",
|
|
2623
3074
|
// ]);
|
|
2624
3075
|
// expect($log.info.logs[1]).toBeUndefined();
|
|
2625
|
-
// expect($location.
|
|
3076
|
+
// expect($location.getUrl()).toEqual("");
|
|
2626
3077
|
// expect($browser.url()).toEqual("http://server/");
|
|
2627
3078
|
// }));
|
|
2628
3079
|
|
|
@@ -2635,14 +3086,14 @@ describe("$location", () => {
|
|
|
2635
3086
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2636
3087
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
2637
3088
|
// if (newUrl === "http://server/#!/somePath") {
|
|
2638
|
-
// $location.
|
|
3089
|
+
// $location.setUrl("/redirectPath");
|
|
2639
3090
|
// }
|
|
2640
3091
|
// });
|
|
2641
3092
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
2642
3093
|
// $log.info("after", newUrl, oldUrl, $browser.url());
|
|
2643
3094
|
// });
|
|
2644
3095
|
|
|
2645
|
-
// $location.
|
|
3096
|
+
// $location.setUrl("/somePath");
|
|
2646
3097
|
// $rootScope.$apply();
|
|
2647
3098
|
|
|
2648
3099
|
// expect($log.info.logs.shift()).toEqual([
|
|
@@ -2664,7 +3115,7 @@ describe("$location", () => {
|
|
|
2664
3115
|
// "http://server/#!/redirectPath",
|
|
2665
3116
|
// ]);
|
|
2666
3117
|
|
|
2667
|
-
// expect($location.
|
|
3118
|
+
// expect($location.getUrl()).toEqual("/redirectPath");
|
|
2668
3119
|
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
|
|
2669
3120
|
// }));
|
|
2670
3121
|
|
|
@@ -2678,14 +3129,14 @@ describe("$location", () => {
|
|
|
2678
3129
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
2679
3130
|
// if (newUrl === "http://server/#!/somePath") {
|
|
2680
3131
|
// event.preventDefault();
|
|
2681
|
-
// $location.
|
|
3132
|
+
// $location.setUrl("/redirectPath");
|
|
2682
3133
|
// }
|
|
2683
3134
|
// });
|
|
2684
3135
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
2685
3136
|
// $log.info("after", newUrl, oldUrl, $browser.url());
|
|
2686
3137
|
// });
|
|
2687
3138
|
|
|
2688
|
-
// $location.
|
|
3139
|
+
// $location.setUrl("/somePath");
|
|
2689
3140
|
// $rootScope.$apply();
|
|
2690
3141
|
|
|
2691
3142
|
// expect($log.info.logs.shift()).toEqual([
|
|
@@ -2707,7 +3158,7 @@ describe("$location", () => {
|
|
|
2707
3158
|
// "http://server/#!/redirectPath",
|
|
2708
3159
|
// ]);
|
|
2709
3160
|
|
|
2710
|
-
// expect($location.
|
|
3161
|
+
// expect($location.getUrl()).toEqual("/redirectPath");
|
|
2711
3162
|
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
|
|
2712
3163
|
// }));
|
|
2713
3164
|
|
|
@@ -2720,16 +3171,16 @@ describe("$location", () => {
|
|
|
2720
3171
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2721
3172
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
2722
3173
|
// if (newUrl === "http://server/#!/somePath") {
|
|
2723
|
-
// $location.
|
|
3174
|
+
// $location.setUrl("/redirectPath");
|
|
2724
3175
|
// } else if (newUrl === "http://server/#!/redirectPath") {
|
|
2725
|
-
// $location.
|
|
3176
|
+
// $location.setUrl("/redirectPath2");
|
|
2726
3177
|
// }
|
|
2727
3178
|
// });
|
|
2728
3179
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
2729
3180
|
// $log.info("after", newUrl, oldUrl, $browser.url());
|
|
2730
3181
|
// });
|
|
2731
3182
|
|
|
2732
|
-
// $location.
|
|
3183
|
+
// $location.setUrl("/somePath");
|
|
2733
3184
|
// $rootScope.$apply();
|
|
2734
3185
|
|
|
2735
3186
|
// expect($log.info.logs.shift()).toEqual([
|
|
@@ -2757,7 +3208,7 @@ describe("$location", () => {
|
|
|
2757
3208
|
// "http://server/#!/redirectPath2",
|
|
2758
3209
|
// ]);
|
|
2759
3210
|
|
|
2760
|
-
// expect($location.
|
|
3211
|
+
// expect($location.getUrl()).toEqual("/redirectPath2");
|
|
2761
3212
|
// expect($browser.url()).toEqual("http://server/#!/redirectPath2");
|
|
2762
3213
|
// }));
|
|
2763
3214
|
|
|
@@ -2770,7 +3221,7 @@ describe("$location", () => {
|
|
|
2770
3221
|
// $rootScope.$apply(); // clear initial $locationChangeStart
|
|
2771
3222
|
|
|
2772
3223
|
// expect($browser.url()).toEqual("http://server/");
|
|
2773
|
-
// expect($location.
|
|
3224
|
+
// expect($location.getUrl()).toEqual("");
|
|
2774
3225
|
|
|
2775
3226
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2776
3227
|
// $log.info("start", newUrl, oldUrl);
|
|
@@ -2800,11 +3251,11 @@ describe("$location", () => {
|
|
|
2800
3251
|
// $rootScope,
|
|
2801
3252
|
// $log,
|
|
2802
3253
|
// ) => {
|
|
2803
|
-
// $location.
|
|
3254
|
+
// $location.setUrl("/somepath");
|
|
2804
3255
|
// $rootScope.$apply();
|
|
2805
3256
|
|
|
2806
3257
|
// expect($browser.url()).toEqual("http://server/#!/somepath");
|
|
2807
|
-
// expect($location.
|
|
3258
|
+
// expect($location.getUrl()).toEqual("/somepath");
|
|
2808
3259
|
|
|
2809
3260
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2810
3261
|
// $log.info("start", newUrl, oldUrl);
|
|
@@ -2837,7 +3288,7 @@ describe("$location", () => {
|
|
|
2837
3288
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2838
3289
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
2839
3290
|
// if (newUrl === "http://server/#!/somePath") {
|
|
2840
|
-
// $location.
|
|
3291
|
+
// $location.setUrl("/redirectPath");
|
|
2841
3292
|
// }
|
|
2842
3293
|
// });
|
|
2843
3294
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
@@ -2866,7 +3317,7 @@ describe("$location", () => {
|
|
|
2866
3317
|
// "http://server/#!/redirectPath",
|
|
2867
3318
|
// ]);
|
|
2868
3319
|
|
|
2869
|
-
// expect($location.
|
|
3320
|
+
// expect($location.getUrl()).toEqual("/redirectPath");
|
|
2870
3321
|
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
|
|
2871
3322
|
// }));
|
|
2872
3323
|
|
|
@@ -2880,7 +3331,7 @@ describe("$location", () => {
|
|
|
2880
3331
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
2881
3332
|
// if (newUrl === "http://server/#!/somePath") {
|
|
2882
3333
|
// event.preventDefault();
|
|
2883
|
-
// $location.
|
|
3334
|
+
// $location.setUrl("/redirectPath");
|
|
2884
3335
|
// }
|
|
2885
3336
|
// });
|
|
2886
3337
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
@@ -2909,7 +3360,7 @@ describe("$location", () => {
|
|
|
2909
3360
|
// "http://server/#!/redirectPath",
|
|
2910
3361
|
// ]);
|
|
2911
3362
|
|
|
2912
|
-
// expect($location.
|
|
3363
|
+
// expect($location.getUrl()).toEqual("/redirectPath");
|
|
2913
3364
|
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
|
|
2914
3365
|
// }));
|
|
2915
3366
|
|
|
@@ -2985,17 +3436,17 @@ describe("$location", () => {
|
|
|
2985
3436
|
// const base = $browser.url();
|
|
2986
3437
|
|
|
2987
3438
|
// $rootScope.$on("$locationChangeStart", () => {
|
|
2988
|
-
// log($location.
|
|
3439
|
+
// log($location.getPath());
|
|
2989
3440
|
// });
|
|
2990
3441
|
|
|
2991
3442
|
// // change through $location service
|
|
2992
3443
|
// $rootScope.$apply(() => {
|
|
2993
|
-
// $location.
|
|
3444
|
+
// $location.setPath("/myNewPath");
|
|
2994
3445
|
// });
|
|
2995
3446
|
|
|
2996
3447
|
// // reset location
|
|
2997
3448
|
// $rootScope.$apply(() => {
|
|
2998
|
-
// $location.
|
|
3449
|
+
// $location.setPath("");
|
|
2999
3450
|
// });
|
|
3000
3451
|
|
|
3001
3452
|
// // change through $browser
|
|
@@ -3007,100 +3458,32 @@ describe("$location", () => {
|
|
|
3007
3458
|
// });
|
|
3008
3459
|
|
|
3009
3460
|
describe("$locationProvider", () => {
|
|
3010
|
-
describe("
|
|
3011
|
-
it("should
|
|
3461
|
+
describe("html5ModeConf", () => {
|
|
3462
|
+
it("should have default values", () => {
|
|
3012
3463
|
module.config(($locationProvider) => {
|
|
3013
|
-
$locationProvider.
|
|
3464
|
+
expect($locationProvider.html5ModeConf).toEqual({
|
|
3014
3465
|
enabled: true,
|
|
3015
3466
|
requireBase: false,
|
|
3016
|
-
rewriteLinks: false,
|
|
3017
|
-
});
|
|
3018
|
-
expect($locationProvider.getHtml5Mode()).toEqual({
|
|
3019
|
-
enabled: true,
|
|
3020
|
-
requireBase: false,
|
|
3021
|
-
rewriteLinks: false,
|
|
3022
|
-
});
|
|
3023
|
-
});
|
|
3024
|
-
createInjector(["test1"]);
|
|
3025
|
-
});
|
|
3026
|
-
|
|
3027
|
-
it("should only overwrite existing properties if values are of the correct type", () => {
|
|
3028
|
-
module.config(($locationProvider) => {
|
|
3029
|
-
$locationProvider.setHtml5Mode({
|
|
3030
|
-
enabled: "duh",
|
|
3031
|
-
requireBase: "probably",
|
|
3032
|
-
rewriteLinks: 0,
|
|
3033
|
-
});
|
|
3034
|
-
|
|
3035
|
-
expect($locationProvider.getHtml5Mode()).toEqual({
|
|
3036
|
-
enabled: false,
|
|
3037
|
-
requireBase: true,
|
|
3038
|
-
rewriteLinks: true,
|
|
3039
|
-
});
|
|
3040
|
-
});
|
|
3041
|
-
|
|
3042
|
-
createInjector(["test1"]);
|
|
3043
|
-
});
|
|
3044
|
-
|
|
3045
|
-
it("should support setting rewriteLinks to a string", () => {
|
|
3046
|
-
module.config(($locationProvider) => {
|
|
3047
|
-
$locationProvider.setHtml5Mode({
|
|
3048
|
-
rewriteLinks: "yes-rewrite",
|
|
3049
|
-
});
|
|
3050
|
-
|
|
3051
|
-
expect($locationProvider.getHtml5Mode().rewriteLinks).toEqual(
|
|
3052
|
-
"yes-rewrite",
|
|
3053
|
-
);
|
|
3054
|
-
});
|
|
3055
|
-
|
|
3056
|
-
createInjector(["test1"]);
|
|
3057
|
-
});
|
|
3058
|
-
|
|
3059
|
-
it("should not set unknown input properties to html5Mode object", () => {
|
|
3060
|
-
module.config(($locationProvider) => {
|
|
3061
|
-
$locationProvider.setHtml5Mode({
|
|
3062
|
-
someProp: "foo",
|
|
3063
|
-
});
|
|
3064
|
-
|
|
3065
|
-
expect($locationProvider.getHtml5Mode()).toEqual({
|
|
3066
|
-
enabled: false,
|
|
3067
|
-
requireBase: true,
|
|
3068
3467
|
rewriteLinks: true,
|
|
3069
3468
|
});
|
|
3070
3469
|
});
|
|
3071
|
-
|
|
3072
|
-
createInjector(["test1"]);
|
|
3073
|
-
});
|
|
3074
|
-
|
|
3075
|
-
it("should default to enabled:false, requireBase:true and rewriteLinks:true", () => {
|
|
3076
|
-
module.config(($locationProvider) => {
|
|
3077
|
-
expect($locationProvider.getHtml5Mode()).toEqual({
|
|
3078
|
-
enabled: false,
|
|
3079
|
-
requireBase: true,
|
|
3080
|
-
rewriteLinks: true,
|
|
3081
|
-
});
|
|
3082
|
-
});
|
|
3083
|
-
|
|
3084
3470
|
createInjector(["test1"]);
|
|
3085
3471
|
});
|
|
3086
3472
|
});
|
|
3087
3473
|
});
|
|
3088
3474
|
|
|
3089
|
-
describe("
|
|
3475
|
+
describe("Location with html5 url", () => {
|
|
3090
3476
|
let locationUrl;
|
|
3091
3477
|
let locationUmlautUrl;
|
|
3092
3478
|
let locationIndexUrl;
|
|
3093
3479
|
|
|
3094
3480
|
beforeEach(() => {
|
|
3095
|
-
locationUrl = new
|
|
3096
|
-
|
|
3097
|
-
"http://server/pre/",
|
|
3098
|
-
);
|
|
3099
|
-
locationUmlautUrl = new LocationHtml5Url(
|
|
3481
|
+
locationUrl = new Location("http://server/pre/", "http://server/pre/");
|
|
3482
|
+
locationUmlautUrl = new Location(
|
|
3100
3483
|
"http://särver/pre/",
|
|
3101
3484
|
"http://särver/pre/",
|
|
3102
3485
|
);
|
|
3103
|
-
locationIndexUrl = new
|
|
3486
|
+
locationIndexUrl = new Location(
|
|
3104
3487
|
"http://server/pre/index.html",
|
|
3105
3488
|
"http://server/pre/",
|
|
3106
3489
|
);
|
|
@@ -3209,17 +3592,18 @@ describe("$location", () => {
|
|
|
3209
3592
|
// });
|
|
3210
3593
|
|
|
3211
3594
|
it("should support state", () => {
|
|
3212
|
-
expect(locationUrl.
|
|
3595
|
+
expect(locationUrl.setState({ a: 2 }).getState()).toEqual({ a: 2 });
|
|
3213
3596
|
});
|
|
3214
3597
|
});
|
|
3215
3598
|
|
|
3216
|
-
describe("
|
|
3599
|
+
describe("Location with hashbang url", () => {
|
|
3217
3600
|
let locationUrl;
|
|
3218
3601
|
|
|
3219
3602
|
it("should rewrite URL", () => {
|
|
3220
|
-
locationUrl = new
|
|
3603
|
+
locationUrl = new Location(
|
|
3221
3604
|
"http://server/pre/",
|
|
3222
3605
|
"http://server/pre/",
|
|
3606
|
+
false,
|
|
3223
3607
|
"#",
|
|
3224
3608
|
);
|
|
3225
3609
|
|
|
@@ -3239,73 +3623,74 @@ describe("$location", () => {
|
|
|
3239
3623
|
});
|
|
3240
3624
|
|
|
3241
3625
|
it("should not set hash if one was not originally specified", () => {
|
|
3242
|
-
locationUrl = new
|
|
3626
|
+
locationUrl = new Location(
|
|
3243
3627
|
"http://server/pre/index.html",
|
|
3244
3628
|
"http://server/pre/",
|
|
3629
|
+
false,
|
|
3245
3630
|
"#",
|
|
3246
3631
|
);
|
|
3247
3632
|
|
|
3248
|
-
locationUrl
|
|
3249
|
-
expect(locationUrl.
|
|
3250
|
-
expect(locationUrl.absUrl
|
|
3633
|
+
locationUrl.parse("http://server/pre/index.html");
|
|
3634
|
+
expect(locationUrl.getUrl()).toBe("");
|
|
3635
|
+
expect(locationUrl.absUrl).toBe("http://server/pre/index.html");
|
|
3251
3636
|
});
|
|
3252
3637
|
|
|
3253
3638
|
it("should parse hash if one was specified", () => {
|
|
3254
|
-
locationUrl = new
|
|
3639
|
+
locationUrl = new Location(
|
|
3255
3640
|
"http://server/pre/index.html",
|
|
3256
3641
|
"http://server/pre/",
|
|
3642
|
+
false,
|
|
3257
3643
|
"#",
|
|
3258
3644
|
);
|
|
3259
3645
|
|
|
3260
|
-
locationUrl
|
|
3261
|
-
expect(locationUrl.
|
|
3262
|
-
expect(locationUrl.absUrl
|
|
3263
|
-
"http://server/pre/index.html#/foo/bar",
|
|
3264
|
-
);
|
|
3646
|
+
locationUrl.parse("http://server/pre/index.html#/foo/bar");
|
|
3647
|
+
expect(locationUrl.getUrl()).toBe("/foo/bar");
|
|
3648
|
+
expect(locationUrl.absUrl).toBe("http://server/pre/index.html#/foo/bar");
|
|
3265
3649
|
});
|
|
3266
3650
|
|
|
3267
3651
|
it("should prefix hash url with / if one was originally missing", () => {
|
|
3268
|
-
locationUrl = new
|
|
3652
|
+
locationUrl = new Location(
|
|
3269
3653
|
"http://server/pre/index.html",
|
|
3270
3654
|
"http://server/pre/",
|
|
3655
|
+
false,
|
|
3271
3656
|
"#",
|
|
3272
3657
|
);
|
|
3273
3658
|
|
|
3274
|
-
locationUrl
|
|
3275
|
-
|
|
3276
|
-
)
|
|
3277
|
-
expect(locationUrl.url()).toBe("/not-starting-with-slash");
|
|
3278
|
-
expect(locationUrl.absUrl()).toBe(
|
|
3659
|
+
locationUrl.parse("http://server/pre/index.html#not-starting-with-slash");
|
|
3660
|
+
expect(locationUrl.getUrl()).toBe("/not-starting-with-slash");
|
|
3661
|
+
expect(locationUrl.absUrl).toBe(
|
|
3279
3662
|
"http://server/pre/index.html#/not-starting-with-slash",
|
|
3280
3663
|
);
|
|
3281
3664
|
});
|
|
3282
3665
|
|
|
3283
3666
|
it("should not strip stuff from path just because it looks like Windows drive when it's not", () => {
|
|
3284
|
-
locationUrl = new
|
|
3667
|
+
locationUrl = new Location(
|
|
3285
3668
|
"http://server/pre/index.html",
|
|
3286
3669
|
"http://server/pre/",
|
|
3670
|
+
false,
|
|
3287
3671
|
"#",
|
|
3288
3672
|
);
|
|
3289
3673
|
|
|
3290
|
-
locationUrl
|
|
3674
|
+
locationUrl.parse(
|
|
3291
3675
|
"http://server/pre/index.html#http%3A%2F%2Fexample.com%2F",
|
|
3292
3676
|
);
|
|
3293
|
-
expect(locationUrl.
|
|
3294
|
-
expect(locationUrl.absUrl
|
|
3677
|
+
expect(locationUrl.getUrl()).toBe("/http://example.com/");
|
|
3678
|
+
expect(locationUrl.absUrl).toBe(
|
|
3295
3679
|
"http://server/pre/index.html#/http://example.com/",
|
|
3296
3680
|
);
|
|
3297
3681
|
});
|
|
3298
3682
|
|
|
3299
3683
|
it("should allow navigating outside the original base URL", () => {
|
|
3300
|
-
locationUrl = new
|
|
3684
|
+
locationUrl = new Location(
|
|
3301
3685
|
"http://server/pre/index.html",
|
|
3302
3686
|
"http://server/pre/",
|
|
3687
|
+
false,
|
|
3303
3688
|
"#",
|
|
3304
3689
|
);
|
|
3305
3690
|
|
|
3306
|
-
locationUrl
|
|
3307
|
-
expect(locationUrl.
|
|
3308
|
-
expect(locationUrl.absUrl
|
|
3691
|
+
locationUrl.parse("http://server/next/index.html");
|
|
3692
|
+
expect(locationUrl.getUrl()).toBe("");
|
|
3693
|
+
expect(locationUrl.absUrl).toBe("http://server/next/index.html");
|
|
3309
3694
|
});
|
|
3310
3695
|
});
|
|
3311
3696
|
|
|
@@ -3315,7 +3700,7 @@ describe("$location", () => {
|
|
|
3315
3700
|
// const parser = document.createElement("a");
|
|
3316
3701
|
// parser.href = options.initialUrl;
|
|
3317
3702
|
|
|
3318
|
-
// $windowProvider.$get =
|
|
3703
|
+
// $windowProvider.$get = () => {
|
|
3319
3704
|
// const win = {};
|
|
3320
3705
|
// angular.extend(win, window);
|
|
3321
3706
|
// // Ensure `window` is a reference to the mock global object, so that
|
|
@@ -3377,7 +3762,7 @@ describe("$location", () => {
|
|
|
3377
3762
|
// $sniffer,
|
|
3378
3763
|
// $$taskTrackerFactory,
|
|
3379
3764
|
// );
|
|
3380
|
-
// browser.baseHref =
|
|
3765
|
+
// browser.baseHref = () => {
|
|
3381
3766
|
// return options.baseHref;
|
|
3382
3767
|
// };
|
|
3383
3768
|
// return browser;
|
|
@@ -3399,8 +3784,8 @@ describe("$location", () => {
|
|
|
3399
3784
|
}
|
|
3400
3785
|
|
|
3401
3786
|
function parseLinkAndReturn(location, url, relHref) {
|
|
3402
|
-
if (location
|
|
3403
|
-
return location.absUrl
|
|
3787
|
+
if (location.parseLinkUrl(url, relHref)) {
|
|
3788
|
+
return location.absUrl;
|
|
3404
3789
|
}
|
|
3405
3790
|
return undefined;
|
|
3406
3791
|
}
|