@angular-wave/angular.ts 0.7.7 → 0.8.0
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/animations/raf-scheduler.d.ts +2 -2
- package/@types/animations/shared.d.ts +0 -1
- package/@types/core/compile/attributes.d.ts +3 -3
- package/@types/core/compile/compile.d.ts +1 -1
- package/@types/core/di/injector.d.ts +0 -1
- package/@types/core/di/internal-injector.d.ts +1 -0
- package/@types/core/di/ng-module.d.ts +5 -0
- package/@types/core/filter/filter.d.ts +11 -13
- package/@types/core/parse/parse.d.ts +6 -7
- package/@types/core/sanitize/sanitize-uri.d.ts +3 -6
- package/@types/core/scope/scope.d.ts +1 -1
- package/@types/directive/attrs/attrs.d.ts +7 -1
- package/@types/directive/bind/bind.d.ts +2 -1
- package/@types/directive/events/events.d.ts +9 -3
- package/@types/directive/http/http.d.ts +6 -2
- package/@types/directive/include/include.d.ts +2 -2
- package/@types/directive/input/input.d.ts +2 -12
- package/@types/directive/messages/messages.d.ts +9 -48
- package/@types/directive/model/model.d.ts +3 -3
- package/@types/directive/options/options.d.ts +13 -20
- package/@types/directive/switch/switch.d.ts +1 -0
- package/@types/directive/transclude/transclude.d.ts +10 -6
- package/@types/index.d.ts +1 -1
- package/@types/interface.d.ts +56 -18
- package/@types/{public.d.ts → ng.d.ts} +2 -2
- package/@types/router/directives/view-directive.d.ts +2 -19
- package/@types/router/{common → glob}/glob.d.ts +5 -1
- package/@types/router/globals.d.ts +2 -3
- package/@types/router/path/path-utils.d.ts +8 -11
- 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 +1 -2
- package/@types/router/state/state-service.d.ts +8 -7
- package/@types/router/state-filters.d.ts +24 -2
- package/@types/router/transition/transition.d.ts +12 -15
- package/@types/router/url/url-matcher.d.ts +3 -3
- package/@types/router/url/url-rule.d.ts +1 -0
- package/@types/router/url/url-rules.d.ts +26 -6
- package/@types/router/url/url-service.d.ts +30 -42
- package/@types/services/anchor-scroll.d.ts +1 -1
- package/@types/{core → services/exception}/exception-handler.d.ts +4 -4
- package/@types/{core/error-handler.d.ts → services/exception/interface.d.ts} +1 -1
- package/@types/services/http/http.d.ts +48 -3
- package/@types/services/http/interface.d.ts +2 -2
- package/@types/services/http-backend/http-backend.d.ts +49 -44
- package/@types/services/location/interface.d.ts +63 -0
- package/@types/services/location/location.d.ts +330 -0
- package/@types/{core → services}/sce/sce.d.ts +1 -1
- package/@types/services/template-cache/interface.d.ts +8 -2
- package/@types/services/template-cache/template-cache.d.ts +1 -1
- package/@types/services/template-request.d.ts +1 -1
- package/@types/shared/cache.d.ts +0 -2
- package/@types/shared/common.d.ts +0 -2
- package/@types/shared/dom.d.ts +6 -0
- package/@types/shared/interface.d.ts +0 -4
- package/@types/{router/common → shared}/queue.d.ts +2 -2
- package/@types/shared/test-utils.d.ts +1 -0
- package/@types/shared/url-utils/interface.d.ts +46 -0
- package/@types/shared/url-utils/url-utils.d.ts +64 -0
- package/@types/shared/utils.d.ts +44 -6
- package/Makefile +8 -4
- package/dist/angular-ts.esm.js +1889 -2199
- package/dist/angular-ts.umd.js +1889 -2199
- 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 +10 -8
- 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 +203 -0
- 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 +66 -1
- package/docs/content/docs/service/location.md +57 -0
- package/docs/content/docs/service/templateCache.md +2 -2
- package/docs/content/docs/service/url.md +5 -0
- package/docs/layouts/partials/hooks/head-end.html +1 -1
- package/docs/layouts/shortcodes/showcss.html +2 -0
- 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-bind/ng-bind.html +2 -2
- 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 +32 -0
- package/docs/static/typedoc/classes/TemplateCacheProvider.html +1 -1
- package/docs/static/typedoc/hierarchy.html +1 -1
- package/docs/static/typedoc/index.html +1 -1
- package/docs/static/typedoc/interfaces/DefaultPorts.html +5 -0
- package/docs/static/typedoc/interfaces/Directive.html +5 -4
- package/docs/static/typedoc/interfaces/Html5Mode.html +23 -0
- package/docs/static/typedoc/interfaces/HttpProviderDefaults.html +1 -1
- package/docs/static/typedoc/interfaces/HttpResponse.html +2 -3
- package/docs/static/typedoc/interfaces/Provider.html +16 -10
- package/docs/static/typedoc/interfaces/RequestConfig.html +1 -1
- package/docs/static/typedoc/interfaces/RequestShortcutConfig.html +1 -1
- package/docs/static/typedoc/interfaces/TemplateCache.html +7 -0
- package/docs/static/typedoc/interfaces/UrlParts.html +9 -0
- package/docs/static/typedoc/types/AnnotatedDirectiveFactory.html +1 -0
- package/docs/static/typedoc/types/AnnotatedFactory.html +1 -1
- package/docs/static/typedoc/types/DirectiveFactory.html +1 -2
- package/docs/static/typedoc/types/DirectiveFactoryFn.html +1 -0
- package/docs/static/typedoc/types/Expression.html +1 -1
- package/docs/static/typedoc/types/HttpResponseStatus.html +1 -0
- package/docs/static/typedoc/types/{TemplateCache.html → SwapModeType.html} +1 -1
- package/docs/static/typedoc/types/UrlChangeListener.html +5 -0
- package/docs/static/typedoc/variables/SwapMode.html +11 -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/legacy.d.ts +0 -10
- package/package.json +1 -3
- package/src/{loader.js → angular.js} +5 -10
- package/src/angular.spec.js +189 -21
- package/src/animations/animate-children-directive.js +2 -2
- package/src/animations/animate-css.js +17 -18
- package/src/animations/animate.spec.js +1 -1
- package/src/animations/raf-scheduler.js +1 -1
- package/src/animations/shared.js +2 -12
- package/src/binding.spec.js +1 -1
- package/src/core/compile/attributes.js +1 -1
- package/src/core/compile/compile.js +7 -10
- 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 +11 -25
- 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 +7 -7
- package/src/core/di/ng-module.js +12 -27
- package/src/core/filter/filter.js +28 -28
- 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/interpreter.js +32 -38
- 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 +17 -16
- package/src/core/prop.spec.js +1 -1
- package/src/core/root-element.spec.js +1 -1
- package/src/core/sanitize/sanitize-uri.js +3 -3
- package/src/core/scope/scope.js +12 -13
- 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.js +7 -4
- 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 +1 -1
- package/src/directive/events/events.js +6 -2
- 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 +3 -1
- package/src/directive/http/form-test.html +18 -0
- package/src/directive/http/get.spec.js +281 -4
- package/src/directive/http/http.js +112 -15
- package/src/directive/http/http.test.js +2 -2
- package/src/directive/http/post.spec.js +506 -9
- package/src/directive/http/put.spec.js +3 -1
- package/src/directive/if/if.spec.js +1 -1
- package/src/directive/include/include.js +7 -7
- 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 +19 -43
- package/src/directive/input/input.spec.js +1 -2
- package/src/directive/input/input.test.js +1 -0
- package/src/directive/messages/messages.js +4 -0
- package/src/directive/messages/messages.spec.js +1 -1
- package/src/directive/messages/messages.test.js +1 -0
- package/src/directive/model/model.js +14 -14
- 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.js +454 -464
- 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.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.js +12 -14
- package/src/directive/setter/setter.spec.js +40 -17
- 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.js +1 -0
- package/src/directive/switch/switch.spec.js +1 -1
- package/src/directive/switch/switch.test.js +1 -0
- package/src/directive/transclude/transclude.js +87 -89
- 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 +6 -2
- package/src/interface.ts +70 -19
- package/src/loader.md +0 -155
- package/src/{public.js → ng.js} +16 -23
- package/src/{public.spec.js → ng.spec.js} +1 -1
- package/src/router/directives/state-directives.spec.js +9 -8
- package/src/router/directives/view-directive.js +11 -9
- package/src/router/directives/view-directive.spec.js +8 -9
- package/src/router/{common/common.html → glob/glob.html} +2 -3
- package/src/router/{common → glob}/glob.js +5 -0
- package/src/router/{common/common.test.js → glob/glob.test.js} +2 -1
- package/src/router/globals.js +1 -2
- package/src/router/path/path-utils.js +5 -0
- package/src/router/router-test-hashbang.html +45 -0
- package/src/router/services.spec.js +5 -6
- 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 +2 -3
- package/src/router/state/state-service.js +13 -10
- 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 +15 -11
- package/src/router/template-factory.js +5 -4
- package/src/router/template-factory.spec.js +1 -1
- package/src/router/transition/hook-registry.js +1 -1
- package/src/router/transition/transition-service.js +6 -5
- package/src/router/transition/transition.js +4 -4
- package/src/router/url/url-matcher.js +3 -3
- package/src/router/url/url-rule.js +1 -0
- package/src/router/url/url-rules.js +8 -5
- package/src/router/url/url-service.js +82 -85
- package/src/router/url/url-service.spec.js +55 -39
- 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.spec.js +1 -1
- package/src/services/anchor-scroll.html +2 -9
- package/src/services/anchor-scroll.js +6 -5
- package/src/{core → services/exception}/exception-handler.js +2 -2
- package/src/{core/error-handler.ts → services/exception/interface.ts} +1 -1
- package/src/services/http/http.js +11 -17
- package/src/services/http/http.spec.js +2 -7
- package/src/services/http/interface.ts +2 -2
- package/src/services/http/template-request.spec.js +1 -1
- package/src/services/http-backend/http-backend.js +53 -89
- package/src/services/http-backend/http-backend.spec.js +2 -6
- package/src/services/http-backend/http-backend.test.js +1 -0
- package/src/services/location/interface.ts +70 -0
- package/src/{core → services}/location/location.html +4 -1
- package/src/services/location/location.js +999 -0
- package/src/{core → services}/location/location.spec.js +911 -532
- package/src/{core → 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/{core → services}/sce/sce.html +1 -1
- package/src/{core → services}/sce/sce.js +14 -10
- package/src/{core → services}/sce/sce.md +2 -2
- package/src/{core → services}/sce/sce.spec.js +3 -4
- package/src/{core → services}/sce/sce.test.js +1 -1
- package/src/services/template-cache/interface.ts +8 -2
- package/src/services/template-cache/template-cache.js +3 -1
- package/src/services/template-cache/template-cache.spec.js +73 -1
- package/src/services/template-cache/template-cache.test.js +1 -0
- package/src/services/template-request.js +2 -1
- package/src/shared/cache.js +0 -2
- package/src/shared/common.js +0 -5
- package/src/shared/common.spec.js +1 -1
- package/src/shared/dom.js +10 -0
- 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/test-utils.js +1 -0
- package/src/shared/url-utils/interface.ts +54 -0
- package/src/{core → shared}/url-utils/url-utils.html +4 -1
- package/src/{core → shared}/url-utils/url-utils.js +26 -47
- package/src/{core → shared}/url-utils/url-utils.spec.js +10 -17
- package/src/{core → shared}/url-utils/url-utils.test.js +1 -1
- package/src/shared/utils.js +60 -9
- package/src/shared/utils.spec.js +35 -1
- package/src/src.html +1 -2
- package/typedoc.json +0 -1
- package/utils/express.js +36 -2
- package/utils/version.cjs +23 -0
- package/@types/core/location/location.d.ts +0 -317
- package/@types/core/task-tracker-factory.d.ts +0 -76
- package/@types/core/url-utils/url-utils.d.ts +0 -56
- package/@types/router/state-provider.d.ts +0 -123
- package/@types/services/browser.d.ts +0 -101
- package/docs/static/typedoc/types/SwapInsertPosition.html +0 -2
- package/jsdoc.json +0 -22
- package/src/core/location/location.js +0 -984
- package/src/core/location/location.md +0 -114
- package/src/core/task-tracker-factory.js +0 -145
- package/src/core/url-utils/url-utils.md +0 -46
- 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/browser.js +0 -212
- /package/@types/{loader.d.ts → angular.d.ts} +0 -0
- /package/src/router/{common → glob}/glob.spec.js +0 -0
- /package/src/{router/common → shared}/queue.spec.js +0 -0
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
decodePath,
|
|
3
|
+
encodePath,
|
|
4
|
+
normalizePath,
|
|
5
|
+
Location,
|
|
4
6
|
LocationProvider,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
parseAppUrl,
|
|
8
|
+
stripBaseUrl,
|
|
9
|
+
stripHash,
|
|
10
|
+
stripFile,
|
|
11
|
+
serverBase,
|
|
12
|
+
urlsEqual,
|
|
13
|
+
} from "./location.js";
|
|
14
|
+
import { Angular } from "../../angular.js";
|
|
15
|
+
import { createInjector } from "../../core/di/injector.js";
|
|
8
16
|
|
|
9
17
|
describe("$location", () => {
|
|
10
18
|
let module;
|
|
@@ -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,800 @@ 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" });
|
|
540
531
|
});
|
|
541
532
|
});
|
|
542
533
|
});
|
|
543
534
|
|
|
544
535
|
describe("HashbangUrl", () => {
|
|
545
536
|
function createHashbangUrl() {
|
|
546
|
-
const locationUrl = new
|
|
537
|
+
const locationUrl = new Location(
|
|
547
538
|
"http://www.server.org:1234/base",
|
|
548
539
|
"http://www.server.org:1234/",
|
|
540
|
+
false,
|
|
549
541
|
"#!",
|
|
550
542
|
);
|
|
551
|
-
locationUrl
|
|
543
|
+
locationUrl.parse("http://www.server.org:1234/base#!/path?a=b&c#hash");
|
|
552
544
|
return locationUrl;
|
|
553
545
|
}
|
|
554
546
|
|
|
555
547
|
it("should parse hashbang url into path and search", () => {
|
|
556
548
|
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");
|
|
549
|
+
expect(locationUrl.getPath()).toBe("/path");
|
|
550
|
+
expect(locationUrl.getSearch()).toEqual({ a: "b", c: true });
|
|
551
|
+
expect(locationUrl.getHash()).toBe("hash");
|
|
563
552
|
});
|
|
564
553
|
|
|
565
|
-
it("absUrl
|
|
554
|
+
it("absUrl should return hashbang url", () => {
|
|
566
555
|
const locationUrl = createHashbangUrl();
|
|
567
|
-
expect(locationUrl.absUrl
|
|
556
|
+
expect(locationUrl.absUrl).toBe(
|
|
568
557
|
"http://www.server.org:1234/base#!/path?a=b&c#hash",
|
|
569
558
|
);
|
|
570
559
|
|
|
571
|
-
locationUrl.
|
|
572
|
-
locationUrl.
|
|
573
|
-
locationUrl.
|
|
574
|
-
expect(locationUrl.absUrl
|
|
560
|
+
locationUrl.setPath("/new/path");
|
|
561
|
+
locationUrl.setSearch({ one: 1 });
|
|
562
|
+
locationUrl.setHash("hhh");
|
|
563
|
+
expect(locationUrl.absUrl).toBe(
|
|
575
564
|
"http://www.server.org:1234/base#!/new/path?one=1#hhh",
|
|
576
565
|
);
|
|
577
566
|
});
|
|
578
567
|
|
|
579
568
|
it("should preserve query params in base", () => {
|
|
580
|
-
const locationUrl = new
|
|
569
|
+
const locationUrl = new Location(
|
|
581
570
|
"http://www.server.org:1234/base?base=param",
|
|
582
571
|
"http://www.server.org:1234/",
|
|
572
|
+
false,
|
|
583
573
|
"#",
|
|
584
574
|
);
|
|
585
|
-
locationUrl
|
|
575
|
+
locationUrl.parse(
|
|
586
576
|
"http://www.server.org:1234/base?base=param#/path?a=b&c#hash",
|
|
587
577
|
);
|
|
588
|
-
expect(locationUrl.absUrl
|
|
578
|
+
expect(locationUrl.absUrl).toBe(
|
|
589
579
|
"http://www.server.org:1234/base?base=param#/path?a=b&c#hash",
|
|
590
580
|
);
|
|
591
581
|
|
|
592
|
-
locationUrl.
|
|
593
|
-
locationUrl.
|
|
594
|
-
locationUrl.
|
|
595
|
-
expect(locationUrl.absUrl
|
|
582
|
+
locationUrl.setPath("/new/path");
|
|
583
|
+
locationUrl.setSearch({ one: 1 });
|
|
584
|
+
locationUrl.setHash("hhh");
|
|
585
|
+
expect(locationUrl.absUrl).toBe(
|
|
596
586
|
"http://www.server.org:1234/base?base=param#/new/path?one=1#hhh",
|
|
597
587
|
);
|
|
598
588
|
});
|
|
599
589
|
|
|
600
590
|
it("should prefix path with forward-slash", () => {
|
|
601
|
-
const locationUrl = new
|
|
591
|
+
const locationUrl = new Location(
|
|
602
592
|
"http://host.com/base",
|
|
603
593
|
"http://host.com/",
|
|
594
|
+
false,
|
|
604
595
|
"#",
|
|
605
596
|
);
|
|
606
|
-
locationUrl
|
|
607
|
-
expect(locationUrl.
|
|
608
|
-
expect(locationUrl.absUrl
|
|
597
|
+
locationUrl.parse("http://host.com/base#path");
|
|
598
|
+
expect(locationUrl.getPath()).toBe("/path");
|
|
599
|
+
expect(locationUrl.absUrl).toBe("http://host.com/base#/path");
|
|
609
600
|
|
|
610
|
-
locationUrl.
|
|
611
|
-
expect(locationUrl.
|
|
612
|
-
expect(locationUrl.absUrl
|
|
601
|
+
locationUrl.setPath("wrong");
|
|
602
|
+
expect(locationUrl.getPath()).toBe("/wrong");
|
|
603
|
+
expect(locationUrl.absUrl).toBe("http://host.com/base#/wrong");
|
|
613
604
|
});
|
|
614
605
|
|
|
615
606
|
it("should set path to forward-slash when empty", () => {
|
|
616
|
-
const locationUrl = new
|
|
607
|
+
const locationUrl = new Location(
|
|
617
608
|
"http://server/base",
|
|
618
609
|
"http://server/",
|
|
610
|
+
false,
|
|
619
611
|
"#!",
|
|
620
612
|
);
|
|
621
|
-
locationUrl
|
|
622
|
-
locationUrl.
|
|
613
|
+
locationUrl.parse("http://server/base");
|
|
614
|
+
locationUrl.setPath("aaa");
|
|
623
615
|
|
|
624
|
-
expect(locationUrl.
|
|
625
|
-
expect(locationUrl.absUrl
|
|
616
|
+
expect(locationUrl.getPath()).toBe("/aaa");
|
|
617
|
+
expect(locationUrl.absUrl).toBe("http://server/base#!/aaa");
|
|
626
618
|
});
|
|
627
619
|
|
|
628
620
|
it("should not preserve old properties when parsing new url", () => {
|
|
629
621
|
const locationUrl = createHashbangUrl();
|
|
630
|
-
locationUrl
|
|
622
|
+
locationUrl.parse("http://www.server.org:1234/base#!/");
|
|
631
623
|
|
|
632
|
-
expect(locationUrl.
|
|
633
|
-
expect(locationUrl.
|
|
634
|
-
expect(locationUrl.
|
|
635
|
-
expect(locationUrl.absUrl
|
|
624
|
+
expect(locationUrl.getPath()).toBe("/");
|
|
625
|
+
expect(locationUrl.getSearch()).toEqual({});
|
|
626
|
+
expect(locationUrl.getHash()).toBe("");
|
|
627
|
+
expect(locationUrl.absUrl).toBe("http://www.server.org:1234/base#!/");
|
|
636
628
|
});
|
|
637
629
|
|
|
638
630
|
it("should insert default hashbang if a hash is given with no hashbang prefix", () => {
|
|
639
631
|
const locationUrl = createHashbangUrl();
|
|
640
632
|
|
|
641
|
-
locationUrl
|
|
642
|
-
expect(locationUrl.absUrl
|
|
633
|
+
locationUrl.parse("http://www.server.org:1234/base#/path");
|
|
634
|
+
expect(locationUrl.absUrl).toBe(
|
|
643
635
|
"http://www.server.org:1234/base#!#%2Fpath",
|
|
644
636
|
);
|
|
645
|
-
expect(locationUrl.
|
|
646
|
-
expect(locationUrl.
|
|
637
|
+
expect(locationUrl.getHash()).toBe("/path");
|
|
638
|
+
expect(locationUrl.getPath()).toBe("");
|
|
647
639
|
|
|
648
|
-
locationUrl
|
|
649
|
-
expect(locationUrl.absUrl
|
|
650
|
-
expect(locationUrl.
|
|
651
|
-
expect(locationUrl.
|
|
640
|
+
locationUrl.parse("http://www.server.org:1234/base#");
|
|
641
|
+
expect(locationUrl.absUrl).toBe("http://www.server.org:1234/base");
|
|
642
|
+
expect(locationUrl.getHash()).toBe("");
|
|
643
|
+
expect(locationUrl.getPath()).toBe("");
|
|
652
644
|
});
|
|
653
645
|
|
|
654
646
|
it("should ignore extra path segments if no hashbang is given", () => {
|
|
655
647
|
const locationUrl = createHashbangUrl();
|
|
656
|
-
locationUrl
|
|
657
|
-
expect(locationUrl.absUrl
|
|
658
|
-
expect(locationUrl.
|
|
659
|
-
expect(locationUrl.
|
|
648
|
+
locationUrl.parse("http://www.server.org:1234/base/extra/path");
|
|
649
|
+
expect(locationUrl.absUrl).toBe("http://www.server.org:1234/base");
|
|
650
|
+
expect(locationUrl.getPath()).toBe("");
|
|
651
|
+
expect(locationUrl.getHash()).toBe("");
|
|
660
652
|
});
|
|
661
653
|
|
|
662
654
|
describe("encoding", () => {
|
|
663
655
|
it("should encode special characters", () => {
|
|
664
656
|
const locationUrl = createHashbangUrl();
|
|
665
|
-
locationUrl.
|
|
666
|
-
locationUrl.
|
|
667
|
-
locationUrl.
|
|
668
|
-
|
|
669
|
-
expect(locationUrl.
|
|
670
|
-
expect(locationUrl.
|
|
671
|
-
expect(locationUrl.
|
|
672
|
-
expect(locationUrl.absUrl
|
|
657
|
+
locationUrl.setPath("/a <>#");
|
|
658
|
+
locationUrl.setSearch({ "i j": "<>#" });
|
|
659
|
+
locationUrl.setHash("<>#");
|
|
660
|
+
|
|
661
|
+
expect(locationUrl.getPath()).toBe("/a <>#");
|
|
662
|
+
expect(locationUrl.getSearch()).toEqual({ "i j": "<>#" });
|
|
663
|
+
expect(locationUrl.getHash()).toBe("<>#");
|
|
664
|
+
expect(locationUrl.absUrl).toBe(
|
|
673
665
|
"http://www.server.org:1234/base#!/a%20%3C%3E%23?i%20j=%3C%3E%23#%3C%3E%23",
|
|
674
666
|
);
|
|
675
667
|
});
|
|
676
668
|
|
|
677
669
|
it("should not encode !$:@", () => {
|
|
678
670
|
const locationUrl = createHashbangUrl();
|
|
679
|
-
locationUrl.
|
|
680
|
-
locationUrl.
|
|
681
|
-
locationUrl.
|
|
671
|
+
locationUrl.setPath("/!$:@");
|
|
672
|
+
locationUrl.setSearch("");
|
|
673
|
+
locationUrl.setHash("!$:@");
|
|
682
674
|
|
|
683
|
-
expect(locationUrl.absUrl
|
|
675
|
+
expect(locationUrl.absUrl).toBe(
|
|
684
676
|
"http://www.server.org:1234/base#!/!$:@#!$:@",
|
|
685
677
|
);
|
|
686
678
|
});
|
|
687
679
|
|
|
688
680
|
it("should decode special characters", () => {
|
|
689
|
-
const locationUrl = new
|
|
681
|
+
const locationUrl = new Location(
|
|
690
682
|
"http://host.com/a",
|
|
691
683
|
"http://host.com/",
|
|
684
|
+
false,
|
|
692
685
|
"#",
|
|
693
686
|
);
|
|
694
|
-
locationUrl
|
|
687
|
+
locationUrl.parse(
|
|
695
688
|
"http://host.com/a#/%20%3C%3E%23?i%20j=%3C%3E%23#x%20%3C%3E%23",
|
|
696
689
|
);
|
|
697
|
-
expect(locationUrl.
|
|
698
|
-
expect(locationUrl.
|
|
699
|
-
expect(locationUrl.
|
|
690
|
+
expect(locationUrl.getPath()).toBe("/ <>#");
|
|
691
|
+
expect(locationUrl.getSearch()).toEqual({ "i j": "<>#" });
|
|
692
|
+
expect(locationUrl.getHash()).toBe("x <>#");
|
|
700
693
|
});
|
|
701
694
|
|
|
702
695
|
it("should return decoded characters for search specified in URL", () => {
|
|
703
|
-
const locationUrl = new
|
|
696
|
+
const locationUrl = new Location(
|
|
704
697
|
"http://host.com/",
|
|
705
698
|
"http://host.com/",
|
|
699
|
+
true,
|
|
706
700
|
);
|
|
707
|
-
locationUrl
|
|
708
|
-
expect(locationUrl.
|
|
701
|
+
locationUrl.parse("http://host.com/?q=1%2F2%203");
|
|
702
|
+
expect(locationUrl.getSearch()).toEqual({ q: "1/2 3" });
|
|
709
703
|
});
|
|
710
704
|
|
|
711
705
|
it("should return decoded characters for search specified with setter", () => {
|
|
712
|
-
const locationUrl = new
|
|
706
|
+
const locationUrl = new Location(
|
|
713
707
|
"http://host.com/",
|
|
714
708
|
"http://host.com/",
|
|
709
|
+
true,
|
|
715
710
|
);
|
|
716
|
-
locationUrl
|
|
717
|
-
locationUrl.
|
|
718
|
-
expect(locationUrl.
|
|
711
|
+
locationUrl.parse("http://host.com/");
|
|
712
|
+
locationUrl.setSearch("q", "1/2 3");
|
|
713
|
+
expect(locationUrl.getSearch()).toEqual({ q: "1/2 3" });
|
|
719
714
|
});
|
|
720
715
|
|
|
721
716
|
it("should return an array for duplicate params", () => {
|
|
722
|
-
const locationUrl = new
|
|
717
|
+
const locationUrl = new Location(
|
|
723
718
|
"http://host.com",
|
|
724
719
|
"http://host.com",
|
|
720
|
+
true,
|
|
725
721
|
);
|
|
726
|
-
locationUrl
|
|
727
|
-
locationUrl.
|
|
728
|
-
expect(locationUrl.
|
|
722
|
+
locationUrl.parse("http://host.com");
|
|
723
|
+
locationUrl.setSearch("q", ["1/2 3", "4/5 6"]);
|
|
724
|
+
expect(locationUrl.getSearch()).toEqual({ q: ["1/2 3", "4/5 6"] });
|
|
729
725
|
});
|
|
730
726
|
|
|
731
727
|
it("should encode an array correctly from search and add to url", () => {
|
|
732
|
-
const locationUrl = new
|
|
728
|
+
const locationUrl = new Location(
|
|
733
729
|
"http://host.com",
|
|
734
730
|
"http://host.com",
|
|
731
|
+
true,
|
|
735
732
|
);
|
|
736
|
-
locationUrl
|
|
737
|
-
locationUrl.
|
|
738
|
-
expect(locationUrl.absUrl
|
|
733
|
+
locationUrl.parse("http://host.com");
|
|
734
|
+
locationUrl.setSearch({ q: ["1/2 3", "4/5 6"] });
|
|
735
|
+
expect(locationUrl.absUrl).toEqual(
|
|
739
736
|
"http://host.com?q=1%2F2%203&q=4%2F5%206",
|
|
740
737
|
);
|
|
741
738
|
});
|
|
742
739
|
|
|
743
740
|
it("should rewrite params when specifying a single param in search", () => {
|
|
744
|
-
const locationUrl = new
|
|
741
|
+
const locationUrl = new Location(
|
|
745
742
|
"http://host.com",
|
|
746
743
|
"http://host.com",
|
|
744
|
+
true,
|
|
747
745
|
);
|
|
748
|
-
locationUrl
|
|
749
|
-
locationUrl.
|
|
750
|
-
expect(locationUrl.absUrl
|
|
751
|
-
locationUrl.
|
|
752
|
-
expect(locationUrl.absUrl
|
|
746
|
+
locationUrl.parse("http://host.com");
|
|
747
|
+
locationUrl.setSearch({ q: "1/2 3" });
|
|
748
|
+
expect(locationUrl.absUrl).toEqual("http://host.com?q=1%2F2%203");
|
|
749
|
+
locationUrl.setSearch({ q: "4/5 6" });
|
|
750
|
+
expect(locationUrl.absUrl).toEqual("http://host.com?q=4%2F5%206");
|
|
753
751
|
});
|
|
754
752
|
|
|
755
|
-
it("url
|
|
756
|
-
const locationUrl = new
|
|
753
|
+
it("url getter/setter should decode non-component special characters in hashbang mode", () => {
|
|
754
|
+
const locationUrl = new Location(
|
|
757
755
|
"http://host.com",
|
|
758
756
|
"http://host.com",
|
|
757
|
+
false,
|
|
759
758
|
);
|
|
760
|
-
locationUrl
|
|
761
|
-
locationUrl.
|
|
762
|
-
expect(locationUrl.
|
|
759
|
+
locationUrl.parse("http://host.com");
|
|
760
|
+
locationUrl.setUrl("/foo%3Abar");
|
|
761
|
+
expect(locationUrl.getPath()).toEqual("/foo:bar");
|
|
763
762
|
});
|
|
764
763
|
|
|
765
|
-
it("url
|
|
766
|
-
const locationUrl = new
|
|
764
|
+
it("url getter/setter should decode non-component special characters in html5 mode", () => {
|
|
765
|
+
const locationUrl = new Location(
|
|
767
766
|
"http://host.com",
|
|
768
767
|
"http://host.com",
|
|
768
|
+
true,
|
|
769
769
|
);
|
|
770
|
-
locationUrl
|
|
771
|
-
locationUrl.
|
|
772
|
-
expect(locationUrl.
|
|
770
|
+
locationUrl.parse("http://host.com");
|
|
771
|
+
locationUrl.setUrl("/foo%3Abar");
|
|
772
|
+
expect(locationUrl.getPath()).toEqual("/foo:bar");
|
|
773
773
|
});
|
|
774
774
|
});
|
|
775
775
|
});
|
|
776
776
|
|
|
777
|
+
describe("encodePath", () => {
|
|
778
|
+
it("should encode each segment but preserve slashes", () => {
|
|
779
|
+
const input = "user profile/images/pic 1.jpg";
|
|
780
|
+
const result = encodePath(input);
|
|
781
|
+
expect(result).toBe("user%20profile/images/pic%201.jpg");
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
it("should re-encode previously encoded forward slashes as literal slashes", () => {
|
|
785
|
+
const input = "folder1%2Fsub/folder2";
|
|
786
|
+
const result = encodePath(input);
|
|
787
|
+
expect(result).toBe("folder1%2Fsub/folder2");
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
it("should handle special characters properly", () => {
|
|
791
|
+
const input = "a$bc/def@gh";
|
|
792
|
+
const result = encodePath(input);
|
|
793
|
+
expect(result).toBe("a$bc/def@gh");
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
it("should return empty string for empty path", () => {
|
|
797
|
+
const input = "";
|
|
798
|
+
const result = encodePath(input);
|
|
799
|
+
expect(result).toBe("");
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
it("should handle single segment", () => {
|
|
803
|
+
const input = "hello world";
|
|
804
|
+
const result = encodePath(input);
|
|
805
|
+
expect(result).toBe("hello%20world");
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
it("should not double encode already encoded segments except slashes", () => {
|
|
809
|
+
const input = "one%20two/three%2Ffour";
|
|
810
|
+
const result = encodePath(input);
|
|
811
|
+
expect(result).toBe("one%20two/three%2Ffour");
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
it("should not double encode already encoded segments", () => {
|
|
815
|
+
const input = "double%20encoded";
|
|
816
|
+
const result = encodePath(input);
|
|
817
|
+
expect(result).toBe("double%20encoded");
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
it("should preserve double encoded segments as-is (single decode only)", () => {
|
|
821
|
+
const input = "double%2520encoded";
|
|
822
|
+
const result = encodePath(input);
|
|
823
|
+
expect(result).toBe("double%2520encoded"); // double % stays double encoded
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
it("should preserve leading and trailing slashes", () => {
|
|
827
|
+
const input = "/a b/c d/";
|
|
828
|
+
const result = encodePath(input);
|
|
829
|
+
expect(result).toBe("/a%20b/c%20d/");
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
it("should preserve multiple consecutive slashes as empty segments", () => {
|
|
833
|
+
const input = "foo//bar///baz";
|
|
834
|
+
const result = encodePath(input);
|
|
835
|
+
expect(result).toBe("foo//bar///baz");
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
it("should not encode RFC 3986 reserved characters in segments", () => {
|
|
839
|
+
const input = "key=value/param+test";
|
|
840
|
+
const result = encodePath(input);
|
|
841
|
+
expect(result).toBe("key=value/param+test");
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
it("should encode unicode characters properly", () => {
|
|
845
|
+
const input = "café/naïve";
|
|
846
|
+
const result = encodePath(input);
|
|
847
|
+
expect(result).toBe("caf%C3%A9/na%C3%AFve");
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
it("should handle input with only slashes", () => {
|
|
851
|
+
const input = "///";
|
|
852
|
+
const result = encodePath(input);
|
|
853
|
+
expect(result).toBe("///");
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
it("should treat encoded slashes as literal and decoded slashes as separators", () => {
|
|
857
|
+
const input = "part1%2Fsub/part2";
|
|
858
|
+
const result = encodePath(input);
|
|
859
|
+
expect(result).toBe("part1%2Fsub/part2");
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
describe("decodePath", () => {
|
|
864
|
+
it("should decode percent-encoded segments", () => {
|
|
865
|
+
const input = "hello%20world/abc%40def";
|
|
866
|
+
const result = decodePath(input, false);
|
|
867
|
+
expect(result).toBe("hello world/abc@def");
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
it("should encode slashes as %2F in html5Mode", () => {
|
|
871
|
+
const input = "section%2Fname/data";
|
|
872
|
+
const result = decodePath(input, true);
|
|
873
|
+
expect(result).toBe("section%2Fname/data");
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
it("should preserve decoded forward slashes in html5Mode", () => {
|
|
877
|
+
const input = "foo/bar%2Fbaz/qux";
|
|
878
|
+
const result = decodePath(input, true);
|
|
879
|
+
// 'bar/baz' becomes 'bar%2Fbaz'
|
|
880
|
+
expect(result).toBe("foo/bar%2Fbaz/qux");
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
it("should not change decoded slashes when html5Mode is false", () => {
|
|
884
|
+
const input = "foo/bar%2Fbaz/qux";
|
|
885
|
+
const result = decodePath(input, false);
|
|
886
|
+
expect(result).toBe("foo/bar/baz/qux");
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
it("should handle empty segments correctly", () => {
|
|
890
|
+
const input = "a//b";
|
|
891
|
+
const result = decodePath(input, false);
|
|
892
|
+
expect(result).toBe("a//b"); // empty segment remains
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
it("should decode already decoded values without errors", () => {
|
|
896
|
+
const input = "simple/path";
|
|
897
|
+
const result = decodePath(input, false);
|
|
898
|
+
expect(result).toBe("simple/path");
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
it("should decode and re-encode all forward slashes in segments when html5Mode is true", () => {
|
|
902
|
+
const input = "a%2Fb/c%2Fd";
|
|
903
|
+
const result = decodePath(input, true);
|
|
904
|
+
expect(result).toBe("a%2Fb/c%2Fd");
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
it("should return an empty string if given an empty string", () => {
|
|
908
|
+
expect(decodePath("", false)).toBe("");
|
|
909
|
+
expect(decodePath("", true)).toBe("");
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
it("should decode double-encoded segments only once", () => {
|
|
913
|
+
const input = "double%2520encoded"; // '%2520' = '%20'
|
|
914
|
+
const result = decodePath(input, false);
|
|
915
|
+
expect(result).toBe("double%20encoded"); // Only decode once
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
it("should correctly decode reserved URI characters", () => {
|
|
919
|
+
const input = "%3A%3B%26%3D";
|
|
920
|
+
const result = decodePath(input, false);
|
|
921
|
+
expect(result).toBe(":;&=");
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
it("should throw URIError for malformed percent encodings", () => {
|
|
925
|
+
const input = "bad%encoding";
|
|
926
|
+
expect(() => decodePath(input, false)).toThrowError(URIError);
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
it("should preserve leading and trailing empty segments", () => {
|
|
930
|
+
const input = "/path/with/trailing/";
|
|
931
|
+
const result = decodePath(input, false);
|
|
932
|
+
expect(result).toBe("/path/with/trailing/");
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
it("should re-encode slashes inside segments when html5Mode is true", () => {
|
|
936
|
+
const input = "path%2Fsegment/next";
|
|
937
|
+
const result = decodePath(input, true);
|
|
938
|
+
expect(result).toBe("path%2Fsegment/next");
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
it("should handle completely empty segments (multiple slashes)", () => {
|
|
942
|
+
const input = "///";
|
|
943
|
+
const result = decodePath(input, false);
|
|
944
|
+
expect(result).toBe("///");
|
|
945
|
+
});
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
describe("normalizePath", () => {
|
|
949
|
+
it("should encode the path, append search and hash correctly", () => {
|
|
950
|
+
const path = "folder name/file name";
|
|
951
|
+
const search = { q: "test", page: "1" };
|
|
952
|
+
const hash = "section 2";
|
|
953
|
+
|
|
954
|
+
const result = normalizePath(path, search, hash);
|
|
955
|
+
expect(result).toBe(
|
|
956
|
+
"folder%20name/file%20name?q=test&page=1#section%202",
|
|
957
|
+
);
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
it("should return path only if no search and no hash", () => {
|
|
961
|
+
const path = "simple/path";
|
|
962
|
+
const result = normalizePath(path, null, null);
|
|
963
|
+
expect(result).toBe("simple/path");
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
it("should correctly encode search params from object", () => {
|
|
967
|
+
const search = { a: "1", b: "2" };
|
|
968
|
+
const result = normalizePath("path", search, null);
|
|
969
|
+
expect(result).toBe("path?a=1&b=2");
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
it("should correctly encode array values in search", () => {
|
|
973
|
+
const search = { a: ["1", "2"] };
|
|
974
|
+
const result = normalizePath("path", search, null);
|
|
975
|
+
// Expected: a=1&a=2 (both keys repeated)
|
|
976
|
+
expect(result).toBe("path?a=1&a=2");
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
it("should handle boolean true values", () => {
|
|
980
|
+
const search = { flag: true };
|
|
981
|
+
const result = normalizePath("path", search, null);
|
|
982
|
+
expect(result).toBe("path?flag");
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
it("should encode hash value properly", () => {
|
|
986
|
+
const path = "path";
|
|
987
|
+
const hash = "hello world";
|
|
988
|
+
const result = normalizePath(path, null, hash);
|
|
989
|
+
expect(result).toBe("path#hello%20world");
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
it("should not append ? if search is empty string or empty object", () => {
|
|
993
|
+
expect(normalizePath("path", "", "hash")).toBe("path#hash");
|
|
994
|
+
expect(normalizePath("path", {}, "hash")).toBe("path#hash");
|
|
995
|
+
});
|
|
996
|
+
|
|
997
|
+
it("should handle empty path gracefully", () => {
|
|
998
|
+
const result = normalizePath("", { a: "1" }, "h");
|
|
999
|
+
expect(result).toBe("?a=1#h");
|
|
1000
|
+
});
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
describe("parseAppUrl", () => {
|
|
1004
|
+
let locationObj;
|
|
1005
|
+
|
|
1006
|
+
beforeEach(() => {
|
|
1007
|
+
locationObj = new Location(
|
|
1008
|
+
"http://www.domain.com:9877/",
|
|
1009
|
+
"http://www.domain.com:9877/",
|
|
1010
|
+
);
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
it("should throw error on url starting with // or \\\\", () => {
|
|
1014
|
+
expect(() => parseAppUrl("//invalid/path", false)).toThrowError(
|
|
1015
|
+
/Invalid url/,
|
|
1016
|
+
);
|
|
1017
|
+
expect(() => parseAppUrl("\\\\invalid\\path", false)).toThrowError(
|
|
1018
|
+
/Invalid url/,
|
|
1019
|
+
);
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
it("should add leading slash if missing and parse url correctly", () => {
|
|
1023
|
+
parseAppUrl("some/path?foo=bar#hashValue", false);
|
|
1024
|
+
expect(locationObj.getPath()).toBe("/some/path");
|
|
1025
|
+
expect(locationObj.getSearch()).toEqual(
|
|
1026
|
+
jasmine.objectContaining({ foo: "bar" }),
|
|
1027
|
+
);
|
|
1028
|
+
expect(locationObj.getHash()).toBe("hashValue");
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
it("should keep leading slash if present", () => {
|
|
1032
|
+
parseAppUrl("/already/slashed?x=1#abc", locationObj, false);
|
|
1033
|
+
expect(locationObj.getPath()).toBe("/already/slashed");
|
|
1034
|
+
expect(locationObj.getSearch()).toEqual(
|
|
1035
|
+
jasmine.objectContaining({ x: "1" }),
|
|
1036
|
+
);
|
|
1037
|
+
expect(locationObj.getHash()).toBe("abc");
|
|
1038
|
+
});
|
|
1039
|
+
|
|
1040
|
+
it("should remove leading slash from path if prefixed and path starts with slash", () => {
|
|
1041
|
+
parseAppUrl("foo/bar", locationObj, false);
|
|
1042
|
+
expect(locationObj.getPath().charAt(0)).toBe("/");
|
|
1043
|
+
expect(locationObj.getPath()).toBe("/foo/bar");
|
|
1044
|
+
});
|
|
1045
|
+
|
|
1046
|
+
it("should set empty $$search when no query params", () => {
|
|
1047
|
+
parseAppUrl("/pathOnly", locationObj, false);
|
|
1048
|
+
expect(locationObj.getSearch()).toEqual({});
|
|
1049
|
+
});
|
|
1050
|
+
|
|
1051
|
+
it("should decode hash correctly", () => {
|
|
1052
|
+
parseAppUrl("/path#%23encoded", locationObj, false);
|
|
1053
|
+
expect(locationObj.getHash()).toBe("#encoded");
|
|
1054
|
+
});
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
describe("stripBaseUrl", () => {
|
|
1058
|
+
it("should return substring after base if url starts with base", () => {
|
|
1059
|
+
expect(stripBaseUrl("/base", "/base/some/path")).toBe("/some/path");
|
|
1060
|
+
expect(
|
|
1061
|
+
stripBaseUrl("http://example.com", "http://example.com/page"),
|
|
1062
|
+
).toBe("/page");
|
|
1063
|
+
expect(stripBaseUrl("", "/anything")).toBe("/anything"); // empty base returns full url
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
it("should return empty string if url equals base", () => {
|
|
1067
|
+
expect(stripBaseUrl("/base", "/base")).toBe("");
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
it("should return undefined if url does not start with base", () => {
|
|
1071
|
+
expect(stripBaseUrl("/base", "/notbase/something")).toBeUndefined();
|
|
1072
|
+
expect(
|
|
1073
|
+
stripBaseUrl("http://example.com", "https://example.com/page"),
|
|
1074
|
+
).toBeUndefined();
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
it("should handle base being longer than url", () => {
|
|
1078
|
+
expect(stripBaseUrl("/longer/base", "/short")).toBeUndefined();
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
it("should be case sensitive", () => {
|
|
1082
|
+
expect(stripBaseUrl("/Base", "/base/something")).toBeUndefined();
|
|
1083
|
+
});
|
|
1084
|
+
});
|
|
1085
|
+
|
|
1086
|
+
describe("stripHash", () => {
|
|
1087
|
+
it("should return the same URL if there is no hash", () => {
|
|
1088
|
+
expect(stripHash("http://example.com/path")).toBe(
|
|
1089
|
+
"http://example.com/path",
|
|
1090
|
+
);
|
|
1091
|
+
expect(stripHash("/some/path")).toBe("/some/path");
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
it("should remove the hash and everything after it", () => {
|
|
1095
|
+
expect(stripHash("http://example.com/path#section1")).toBe(
|
|
1096
|
+
"http://example.com/path",
|
|
1097
|
+
);
|
|
1098
|
+
expect(stripHash("/path/to/resource#hashvalue")).toBe(
|
|
1099
|
+
"/path/to/resource",
|
|
1100
|
+
);
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
it("should remove hash even if it is at the very end", () => {
|
|
1104
|
+
expect(stripHash("http://example.com/#")).toBe("http://example.com/");
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
it("should handle empty string input", () => {
|
|
1108
|
+
expect(stripHash("")).toBe("");
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
it("should handle hash only string", () => {
|
|
1112
|
+
expect(stripHash("#hashonly")).toBe("");
|
|
1113
|
+
});
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
describe("stripFile", () => {
|
|
1117
|
+
it("removes filename from URL without hash", () => {
|
|
1118
|
+
const input = "https://example.com/path/to/file.js";
|
|
1119
|
+
const expected = "https://example.com/path/to/";
|
|
1120
|
+
expect(stripFile(input)).toBe(expected);
|
|
1121
|
+
});
|
|
1122
|
+
|
|
1123
|
+
it("removes filename and hash from URL", () => {
|
|
1124
|
+
const input = "https://example.com/path/to/file.js#section";
|
|
1125
|
+
const expected = "https://example.com/path/to/";
|
|
1126
|
+
expect(stripFile(input)).toBe(expected);
|
|
1127
|
+
});
|
|
1128
|
+
|
|
1129
|
+
it("handles root URL with file", () => {
|
|
1130
|
+
const input = "https://example.com/file.js";
|
|
1131
|
+
const expected = "https://example.com/";
|
|
1132
|
+
expect(stripFile(input)).toBe(expected);
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
it("handles URL with no file", () => {
|
|
1136
|
+
const input = "https://example.com/path/to/";
|
|
1137
|
+
const expected = "https://example.com/path/to/";
|
|
1138
|
+
expect(stripFile(input)).toBe(expected);
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
it("handles relative URL with file and hash", () => {
|
|
1142
|
+
const input = "docs/static/app.js#v1";
|
|
1143
|
+
const expected = "docs/static/";
|
|
1144
|
+
expect(stripFile(input)).toBe(expected);
|
|
1145
|
+
});
|
|
1146
|
+
});
|
|
1147
|
+
|
|
1148
|
+
describe("serverBase", () => {
|
|
1149
|
+
it("returns server base for https URL without port", () => {
|
|
1150
|
+
const input = "https://example.com/path/to/resource";
|
|
1151
|
+
const expected = "https://example.com";
|
|
1152
|
+
expect(serverBase(input)).toBe(expected);
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
it("returns server base for http URL with port", () => {
|
|
1156
|
+
const input = "http://localhost:8080/api/data";
|
|
1157
|
+
const expected = "http://localhost:8080";
|
|
1158
|
+
expect(serverBase(input)).toBe(expected);
|
|
1159
|
+
});
|
|
1160
|
+
|
|
1161
|
+
it("returns server base for URL with subdomain", () => {
|
|
1162
|
+
const input = "https://api.example.com/v1/query";
|
|
1163
|
+
const expected = "https://api.example.com";
|
|
1164
|
+
expect(serverBase(input)).toBe(expected);
|
|
1165
|
+
});
|
|
1166
|
+
|
|
1167
|
+
it("returns full URL if no path is present", () => {
|
|
1168
|
+
const input = "https://example.com";
|
|
1169
|
+
const expected = "https://example.com";
|
|
1170
|
+
expect(serverBase(input)).toBe(expected);
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
it("handles trailing slash after host", () => {
|
|
1174
|
+
const input = "https://example.com/";
|
|
1175
|
+
const expected = "https://example.com";
|
|
1176
|
+
expect(serverBase(input)).toBe(expected);
|
|
1177
|
+
});
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1180
|
+
describe("urlsEqual", () => {
|
|
1181
|
+
it("matches same URL", () => {
|
|
1182
|
+
expect(
|
|
1183
|
+
urlsEqual("http://example.com/foo", "http://example.com/foo"),
|
|
1184
|
+
).toBe(true);
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
it("ignores trailing slash", () => {
|
|
1188
|
+
expect(
|
|
1189
|
+
urlsEqual("http://example.com/foo/", "http://example.com/foo"),
|
|
1190
|
+
).toBe(true);
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1193
|
+
it("ignores encoded spaces", () => {
|
|
1194
|
+
expect(
|
|
1195
|
+
urlsEqual("http://example.com/foo%20bar", "http://example.com/foo bar"),
|
|
1196
|
+
).toBe(true);
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
it("ignores empty hash", () => {
|
|
1200
|
+
expect(
|
|
1201
|
+
urlsEqual("http://example.com/foo#", "http://example.com/foo"),
|
|
1202
|
+
).toBe(true);
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
it("resolves relative to base href", () => {
|
|
1206
|
+
const base = document.createElement("base");
|
|
1207
|
+
base.href = "http://localhost/";
|
|
1208
|
+
document.head.appendChild(base);
|
|
1209
|
+
|
|
1210
|
+
expect(urlsEqual("/bar", "http://localhost/bar")).toBe(true);
|
|
1211
|
+
|
|
1212
|
+
document.head.removeChild(base); // cleanup
|
|
1213
|
+
});
|
|
1214
|
+
|
|
1215
|
+
it("returns false for different paths", () => {
|
|
1216
|
+
expect(
|
|
1217
|
+
urlsEqual("http://example.com/foo", "http://example.com/bar"),
|
|
1218
|
+
).toBe(false);
|
|
1219
|
+
});
|
|
1220
|
+
});
|
|
1221
|
+
|
|
777
1222
|
// describe("location watch", () => {
|
|
778
1223
|
// it("should not update browser if only the empty hash fragment is cleared", () => {
|
|
779
1224
|
// initService({ supportHistory: true });
|
|
@@ -794,7 +1239,7 @@ describe("$location", () => {
|
|
|
794
1239
|
// mockUpBrowser({ initialUrl: "http://new.com/#", baseHref: "/" });
|
|
795
1240
|
// inject(($browser, $location, $window) => {
|
|
796
1241
|
// expect($browser.url()).toBe("http://new.com/");
|
|
797
|
-
// expect($location.absUrl
|
|
1242
|
+
// expect($location.absUrl).toBe("http://new.com/");
|
|
798
1243
|
// expect($window.location.href).toBe("http://new.com/#");
|
|
799
1244
|
// });
|
|
800
1245
|
// });
|
|
@@ -809,8 +1254,8 @@ describe("$location", () => {
|
|
|
809
1254
|
// let handlerCalled = false;
|
|
810
1255
|
// $rootScope.$on("$locationChangeSuccess", () => {
|
|
811
1256
|
// handlerCalled = true;
|
|
812
|
-
// if ($location.
|
|
813
|
-
// $location.
|
|
1257
|
+
// if ($location.getPath() !== "/") {
|
|
1258
|
+
// $location.setPath("/").replace();
|
|
814
1259
|
// }
|
|
815
1260
|
// });
|
|
816
1261
|
// expect($browser.url()).toEqual("http://server/base/#!/home");
|
|
@@ -899,7 +1344,7 @@ describe("$location", () => {
|
|
|
899
1344
|
// $rootScope,
|
|
900
1345
|
// $window,
|
|
901
1346
|
// ) => {
|
|
902
|
-
// $location.
|
|
1347
|
+
// $location.setUrl("baz");
|
|
903
1348
|
// $rootScope.$digest();
|
|
904
1349
|
|
|
905
1350
|
// const originalUrl = $window.location.href;
|
|
@@ -911,7 +1356,7 @@ describe("$location", () => {
|
|
|
911
1356
|
// });
|
|
912
1357
|
|
|
913
1358
|
// expect($browser.url()).toBe("http://foo.bar/#!/baz/qux");
|
|
914
|
-
// expect($location.absUrl
|
|
1359
|
+
// expect($location.absUrl).toBe("http://foo.bar/#!/baz/qux");
|
|
915
1360
|
|
|
916
1361
|
// $rootScope.$apply(() => {
|
|
917
1362
|
// $rootScope.$evalAsync(() => {
|
|
@@ -920,7 +1365,7 @@ describe("$location", () => {
|
|
|
920
1365
|
// });
|
|
921
1366
|
|
|
922
1367
|
// expect($browser.url()).toBe("http://foo.bar/#!/baz/quux");
|
|
923
|
-
// expect($location.absUrl
|
|
1368
|
+
// expect($location.absUrl).toBe("http://foo.bar/#!/baz/quux");
|
|
924
1369
|
// }));
|
|
925
1370
|
|
|
926
1371
|
// it("should correctly update `$location` from URL and not digest infinitely", inject((
|
|
@@ -929,7 +1374,7 @@ describe("$location", () => {
|
|
|
929
1374
|
// $rootScope,
|
|
930
1375
|
// $window,
|
|
931
1376
|
// ) => {
|
|
932
|
-
// $location.
|
|
1377
|
+
// $location.setUrl("baz");
|
|
933
1378
|
// $rootScope.$digest();
|
|
934
1379
|
|
|
935
1380
|
// $rootScope.$apply(() => {
|
|
@@ -941,16 +1386,16 @@ describe("$location", () => {
|
|
|
941
1386
|
// ($window).triggerHandler("hashchange");
|
|
942
1387
|
|
|
943
1388
|
// expect($browser.url()).toBe("http://foo.bar/#!/baz/qux");
|
|
944
|
-
// expect($location.absUrl
|
|
1389
|
+
// expect($location.absUrl).toBe("http://foo.bar/#!/baz/qux");
|
|
945
1390
|
// }));
|
|
946
1391
|
// });
|
|
947
1392
|
|
|
948
1393
|
// function updatePathOnLocationChangeSuccessTo(newPath, newParams) {
|
|
949
1394
|
// inject(($rootScope, $location) => {
|
|
950
1395
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
951
|
-
// $location.
|
|
1396
|
+
// $location.setPath(newPath);
|
|
952
1397
|
// if (newParams) {
|
|
953
|
-
// $location.
|
|
1398
|
+
// $location.setSearch(newParams);
|
|
954
1399
|
// }
|
|
955
1400
|
// });
|
|
956
1401
|
// });
|
|
@@ -971,7 +1416,7 @@ describe("$location", () => {
|
|
|
971
1416
|
// $rootScope.$digest();
|
|
972
1417
|
|
|
973
1418
|
// expect($browser.url()).toEqual("http://server/app/#!/Home");
|
|
974
|
-
// expect($location.
|
|
1419
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
975
1420
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
976
1421
|
// });
|
|
977
1422
|
// });
|
|
@@ -993,7 +1438,7 @@ describe("$location", () => {
|
|
|
993
1438
|
// $rootScope.$digest();
|
|
994
1439
|
|
|
995
1440
|
// expect($browser.url()).toEqual("http://server/app/#!/");
|
|
996
|
-
// expect($location.
|
|
1441
|
+
// expect($location.getPath()).toEqual("/");
|
|
997
1442
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
998
1443
|
// expect($browserUrl.calls.argsFor(0)).toEqual([
|
|
999
1444
|
// "http://server/app/#!/",
|
|
@@ -1016,7 +1461,7 @@ describe("$location", () => {
|
|
|
1016
1461
|
// $rootScope.$digest();
|
|
1017
1462
|
|
|
1018
1463
|
// expect($browser.url()).toEqual("http://server/app/#!/Home");
|
|
1019
|
-
// expect($location.
|
|
1464
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
1020
1465
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
1021
1466
|
// expect($browserUrl.calls.argsFor(0)).toEqual([
|
|
1022
1467
|
// "http://server/app/#!/Home",
|
|
@@ -1039,7 +1484,7 @@ describe("$location", () => {
|
|
|
1039
1484
|
// $rootScope.$digest();
|
|
1040
1485
|
|
|
1041
1486
|
// expect($browser.url()).toEqual("http://server/app/#!/");
|
|
1042
|
-
// expect($location.
|
|
1487
|
+
// expect($location.getPath()).toEqual("/");
|
|
1043
1488
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
1044
1489
|
// });
|
|
1045
1490
|
// });
|
|
@@ -1061,7 +1506,7 @@ describe("$location", () => {
|
|
|
1061
1506
|
// $rootScope.$digest();
|
|
1062
1507
|
|
|
1063
1508
|
// expect($browser.url()).toEqual("http://server/app/Home");
|
|
1064
|
-
// expect($location.
|
|
1509
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
1065
1510
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
1066
1511
|
// });
|
|
1067
1512
|
// });
|
|
@@ -1081,7 +1526,7 @@ describe("$location", () => {
|
|
|
1081
1526
|
// $rootScope.$digest();
|
|
1082
1527
|
|
|
1083
1528
|
// expect($browser.url()).toEqual("http://server/app/");
|
|
1084
|
-
// expect($location.
|
|
1529
|
+
// expect($location.getPath()).toEqual("/");
|
|
1085
1530
|
// expect($browserUrl).not.toHaveBeenCalled();
|
|
1086
1531
|
// });
|
|
1087
1532
|
// });
|
|
@@ -1101,7 +1546,7 @@ describe("$location", () => {
|
|
|
1101
1546
|
// $rootScope.$digest();
|
|
1102
1547
|
|
|
1103
1548
|
// expect($browser.url()).toEqual("http://server/app/Home");
|
|
1104
|
-
// expect($location.
|
|
1549
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
1105
1550
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
1106
1551
|
// });
|
|
1107
1552
|
// });
|
|
@@ -1121,7 +1566,7 @@ describe("$location", () => {
|
|
|
1121
1566
|
// $rootScope.$digest();
|
|
1122
1567
|
|
|
1123
1568
|
// expect($browser.url()).toEqual("http://server/app/");
|
|
1124
|
-
// expect($location.
|
|
1569
|
+
// expect($location.getPath()).toEqual("/");
|
|
1125
1570
|
// expect($browserUrl).not.toHaveBeenCalled();
|
|
1126
1571
|
// });
|
|
1127
1572
|
// });
|
|
@@ -1141,8 +1586,8 @@ describe("$location", () => {
|
|
|
1141
1586
|
|
|
1142
1587
|
// $rootScope.$digest();
|
|
1143
1588
|
|
|
1144
|
-
// expect($location.
|
|
1145
|
-
// expect($location.
|
|
1589
|
+
// expect($location.getPath()).toEqual("/");
|
|
1590
|
+
// expect($location.getSearch()).toEqual({ q: "'" });
|
|
1146
1591
|
// expect($browserUrl).toHaveBeenCalledTimes(1);
|
|
1147
1592
|
// });
|
|
1148
1593
|
// });
|
|
@@ -1154,12 +1599,12 @@ describe("$location", () => {
|
|
|
1154
1599
|
// initService({ html5Mode: false, hashPrefix: "!", supportHistory: true });
|
|
1155
1600
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
|
|
1156
1601
|
// inject(($window, $browser, $location, $rootScope) => {
|
|
1157
|
-
// spyOn($location, "
|
|
1602
|
+
// spyOn($location, "parse").and.callThrough();
|
|
1158
1603
|
// $window.location.href = "http://new.com/a/b#!/aaa";
|
|
1159
1604
|
// $browser.$$checkUrlChange();
|
|
1160
|
-
// expect($location.absUrl
|
|
1161
|
-
// expect($location.
|
|
1162
|
-
// expect($location
|
|
1605
|
+
// expect($location.absUrl).toBe("http://new.com/a/b#!/aaa");
|
|
1606
|
+
// expect($location.getPath()).toBe("/aaa");
|
|
1607
|
+
// expect($location.parse).toHaveBeenCalled();
|
|
1163
1608
|
// });
|
|
1164
1609
|
// });
|
|
1165
1610
|
|
|
@@ -1174,10 +1619,10 @@ describe("$location", () => {
|
|
|
1174
1619
|
// $rootScope.$apply(() => {
|
|
1175
1620
|
// $window.location.href = NEW_URL;
|
|
1176
1621
|
// $browser.$$checkUrlChange(); // simulate firing event from browser
|
|
1177
|
-
// expect($location.absUrl
|
|
1622
|
+
// expect($location.absUrl).toBe(OLD_URL); // should be async
|
|
1178
1623
|
// });
|
|
1179
1624
|
|
|
1180
|
-
// expect($location.absUrl
|
|
1625
|
+
// expect($location.absUrl).toBe(NEW_URL);
|
|
1181
1626
|
// });
|
|
1182
1627
|
// });
|
|
1183
1628
|
|
|
@@ -1195,12 +1640,12 @@ describe("$location", () => {
|
|
|
1195
1640
|
// notRunYet = false;
|
|
1196
1641
|
// $window.location.href = NEW_URL;
|
|
1197
1642
|
// $browser.$$checkUrlChange(); // simulate firing event from browser
|
|
1198
|
-
// expect($location.absUrl
|
|
1643
|
+
// expect($location.absUrl).toBe(OLD_URL); // should be async
|
|
1199
1644
|
// }
|
|
1200
1645
|
// });
|
|
1201
1646
|
|
|
1202
1647
|
// $rootScope.$digest();
|
|
1203
|
-
// expect($location.absUrl
|
|
1648
|
+
// expect($location.absUrl).toBe(NEW_URL);
|
|
1204
1649
|
// });
|
|
1205
1650
|
// });
|
|
1206
1651
|
|
|
@@ -1212,7 +1657,7 @@ describe("$location", () => {
|
|
|
1212
1657
|
// $browser,
|
|
1213
1658
|
// "url",
|
|
1214
1659
|
// ).and.callThrough();
|
|
1215
|
-
// $location.
|
|
1660
|
+
// $location.setPath("/new/path");
|
|
1216
1661
|
// expect($browserUrl).not.toHaveBeenCalled();
|
|
1217
1662
|
// $rootScope.$apply();
|
|
1218
1663
|
|
|
@@ -1229,10 +1674,10 @@ describe("$location", () => {
|
|
|
1229
1674
|
// $browser,
|
|
1230
1675
|
// "url",
|
|
1231
1676
|
// ).and.callThrough();
|
|
1232
|
-
// $location.
|
|
1677
|
+
// $location.setPath("/new/path");
|
|
1233
1678
|
|
|
1234
1679
|
// $rootScope.$watch(() => {
|
|
1235
|
-
// $location.
|
|
1680
|
+
// $location.setSearch("a=b");
|
|
1236
1681
|
// });
|
|
1237
1682
|
|
|
1238
1683
|
// $rootScope.$apply();
|
|
@@ -1249,7 +1694,7 @@ describe("$location", () => {
|
|
|
1249
1694
|
// $browser,
|
|
1250
1695
|
// "url",
|
|
1251
1696
|
// ).and.callThrough();
|
|
1252
|
-
// $location.
|
|
1697
|
+
// $location.setPath("/n/url").replace();
|
|
1253
1698
|
// $rootScope.$apply();
|
|
1254
1699
|
|
|
1255
1700
|
// expect($browserUrl).toHaveBeenCalled();
|
|
@@ -1267,16 +1712,16 @@ describe("$location", () => {
|
|
|
1267
1712
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
|
|
1268
1713
|
// inject(($rootScope, $browser, $location) => {
|
|
1269
1714
|
// // init watches
|
|
1270
|
-
// $location.
|
|
1715
|
+
// $location.setUrl("/initUrl");
|
|
1271
1716
|
// $rootScope.$apply();
|
|
1272
1717
|
|
|
1273
1718
|
// // changes url but resets it before digest
|
|
1274
|
-
// $location.
|
|
1719
|
+
// $location.setUrl("/newUrl").replace().url("/initUrl");
|
|
1275
1720
|
// $rootScope.$apply();
|
|
1276
1721
|
// expect($location.$$replace).toBe(false);
|
|
1277
1722
|
|
|
1278
1723
|
// // set the url to the old value
|
|
1279
|
-
// $location.
|
|
1724
|
+
// $location.setUrl("/newUrl").replace();
|
|
1280
1725
|
// $rootScope.$apply();
|
|
1281
1726
|
// expect($location.$$replace).toBe(false);
|
|
1282
1727
|
|
|
@@ -1294,7 +1739,7 @@ describe("$location", () => {
|
|
|
1294
1739
|
// $rootScope.$watch(
|
|
1295
1740
|
// () => true,
|
|
1296
1741
|
// () => {
|
|
1297
|
-
// $location.
|
|
1742
|
+
// $location.setPath("/changed");
|
|
1298
1743
|
// },
|
|
1299
1744
|
// );
|
|
1300
1745
|
|
|
@@ -1307,7 +1752,7 @@ describe("$location", () => {
|
|
|
1307
1752
|
// initService({ html5Mode: false, hashPrefix: "", supportHistory: true });
|
|
1308
1753
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b", baseHref: "/a/b" });
|
|
1309
1754
|
// inject(($rootScope, $browser, $location) => {
|
|
1310
|
-
// $location.
|
|
1755
|
+
// $location.setHash("test");
|
|
1311
1756
|
|
|
1312
1757
|
// $rootScope.$digest();
|
|
1313
1758
|
// expect($browser.url()).toBe("http://new.com/a/b##test");
|
|
@@ -1324,7 +1769,7 @@ describe("$location", () => {
|
|
|
1324
1769
|
// state: { a: 2 },
|
|
1325
1770
|
// });
|
|
1326
1771
|
// inject(($location) => {
|
|
1327
|
-
// expect($location.
|
|
1772
|
+
// expect($location.getState()).toEqual({ a: 2 });
|
|
1328
1773
|
// });
|
|
1329
1774
|
// });
|
|
1330
1775
|
|
|
@@ -1335,7 +1780,7 @@ describe("$location", () => {
|
|
|
1335
1780
|
// $window.history.pushState({ b: 3 });
|
|
1336
1781
|
// $rootScope.$digest();
|
|
1337
1782
|
|
|
1338
|
-
// expect($location.
|
|
1783
|
+
// expect($location.getState()).toEqual({ b: 3 });
|
|
1339
1784
|
|
|
1340
1785
|
// $window.history.pushState(
|
|
1341
1786
|
// { b: 4 },
|
|
@@ -1344,10 +1789,10 @@ describe("$location", () => {
|
|
|
1344
1789
|
// );
|
|
1345
1790
|
// $rootScope.$digest();
|
|
1346
1791
|
|
|
1347
|
-
// expect($location.
|
|
1348
|
-
// expect($location.
|
|
1349
|
-
// expect($location.
|
|
1350
|
-
// expect($location.
|
|
1792
|
+
// expect($location.getPath()).toBe("/c");
|
|
1793
|
+
// expect($location.getSearch()).toEqual({ d: "e" });
|
|
1794
|
+
// expect($location.getHash()).toBe("f");
|
|
1795
|
+
// expect($location.getState()).toEqual({ b: 4 });
|
|
1351
1796
|
// });
|
|
1352
1797
|
// });
|
|
1353
1798
|
|
|
@@ -1362,9 +1807,9 @@ describe("$location", () => {
|
|
|
1362
1807
|
// $window.history.pushState({}, null, "http://server/app/Home?q='");
|
|
1363
1808
|
// $rootScope.$digest();
|
|
1364
1809
|
|
|
1365
|
-
// expect($location.absUrl
|
|
1366
|
-
// expect($location.
|
|
1367
|
-
// expect($location.
|
|
1810
|
+
// expect($location.absUrl).toEqual("http://server/app/Home?q='");
|
|
1811
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
1812
|
+
// expect($location.getSearch()).toEqual({ q: "'" });
|
|
1368
1813
|
// });
|
|
1369
1814
|
// });
|
|
1370
1815
|
|
|
@@ -1379,9 +1824,9 @@ describe("$location", () => {
|
|
|
1379
1824
|
// $window.location.href = "http://server/app/Home?q='";
|
|
1380
1825
|
// ($window).triggerHandler("popstate");
|
|
1381
1826
|
|
|
1382
|
-
// expect($location.absUrl
|
|
1383
|
-
// expect($location.
|
|
1384
|
-
// expect($location.
|
|
1827
|
+
// expect($location.absUrl).toEqual("http://server/app/Home?q='");
|
|
1828
|
+
// expect($location.getPath()).toEqual("/Home");
|
|
1829
|
+
// expect($location.getSearch()).toEqual({ q: "'" });
|
|
1385
1830
|
// });
|
|
1386
1831
|
// });
|
|
1387
1832
|
|
|
@@ -1393,7 +1838,7 @@ describe("$location", () => {
|
|
|
1393
1838
|
// $browser,
|
|
1394
1839
|
// "url",
|
|
1395
1840
|
// ).and.callThrough();
|
|
1396
|
-
// $location.
|
|
1841
|
+
// $location.setPath("/n/url").state({ a: 2 }).replace();
|
|
1397
1842
|
// $rootScope.$apply();
|
|
1398
1843
|
|
|
1399
1844
|
// expect($browserUrl).toHaveBeenCalled();
|
|
@@ -1417,11 +1862,11 @@ describe("$location", () => {
|
|
|
1417
1862
|
// "url",
|
|
1418
1863
|
// ).and.callThrough();
|
|
1419
1864
|
// $location
|
|
1420
|
-
// .
|
|
1865
|
+
// .setPath("/n/url")
|
|
1421
1866
|
// .state({ a: 2 })
|
|
1422
1867
|
// .replace()
|
|
1423
1868
|
// .state({ b: 3 })
|
|
1424
|
-
// .
|
|
1869
|
+
// .setPath("/o/url");
|
|
1425
1870
|
// $rootScope.$apply();
|
|
1426
1871
|
|
|
1427
1872
|
// expect($browserUrl).toHaveBeenCalled();
|
|
@@ -1444,7 +1889,7 @@ describe("$location", () => {
|
|
|
1444
1889
|
// $browser,
|
|
1445
1890
|
// "url",
|
|
1446
1891
|
// ).and.callThrough();
|
|
1447
|
-
// $location.
|
|
1892
|
+
// $location.setState({ a: 2 }).replace().state({ b: 3 });
|
|
1448
1893
|
// $rootScope.$apply();
|
|
1449
1894
|
|
|
1450
1895
|
// expect($browserUrl).toHaveBeenCalled();
|
|
@@ -1464,7 +1909,7 @@ describe("$location", () => {
|
|
|
1464
1909
|
|
|
1465
1910
|
// inject(($rootScope, $location) => {
|
|
1466
1911
|
// // init watches
|
|
1467
|
-
// $location.
|
|
1912
|
+
// $location.setUrl("/initUrl").state({ a: 2 });
|
|
1468
1913
|
// $rootScope.$apply();
|
|
1469
1914
|
|
|
1470
1915
|
// // changes url & state but resets them before digest
|
|
@@ -1478,7 +1923,7 @@ describe("$location", () => {
|
|
|
1478
1923
|
// expect($location.$$replace).toBe(false);
|
|
1479
1924
|
|
|
1480
1925
|
// // set the url to the old value
|
|
1481
|
-
// $location.
|
|
1926
|
+
// $location.setUrl("/newUrl").state({ a: 2 }).replace();
|
|
1482
1927
|
// $rootScope.$apply();
|
|
1483
1928
|
// expect($location.$$replace).toBe(false);
|
|
1484
1929
|
|
|
@@ -1495,7 +1940,7 @@ describe("$location", () => {
|
|
|
1495
1940
|
|
|
1496
1941
|
// inject(($rootScope, $location, $browser) => {
|
|
1497
1942
|
// const o = { a: 2 };
|
|
1498
|
-
// $location.
|
|
1943
|
+
// $location.setState(o);
|
|
1499
1944
|
// o.a = 3;
|
|
1500
1945
|
// $rootScope.$apply();
|
|
1501
1946
|
// expect($browser.state()).toEqual({ a: 3 });
|
|
@@ -1506,14 +1951,14 @@ describe("$location", () => {
|
|
|
1506
1951
|
// });
|
|
1507
1952
|
// });
|
|
1508
1953
|
|
|
1509
|
-
// it("should make $location.
|
|
1954
|
+
// it("should make $location.getState() referencially identical with $browser.state() after digest", () => {
|
|
1510
1955
|
// initService({ html5Mode: true, supportHistory: true });
|
|
1511
1956
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
|
|
1512
1957
|
|
|
1513
1958
|
// inject(($rootScope, $location, $browser) => {
|
|
1514
|
-
// $location.
|
|
1959
|
+
// $location.setState({ a: 2 });
|
|
1515
1960
|
// $rootScope.$apply();
|
|
1516
|
-
// expect($location.
|
|
1961
|
+
// expect($location.getState()).toBe($browser.state());
|
|
1517
1962
|
// });
|
|
1518
1963
|
// });
|
|
1519
1964
|
|
|
@@ -1522,9 +1967,9 @@ describe("$location", () => {
|
|
|
1522
1967
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
|
|
1523
1968
|
|
|
1524
1969
|
// inject(($rootScope, $location) => {
|
|
1525
|
-
// $location.
|
|
1970
|
+
// $location.setUrl("/foo").state({ a: 2 });
|
|
1526
1971
|
// $rootScope.$apply();
|
|
1527
|
-
// expect($location.
|
|
1972
|
+
// expect($location.getState()).toEqual({ a: 2 });
|
|
1528
1973
|
// });
|
|
1529
1974
|
// });
|
|
1530
1975
|
|
|
@@ -1533,14 +1978,14 @@ describe("$location", () => {
|
|
|
1533
1978
|
// mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
|
|
1534
1979
|
|
|
1535
1980
|
// inject(($rootScope, $location, $browser) => {
|
|
1536
|
-
// $location.
|
|
1981
|
+
// $location.setUrl("/foo").state({ a: 2 });
|
|
1537
1982
|
// $rootScope.$apply();
|
|
1538
1983
|
|
|
1539
1984
|
// const $browserUrl = spyOnlyCallsWithArgs(
|
|
1540
1985
|
// $browser,
|
|
1541
1986
|
// "url",
|
|
1542
1987
|
// ).and.callThrough();
|
|
1543
|
-
// $location.
|
|
1988
|
+
// $location.setUrl("/bar");
|
|
1544
1989
|
// $rootScope.$apply();
|
|
1545
1990
|
|
|
1546
1991
|
// expect($browserUrl).toHaveBeenCalled();
|
|
@@ -1579,8 +2024,8 @@ describe("$location", () => {
|
|
|
1579
2024
|
// });
|
|
1580
2025
|
// inject(($rootScope, $location, $browser) => {
|
|
1581
2026
|
// expect($browser.url()).toBe("http://domain.com/base/index.html#!/a/b");
|
|
1582
|
-
// $location.
|
|
1583
|
-
// $location.
|
|
2027
|
+
// $location.setPath("/new");
|
|
2028
|
+
// $location.setSearch({ a: true });
|
|
1584
2029
|
// $rootScope.$apply();
|
|
1585
2030
|
// expect($browser.url()).toBe(
|
|
1586
2031
|
// "http://domain.com/base/index.html#!/new?a",
|
|
@@ -1596,8 +2041,8 @@ describe("$location", () => {
|
|
|
1596
2041
|
// });
|
|
1597
2042
|
// inject(($rootScope, $location, $browser) => {
|
|
1598
2043
|
// expect($browser.url()).toBe("http://domain.com/base/index.html#/a/b");
|
|
1599
|
-
// $location.
|
|
1600
|
-
// $location.
|
|
2044
|
+
// $location.setPath("/new");
|
|
2045
|
+
// $location.setSearch({ a: true });
|
|
1601
2046
|
// $rootScope.$apply();
|
|
1602
2047
|
// expect($browser.url()).toBe("http://domain.com/base/index.html#/new?a");
|
|
1603
2048
|
// });
|
|
@@ -1618,8 +2063,8 @@ describe("$location", () => {
|
|
|
1618
2063
|
// expect($browser.url()).toBe(
|
|
1619
2064
|
// "http://domain.com/base/index.html#!!/a/b",
|
|
1620
2065
|
// );
|
|
1621
|
-
// $location.
|
|
1622
|
-
// $location.
|
|
2066
|
+
// $location.setPath("/new");
|
|
2067
|
+
// $location.setSearch({ a: true });
|
|
1623
2068
|
// $rootScope.$apply();
|
|
1624
2069
|
// expect($browser.url()).toBe(
|
|
1625
2070
|
// "http://domain.com/base/index.html#!!/new?a",
|
|
@@ -1670,8 +2115,8 @@ describe("$location", () => {
|
|
|
1670
2115
|
// });
|
|
1671
2116
|
// inject(($rootScope, $location, $browser) => {
|
|
1672
2117
|
// expect($browser.url()).toBe("http://domain.com/base/old/index.html#a");
|
|
1673
|
-
// $location.
|
|
1674
|
-
// $location.
|
|
2118
|
+
// $location.setPath("/new");
|
|
2119
|
+
// $location.setSearch({ a: true });
|
|
1675
2120
|
// $rootScope.$apply();
|
|
1676
2121
|
// expect($browser.url()).toBe("http://domain.com/base/new?a#a");
|
|
1677
2122
|
// });
|
|
@@ -1685,11 +2130,11 @@ describe("$location", () => {
|
|
|
1685
2130
|
// });
|
|
1686
2131
|
// inject(($rootScope, $location, $browser) => {
|
|
1687
2132
|
// expect($browser.url()).toBe("http://domain.com/base/a/b");
|
|
1688
|
-
// $location.
|
|
1689
|
-
// $location.
|
|
2133
|
+
// $location.setPath("/new");
|
|
2134
|
+
// $location.setHash("abc");
|
|
1690
2135
|
// $rootScope.$apply();
|
|
1691
2136
|
// expect($browser.url()).toBe("http://domain.com/base/new#abc");
|
|
1692
|
-
// expect($location.
|
|
2137
|
+
// expect($location.getPath()).toBe("/new");
|
|
1693
2138
|
// });
|
|
1694
2139
|
// });
|
|
1695
2140
|
|
|
@@ -1701,7 +2146,7 @@ describe("$location", () => {
|
|
|
1701
2146
|
// });
|
|
1702
2147
|
// inject(($rootScope, $location, $browser) => {
|
|
1703
2148
|
// expect($browser.url()).toBe("http://domain.com/base/a/b");
|
|
1704
|
-
// expect($location.
|
|
2149
|
+
// expect($location.getPath()).toBe("/a/b");
|
|
1705
2150
|
// });
|
|
1706
2151
|
// });
|
|
1707
2152
|
// });
|
|
@@ -1898,7 +2343,7 @@ describe("$location", () => {
|
|
|
1898
2343
|
// );
|
|
1899
2344
|
// });
|
|
1900
2345
|
|
|
1901
|
-
// it('should produce relative paths correctly when $location.
|
|
2346
|
+
// it('should produce relative paths correctly when $location.getPath() is "/" when history enabled on old browser', () => {
|
|
1902
2347
|
// configureTestLink({ linkHref: "partial1" });
|
|
1903
2348
|
// initService({ html5Mode: true, supportHistory: false, hashPrefix: "!" });
|
|
1904
2349
|
// inject(
|
|
@@ -1909,7 +2354,7 @@ describe("$location", () => {
|
|
|
1909
2354
|
// setupRewriteChecks(),
|
|
1910
2355
|
// ($browser, $location, $rootScope) => {
|
|
1911
2356
|
// $rootScope.$apply(() => {
|
|
1912
|
-
// $location.
|
|
2357
|
+
// $location.setPath("/");
|
|
1913
2358
|
// });
|
|
1914
2359
|
// browserTrigger(link, "click");
|
|
1915
2360
|
// expectRewriteTo(
|
|
@@ -2226,11 +2671,11 @@ describe("$location", () => {
|
|
|
2226
2671
|
// setupRewriteChecks(),
|
|
2227
2672
|
// ($browser, $location, $rootScope) => {
|
|
2228
2673
|
// $rootScope.$apply(() => {
|
|
2229
|
-
// $location.
|
|
2230
|
-
// $location.
|
|
2674
|
+
// $location.setPath("/some");
|
|
2675
|
+
// $location.setHash("foo");
|
|
2231
2676
|
// });
|
|
2232
2677
|
// browserTrigger(link, "click");
|
|
2233
|
-
// expect($location.
|
|
2678
|
+
// expect($location.getHash()).toBe("link");
|
|
2234
2679
|
// expectRewriteTo(
|
|
2235
2680
|
// $browser,
|
|
2236
2681
|
// "http://host.com/base/index.html#!/some#link",
|
|
@@ -2250,11 +2695,11 @@ describe("$location", () => {
|
|
|
2250
2695
|
// setupRewriteChecks(),
|
|
2251
2696
|
// ($browser, $location, $rootScope) => {
|
|
2252
2697
|
// $rootScope.$apply(() => {
|
|
2253
|
-
// $location.
|
|
2254
|
-
// $location.
|
|
2698
|
+
// $location.setPath("/some");
|
|
2699
|
+
// $location.setHash("foo");
|
|
2255
2700
|
// });
|
|
2256
2701
|
// browserTrigger(link, "click");
|
|
2257
|
-
// expect($location.
|
|
2702
|
+
// expect($location.getHash()).toBe("link");
|
|
2258
2703
|
// expectRewriteTo($browser, "http://host.com/base/some#link");
|
|
2259
2704
|
// },
|
|
2260
2705
|
// );
|
|
@@ -2566,9 +3011,9 @@ describe("$location", () => {
|
|
|
2566
3011
|
// $log.info("after", newUrl, oldUrl, $browser.url());
|
|
2567
3012
|
// });
|
|
2568
3013
|
|
|
2569
|
-
// expect($location.
|
|
2570
|
-
// $location.
|
|
2571
|
-
// expect($location.
|
|
3014
|
+
// expect($location.getUrl()).toEqual("");
|
|
3015
|
+
// $location.setUrl("/somePath");
|
|
3016
|
+
// expect($location.getUrl()).toEqual("/somePath");
|
|
2572
3017
|
// expect($browser.url()).toEqual("http://server/");
|
|
2573
3018
|
// expect($log.info.logs).toEqual([]);
|
|
2574
3019
|
|
|
@@ -2586,7 +3031,7 @@ describe("$location", () => {
|
|
|
2586
3031
|
// "http://server/",
|
|
2587
3032
|
// "http://server/#!/somePath",
|
|
2588
3033
|
// ]);
|
|
2589
|
-
// expect($location.
|
|
3034
|
+
// expect($location.getUrl()).toEqual("/somePath");
|
|
2590
3035
|
// expect($browser.url()).toEqual("http://server/#!/somePath");
|
|
2591
3036
|
// }));
|
|
2592
3037
|
|
|
@@ -2597,7 +3042,7 @@ describe("$location", () => {
|
|
|
2597
3042
|
// $log,
|
|
2598
3043
|
// ) => {
|
|
2599
3044
|
// expect($browser.url()).toEqual("http://server/");
|
|
2600
|
-
// expect($location.
|
|
3045
|
+
// expect($location.getUrl()).toEqual("");
|
|
2601
3046
|
|
|
2602
3047
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2603
3048
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
@@ -2607,9 +3052,9 @@ describe("$location", () => {
|
|
|
2607
3052
|
// throw new Error("location should have been canceled");
|
|
2608
3053
|
// });
|
|
2609
3054
|
|
|
2610
|
-
// expect($location.
|
|
2611
|
-
// $location.
|
|
2612
|
-
// expect($location.
|
|
3055
|
+
// expect($location.getUrl()).toEqual("");
|
|
3056
|
+
// $location.setUrl("/somePath");
|
|
3057
|
+
// expect($location.getUrl()).toEqual("/somePath");
|
|
2613
3058
|
// expect($browser.url()).toEqual("http://server/");
|
|
2614
3059
|
// expect($log.info.logs).toEqual([]);
|
|
2615
3060
|
|
|
@@ -2622,7 +3067,7 @@ describe("$location", () => {
|
|
|
2622
3067
|
// "http://server/",
|
|
2623
3068
|
// ]);
|
|
2624
3069
|
// expect($log.info.logs[1]).toBeUndefined();
|
|
2625
|
-
// expect($location.
|
|
3070
|
+
// expect($location.getUrl()).toEqual("");
|
|
2626
3071
|
// expect($browser.url()).toEqual("http://server/");
|
|
2627
3072
|
// }));
|
|
2628
3073
|
|
|
@@ -2635,14 +3080,14 @@ describe("$location", () => {
|
|
|
2635
3080
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2636
3081
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
2637
3082
|
// if (newUrl === "http://server/#!/somePath") {
|
|
2638
|
-
// $location.
|
|
3083
|
+
// $location.setUrl("/redirectPath");
|
|
2639
3084
|
// }
|
|
2640
3085
|
// });
|
|
2641
3086
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
2642
3087
|
// $log.info("after", newUrl, oldUrl, $browser.url());
|
|
2643
3088
|
// });
|
|
2644
3089
|
|
|
2645
|
-
// $location.
|
|
3090
|
+
// $location.setUrl("/somePath");
|
|
2646
3091
|
// $rootScope.$apply();
|
|
2647
3092
|
|
|
2648
3093
|
// expect($log.info.logs.shift()).toEqual([
|
|
@@ -2664,7 +3109,7 @@ describe("$location", () => {
|
|
|
2664
3109
|
// "http://server/#!/redirectPath",
|
|
2665
3110
|
// ]);
|
|
2666
3111
|
|
|
2667
|
-
// expect($location.
|
|
3112
|
+
// expect($location.getUrl()).toEqual("/redirectPath");
|
|
2668
3113
|
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
|
|
2669
3114
|
// }));
|
|
2670
3115
|
|
|
@@ -2678,14 +3123,14 @@ describe("$location", () => {
|
|
|
2678
3123
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
2679
3124
|
// if (newUrl === "http://server/#!/somePath") {
|
|
2680
3125
|
// event.preventDefault();
|
|
2681
|
-
// $location.
|
|
3126
|
+
// $location.setUrl("/redirectPath");
|
|
2682
3127
|
// }
|
|
2683
3128
|
// });
|
|
2684
3129
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
2685
3130
|
// $log.info("after", newUrl, oldUrl, $browser.url());
|
|
2686
3131
|
// });
|
|
2687
3132
|
|
|
2688
|
-
// $location.
|
|
3133
|
+
// $location.setUrl("/somePath");
|
|
2689
3134
|
// $rootScope.$apply();
|
|
2690
3135
|
|
|
2691
3136
|
// expect($log.info.logs.shift()).toEqual([
|
|
@@ -2707,7 +3152,7 @@ describe("$location", () => {
|
|
|
2707
3152
|
// "http://server/#!/redirectPath",
|
|
2708
3153
|
// ]);
|
|
2709
3154
|
|
|
2710
|
-
// expect($location.
|
|
3155
|
+
// expect($location.getUrl()).toEqual("/redirectPath");
|
|
2711
3156
|
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
|
|
2712
3157
|
// }));
|
|
2713
3158
|
|
|
@@ -2720,16 +3165,16 @@ describe("$location", () => {
|
|
|
2720
3165
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2721
3166
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
2722
3167
|
// if (newUrl === "http://server/#!/somePath") {
|
|
2723
|
-
// $location.
|
|
3168
|
+
// $location.setUrl("/redirectPath");
|
|
2724
3169
|
// } else if (newUrl === "http://server/#!/redirectPath") {
|
|
2725
|
-
// $location.
|
|
3170
|
+
// $location.setUrl("/redirectPath2");
|
|
2726
3171
|
// }
|
|
2727
3172
|
// });
|
|
2728
3173
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
2729
3174
|
// $log.info("after", newUrl, oldUrl, $browser.url());
|
|
2730
3175
|
// });
|
|
2731
3176
|
|
|
2732
|
-
// $location.
|
|
3177
|
+
// $location.setUrl("/somePath");
|
|
2733
3178
|
// $rootScope.$apply();
|
|
2734
3179
|
|
|
2735
3180
|
// expect($log.info.logs.shift()).toEqual([
|
|
@@ -2757,7 +3202,7 @@ describe("$location", () => {
|
|
|
2757
3202
|
// "http://server/#!/redirectPath2",
|
|
2758
3203
|
// ]);
|
|
2759
3204
|
|
|
2760
|
-
// expect($location.
|
|
3205
|
+
// expect($location.getUrl()).toEqual("/redirectPath2");
|
|
2761
3206
|
// expect($browser.url()).toEqual("http://server/#!/redirectPath2");
|
|
2762
3207
|
// }));
|
|
2763
3208
|
|
|
@@ -2770,7 +3215,7 @@ describe("$location", () => {
|
|
|
2770
3215
|
// $rootScope.$apply(); // clear initial $locationChangeStart
|
|
2771
3216
|
|
|
2772
3217
|
// expect($browser.url()).toEqual("http://server/");
|
|
2773
|
-
// expect($location.
|
|
3218
|
+
// expect($location.getUrl()).toEqual("");
|
|
2774
3219
|
|
|
2775
3220
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2776
3221
|
// $log.info("start", newUrl, oldUrl);
|
|
@@ -2800,11 +3245,11 @@ describe("$location", () => {
|
|
|
2800
3245
|
// $rootScope,
|
|
2801
3246
|
// $log,
|
|
2802
3247
|
// ) => {
|
|
2803
|
-
// $location.
|
|
3248
|
+
// $location.setUrl("/somepath");
|
|
2804
3249
|
// $rootScope.$apply();
|
|
2805
3250
|
|
|
2806
3251
|
// expect($browser.url()).toEqual("http://server/#!/somepath");
|
|
2807
|
-
// expect($location.
|
|
3252
|
+
// expect($location.getUrl()).toEqual("/somepath");
|
|
2808
3253
|
|
|
2809
3254
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2810
3255
|
// $log.info("start", newUrl, oldUrl);
|
|
@@ -2837,7 +3282,7 @@ describe("$location", () => {
|
|
|
2837
3282
|
// $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
|
|
2838
3283
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
2839
3284
|
// if (newUrl === "http://server/#!/somePath") {
|
|
2840
|
-
// $location.
|
|
3285
|
+
// $location.setUrl("/redirectPath");
|
|
2841
3286
|
// }
|
|
2842
3287
|
// });
|
|
2843
3288
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
@@ -2866,7 +3311,7 @@ describe("$location", () => {
|
|
|
2866
3311
|
// "http://server/#!/redirectPath",
|
|
2867
3312
|
// ]);
|
|
2868
3313
|
|
|
2869
|
-
// expect($location.
|
|
3314
|
+
// expect($location.getUrl()).toEqual("/redirectPath");
|
|
2870
3315
|
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
|
|
2871
3316
|
// }));
|
|
2872
3317
|
|
|
@@ -2880,7 +3325,7 @@ describe("$location", () => {
|
|
|
2880
3325
|
// $log.info("before", newUrl, oldUrl, $browser.url());
|
|
2881
3326
|
// if (newUrl === "http://server/#!/somePath") {
|
|
2882
3327
|
// event.preventDefault();
|
|
2883
|
-
// $location.
|
|
3328
|
+
// $location.setUrl("/redirectPath");
|
|
2884
3329
|
// }
|
|
2885
3330
|
// });
|
|
2886
3331
|
// $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
|
|
@@ -2909,7 +3354,7 @@ describe("$location", () => {
|
|
|
2909
3354
|
// "http://server/#!/redirectPath",
|
|
2910
3355
|
// ]);
|
|
2911
3356
|
|
|
2912
|
-
// expect($location.
|
|
3357
|
+
// expect($location.getUrl()).toEqual("/redirectPath");
|
|
2913
3358
|
// expect($browser.url()).toEqual("http://server/#!/redirectPath");
|
|
2914
3359
|
// }));
|
|
2915
3360
|
|
|
@@ -2985,17 +3430,17 @@ describe("$location", () => {
|
|
|
2985
3430
|
// const base = $browser.url();
|
|
2986
3431
|
|
|
2987
3432
|
// $rootScope.$on("$locationChangeStart", () => {
|
|
2988
|
-
// log($location.
|
|
3433
|
+
// log($location.getPath());
|
|
2989
3434
|
// });
|
|
2990
3435
|
|
|
2991
3436
|
// // change through $location service
|
|
2992
3437
|
// $rootScope.$apply(() => {
|
|
2993
|
-
// $location.
|
|
3438
|
+
// $location.setPath("/myNewPath");
|
|
2994
3439
|
// });
|
|
2995
3440
|
|
|
2996
3441
|
// // reset location
|
|
2997
3442
|
// $rootScope.$apply(() => {
|
|
2998
|
-
// $location.
|
|
3443
|
+
// $location.setPath("");
|
|
2999
3444
|
// });
|
|
3000
3445
|
|
|
3001
3446
|
// // change through $browser
|
|
@@ -3007,100 +3452,32 @@ describe("$location", () => {
|
|
|
3007
3452
|
// });
|
|
3008
3453
|
|
|
3009
3454
|
describe("$locationProvider", () => {
|
|
3010
|
-
describe("
|
|
3011
|
-
it("should
|
|
3455
|
+
describe("html5ModeConf", () => {
|
|
3456
|
+
it("should have default values", () => {
|
|
3012
3457
|
module.config(($locationProvider) => {
|
|
3013
|
-
$locationProvider.
|
|
3458
|
+
expect($locationProvider.html5ModeConf).toEqual({
|
|
3014
3459
|
enabled: true,
|
|
3015
3460
|
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
3461
|
rewriteLinks: true,
|
|
3039
3462
|
});
|
|
3040
3463
|
});
|
|
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
|
-
rewriteLinks: true,
|
|
3069
|
-
});
|
|
3070
|
-
});
|
|
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
3464
|
createInjector(["test1"]);
|
|
3085
3465
|
});
|
|
3086
3466
|
});
|
|
3087
3467
|
});
|
|
3088
3468
|
|
|
3089
|
-
describe("
|
|
3469
|
+
describe("Location with html5 url", () => {
|
|
3090
3470
|
let locationUrl;
|
|
3091
3471
|
let locationUmlautUrl;
|
|
3092
3472
|
let locationIndexUrl;
|
|
3093
3473
|
|
|
3094
3474
|
beforeEach(() => {
|
|
3095
|
-
locationUrl = new
|
|
3096
|
-
|
|
3097
|
-
"http://server/pre/",
|
|
3098
|
-
);
|
|
3099
|
-
locationUmlautUrl = new LocationHtml5Url(
|
|
3475
|
+
locationUrl = new Location("http://server/pre/", "http://server/pre/");
|
|
3476
|
+
locationUmlautUrl = new Location(
|
|
3100
3477
|
"http://särver/pre/",
|
|
3101
3478
|
"http://särver/pre/",
|
|
3102
3479
|
);
|
|
3103
|
-
locationIndexUrl = new
|
|
3480
|
+
locationIndexUrl = new Location(
|
|
3104
3481
|
"http://server/pre/index.html",
|
|
3105
3482
|
"http://server/pre/",
|
|
3106
3483
|
);
|
|
@@ -3209,17 +3586,18 @@ describe("$location", () => {
|
|
|
3209
3586
|
// });
|
|
3210
3587
|
|
|
3211
3588
|
it("should support state", () => {
|
|
3212
|
-
expect(locationUrl.
|
|
3589
|
+
expect(locationUrl.setState({ a: 2 }).getState()).toEqual({ a: 2 });
|
|
3213
3590
|
});
|
|
3214
3591
|
});
|
|
3215
3592
|
|
|
3216
|
-
describe("
|
|
3593
|
+
describe("Location with hashbang url", () => {
|
|
3217
3594
|
let locationUrl;
|
|
3218
3595
|
|
|
3219
3596
|
it("should rewrite URL", () => {
|
|
3220
|
-
locationUrl = new
|
|
3597
|
+
locationUrl = new Location(
|
|
3221
3598
|
"http://server/pre/",
|
|
3222
3599
|
"http://server/pre/",
|
|
3600
|
+
false,
|
|
3223
3601
|
"#",
|
|
3224
3602
|
);
|
|
3225
3603
|
|
|
@@ -3239,73 +3617,74 @@ describe("$location", () => {
|
|
|
3239
3617
|
});
|
|
3240
3618
|
|
|
3241
3619
|
it("should not set hash if one was not originally specified", () => {
|
|
3242
|
-
locationUrl = new
|
|
3620
|
+
locationUrl = new Location(
|
|
3243
3621
|
"http://server/pre/index.html",
|
|
3244
3622
|
"http://server/pre/",
|
|
3623
|
+
false,
|
|
3245
3624
|
"#",
|
|
3246
3625
|
);
|
|
3247
3626
|
|
|
3248
|
-
locationUrl
|
|
3249
|
-
expect(locationUrl.
|
|
3250
|
-
expect(locationUrl.absUrl
|
|
3627
|
+
locationUrl.parse("http://server/pre/index.html");
|
|
3628
|
+
expect(locationUrl.getUrl()).toBe("");
|
|
3629
|
+
expect(locationUrl.absUrl).toBe("http://server/pre/index.html");
|
|
3251
3630
|
});
|
|
3252
3631
|
|
|
3253
3632
|
it("should parse hash if one was specified", () => {
|
|
3254
|
-
locationUrl = new
|
|
3633
|
+
locationUrl = new Location(
|
|
3255
3634
|
"http://server/pre/index.html",
|
|
3256
3635
|
"http://server/pre/",
|
|
3636
|
+
false,
|
|
3257
3637
|
"#",
|
|
3258
3638
|
);
|
|
3259
3639
|
|
|
3260
|
-
locationUrl
|
|
3261
|
-
expect(locationUrl.
|
|
3262
|
-
expect(locationUrl.absUrl
|
|
3263
|
-
"http://server/pre/index.html#/foo/bar",
|
|
3264
|
-
);
|
|
3640
|
+
locationUrl.parse("http://server/pre/index.html#/foo/bar");
|
|
3641
|
+
expect(locationUrl.getUrl()).toBe("/foo/bar");
|
|
3642
|
+
expect(locationUrl.absUrl).toBe("http://server/pre/index.html#/foo/bar");
|
|
3265
3643
|
});
|
|
3266
3644
|
|
|
3267
3645
|
it("should prefix hash url with / if one was originally missing", () => {
|
|
3268
|
-
locationUrl = new
|
|
3646
|
+
locationUrl = new Location(
|
|
3269
3647
|
"http://server/pre/index.html",
|
|
3270
3648
|
"http://server/pre/",
|
|
3649
|
+
false,
|
|
3271
3650
|
"#",
|
|
3272
3651
|
);
|
|
3273
3652
|
|
|
3274
|
-
locationUrl
|
|
3275
|
-
|
|
3276
|
-
)
|
|
3277
|
-
expect(locationUrl.url()).toBe("/not-starting-with-slash");
|
|
3278
|
-
expect(locationUrl.absUrl()).toBe(
|
|
3653
|
+
locationUrl.parse("http://server/pre/index.html#not-starting-with-slash");
|
|
3654
|
+
expect(locationUrl.getUrl()).toBe("/not-starting-with-slash");
|
|
3655
|
+
expect(locationUrl.absUrl).toBe(
|
|
3279
3656
|
"http://server/pre/index.html#/not-starting-with-slash",
|
|
3280
3657
|
);
|
|
3281
3658
|
});
|
|
3282
3659
|
|
|
3283
3660
|
it("should not strip stuff from path just because it looks like Windows drive when it's not", () => {
|
|
3284
|
-
locationUrl = new
|
|
3661
|
+
locationUrl = new Location(
|
|
3285
3662
|
"http://server/pre/index.html",
|
|
3286
3663
|
"http://server/pre/",
|
|
3664
|
+
false,
|
|
3287
3665
|
"#",
|
|
3288
3666
|
);
|
|
3289
3667
|
|
|
3290
|
-
locationUrl
|
|
3668
|
+
locationUrl.parse(
|
|
3291
3669
|
"http://server/pre/index.html#http%3A%2F%2Fexample.com%2F",
|
|
3292
3670
|
);
|
|
3293
|
-
expect(locationUrl.
|
|
3294
|
-
expect(locationUrl.absUrl
|
|
3671
|
+
expect(locationUrl.getUrl()).toBe("/http://example.com/");
|
|
3672
|
+
expect(locationUrl.absUrl).toBe(
|
|
3295
3673
|
"http://server/pre/index.html#/http://example.com/",
|
|
3296
3674
|
);
|
|
3297
3675
|
});
|
|
3298
3676
|
|
|
3299
3677
|
it("should allow navigating outside the original base URL", () => {
|
|
3300
|
-
locationUrl = new
|
|
3678
|
+
locationUrl = new Location(
|
|
3301
3679
|
"http://server/pre/index.html",
|
|
3302
3680
|
"http://server/pre/",
|
|
3681
|
+
false,
|
|
3303
3682
|
"#",
|
|
3304
3683
|
);
|
|
3305
3684
|
|
|
3306
|
-
locationUrl
|
|
3307
|
-
expect(locationUrl.
|
|
3308
|
-
expect(locationUrl.absUrl
|
|
3685
|
+
locationUrl.parse("http://server/next/index.html");
|
|
3686
|
+
expect(locationUrl.getUrl()).toBe("");
|
|
3687
|
+
expect(locationUrl.absUrl).toBe("http://server/next/index.html");
|
|
3309
3688
|
});
|
|
3310
3689
|
});
|
|
3311
3690
|
|
|
@@ -3315,7 +3694,7 @@ describe("$location", () => {
|
|
|
3315
3694
|
// const parser = document.createElement("a");
|
|
3316
3695
|
// parser.href = options.initialUrl;
|
|
3317
3696
|
|
|
3318
|
-
// $windowProvider.$get =
|
|
3697
|
+
// $windowProvider.$get = () => {
|
|
3319
3698
|
// const win = {};
|
|
3320
3699
|
// angular.extend(win, window);
|
|
3321
3700
|
// // Ensure `window` is a reference to the mock global object, so that
|
|
@@ -3377,7 +3756,7 @@ describe("$location", () => {
|
|
|
3377
3756
|
// $sniffer,
|
|
3378
3757
|
// $$taskTrackerFactory,
|
|
3379
3758
|
// );
|
|
3380
|
-
// browser.baseHref =
|
|
3759
|
+
// browser.baseHref = () => {
|
|
3381
3760
|
// return options.baseHref;
|
|
3382
3761
|
// };
|
|
3383
3762
|
// return browser;
|
|
@@ -3399,8 +3778,8 @@ describe("$location", () => {
|
|
|
3399
3778
|
}
|
|
3400
3779
|
|
|
3401
3780
|
function parseLinkAndReturn(location, url, relHref) {
|
|
3402
|
-
if (location
|
|
3403
|
-
return location.absUrl
|
|
3781
|
+
if (location.parseLinkUrl(url, relHref)) {
|
|
3782
|
+
return location.absUrl;
|
|
3404
3783
|
}
|
|
3405
3784
|
return undefined;
|
|
3406
3785
|
}
|