|
| 1 | +import { set } from 'ember-metal/property_set'; |
| 2 | +import run from 'ember-metal/run_loop'; |
| 3 | +import NoneLocation from 'ember-routing/location/none_location'; |
| 4 | + |
| 5 | +var NoneTestLocation, location; |
| 6 | + |
| 7 | +function createLocation(options) { |
| 8 | + if (!options) { options = {}; } |
| 9 | + location = NoneTestLocation.create(options); |
| 10 | +} |
| 11 | + |
| 12 | +QUnit.module('Ember.NoneLocation', { |
| 13 | + setup() { |
| 14 | + NoneTestLocation = NoneLocation.extend({}); |
| 15 | + }, |
| 16 | + |
| 17 | + teardown() { |
| 18 | + run(function() { |
| 19 | + if (location) { location.destroy(); } |
| 20 | + }); |
| 21 | + } |
| 22 | +}); |
| 23 | + |
| 24 | +QUnit.test('NoneLocation.formatURL() returns the current url always appending rootURL', function() { |
| 25 | + expect(1); |
| 26 | + |
| 27 | + NoneTestLocation.reopen({ |
| 28 | + init() { |
| 29 | + this._super(...arguments); |
| 30 | + set(this, 'rootURL', '/en/'); |
| 31 | + } |
| 32 | + }); |
| 33 | + |
| 34 | + createLocation(); |
| 35 | + |
| 36 | + equal(location.formatURL('/foo/bar'), '/en/foo/bar'); |
| 37 | +}); |
| 38 | + |
| 39 | +QUnit.test('NoneLocation.getURL() returns the current path minus rootURL', function() { |
| 40 | + expect(1); |
| 41 | + |
| 42 | + NoneTestLocation.reopen({ |
| 43 | + init() { |
| 44 | + this._super(...arguments); |
| 45 | + set(this, 'rootURL', '/foo/'); |
| 46 | + set(this, 'path', '/foo/bar'); |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + createLocation(); |
| 51 | + |
| 52 | + equal(location.getURL(), '/bar'); |
| 53 | +}); |
| 54 | + |
| 55 | +QUnit.test('NonoLocation.getURL() will remove the rootURL only from the beginning of a url', function() { |
| 56 | + expect(1); |
| 57 | + |
| 58 | + NoneTestLocation.reopen({ |
| 59 | + init() { |
| 60 | + this._super(...arguments); |
| 61 | + set(this, 'rootURL', '/bar/'); |
| 62 | + set(this, 'path', '/foo/bar/baz'); |
| 63 | + } |
| 64 | + }); |
| 65 | + |
| 66 | + createLocation(); |
| 67 | + |
| 68 | + equal(location.getURL(), '/foo/bar/baz'); |
| 69 | +}); |
0 commit comments