From acf464fbe28344f44e7cf23cce11618f4b68f271 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 25 May 2021 11:49:59 +0200 Subject: [PATCH] MOBILE-3674 tests: Implement url singleton tests --- src/core/singletons/tests/url.test.ts | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/core/singletons/tests/url.test.ts diff --git a/src/core/singletons/tests/url.test.ts b/src/core/singletons/tests/url.test.ts new file mode 100644 index 000000000..c9a7a4f95 --- /dev/null +++ b/src/core/singletons/tests/url.test.ts @@ -0,0 +1,46 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { CoreUrl } from '@singletons/url'; + +describe('CoreUrl singleton', () => { + + it('parses standard urls', () => { + expect(CoreUrl.parse('https://my.subdomain.com/path/?query=search#hash')).toEqual({ + protocol: 'https', + domain: 'my.subdomain.com', + path: '/path/', + query: 'query=search', + fragment: 'hash', + }); + }); + + it('parses domains without TLD', () => { + expect(CoreUrl.parse('ftp://localhost/nested/path')).toEqual({ + protocol: 'ftp', + domain: 'localhost', + path: '/nested/path', + }); + }); + + it('parses ips', () => { + expect(CoreUrl.parse('http://192.168.1.157:8080/')).toEqual({ + protocol: 'http', + domain: '192.168.1.157', + port: '8080', + path: '/', + }); + }); + +});