Пример #1
0
  ['@test should reset namespace of loading and error routes for mounts with resetNamespace'](assert) {
    Router.map(function() {
      this.route('news', function() {
        this.mount('chat');
        this.mount('blog', { resetNamespace: true });
      });
    });

    let engineInstance = buildOwner({
      ownerOptions: { routable: true }
    });

    let router = Router.create({
      _hasModuleBasedResolver() { return true; }
    });
    setOwner(router, engineInstance);
    router._initRouterJs();

    assert.ok(router._routerMicrolib.recognizer.names['news.chat'], 'nested route was created');
    assert.ok(router._routerMicrolib.recognizer.names['news.chat_loading'], 'nested loading route was added');
    assert.ok(router._routerMicrolib.recognizer.names['news.chat_error'], 'nested error route was added');

    assert.ok(router._routerMicrolib.recognizer.names['blog'], 'reset route was created');
    assert.ok(router._routerMicrolib.recognizer.names['blog_loading'], 'reset loading route was added');
    assert.ok(router._routerMicrolib.recognizer.names['blog_error'], 'reset error route was added');

    assert.ok(!router._routerMicrolib.recognizer.names['news.blog'], 'nested reset route was not created');
    assert.ok(!router._routerMicrolib.recognizer.names['news.blog_loading'], 'nested reset loading route was not added');
    assert.ok(!router._routerMicrolib.recognizer.names['news.blog_error'], 'nested reset error route was not added');
  }
Пример #2
0
QUnit.test('replaceWith considers an engine\'s mountPoint', function() {
  expect(4);

  let router = {
    replaceWith(route) {
      return route;
    }
  };

  let engineInstance = buildOwner({
    ownerOptions: {
      routable: true,
      mountPoint: 'foo.bar'
    }
  });

  let route = EmberRoute.create({ router });
  setOwner(route, engineInstance);

  strictEqual(route.replaceWith('application'), 'foo.bar.application', 'properly prefixes application route');
  strictEqual(route.replaceWith('posts'), 'foo.bar.posts', 'properly prefixes child routes');
  throws(() => route.replaceWith('/posts'), 'throws when trying to use a url');

  let queryParams = {};
  strictEqual(route.replaceWith(queryParams), queryParams, 'passes query param only transitions through');
});
Пример #3
0
  ['@test should allow aliasing of engine names with `as`'](assert) {
    assert.expect(1);

    Router = Router.map(function() {
      this.route('bleep', function() {
        this.route('bloop', function() {
          this.mount('chat', { as: 'blork' });
        });
      });
    });

    let engineInstance = buildOwner({
      ownerOptions: { routable: true }
    });

    let router = Router.create();
    setOwner(router, engineInstance);
    router._initRouterJs();

    assert.deepEqual(
      router._routerMicrolib.recognizer.names['bleep.bloop.blork']
      .segments
      .slice(1, 4)
      .map(s => s.value),
      ['bleep', 'bloop', 'blork'],
      'segments are properly associated with mounted engine with aliased name');
  }
Пример #4
0
QUnit.test('transitionToRoute considers an engine\'s mountPoint', function() {
  expect(4);

  let router = {
    transitionTo(route) {
      return route;
    }
  };

  let engineInstance = buildOwner({
    ownerOptions: {
      routable: true,
      mountPoint: 'foo.bar'
    }
  });

  let controller = Controller.create({ target: router });
  setOwner(controller, engineInstance);

  strictEqual(controller.transitionToRoute('application'), 'foo.bar.application', 'properly prefixes application route');
  strictEqual(controller.transitionToRoute('posts'), 'foo.bar.posts', 'properly prefixes child routes');
  throws(() => controller.transitionToRoute('/posts'), 'throws when trying to use a url');

  let queryParams = {};
  strictEqual(controller.transitionToRoute(queryParams), queryParams, 'passes query param only transitions through');
});
Пример #5
0
  ['@test intermediateTransitionTo considers an engine\'s mountPoint'](assert) {
    let lastRoute;
    let router = {
      intermediateTransitionTo(route) {
        lastRoute = route;
      }
    };

    let engineInstance = buildOwner({
      ownerOptions: {
        routable: true,
        mountPoint: 'foo.bar'
      }
    });

    let route = EmberRoute.create({ router });
    setOwner(route, engineInstance);

    route.intermediateTransitionTo('application');
    assert.strictEqual(lastRoute, 'foo.bar.application', 'properly prefixes application route');

    route.intermediateTransitionTo('posts');
    assert.strictEqual(lastRoute, 'foo.bar.posts', 'properly prefixes child routes');

    assert.throws(() => route.intermediateTransitionTo('/posts'), 'throws when trying to use a url');

    let queryParams = {};
    route.intermediateTransitionTo(queryParams);
    assert.strictEqual(lastRoute, queryParams, 'passes query param only transitions through');
  }
Пример #6
0
QUnit.test('paramsFor considers an engine\'s mountPoint', function(assert) {
  expect(2);

  let router = {
    _deserializeQueryParams() {},
    _routerMicrolib: {
      state: {
        handlerInfos: [
          { name: 'posts' }
        ],
        params: {
          'foo.bar': { a: 'b' },
          'foo.bar.posts': { c: 'd' }
        }
      }
    }
  };

  let engineInstance = buildOwner({
    ownerOptions: {
      routable: true,

      mountPoint: 'foo.bar',

      lookup(name) {
        if (name === 'route:posts') {
          return postsRoute;
        } else if (name === 'route:application') {
          return applicationRoute;
        }
      }
    }
  });

  let applicationRoute = EmberRoute.create({ router, routeName: 'application', fullRouteName: 'foo.bar' });
  let postsRoute = EmberRoute.create({ router, routeName: 'posts', fullRouteName: 'foo.bar.posts' });
  let route = EmberRoute.create({ router });

  setOwner(applicationRoute, engineInstance);
  setOwner(postsRoute, engineInstance);
  setOwner(route, engineInstance);

  assert.deepEqual(route.paramsFor('application'), { a: 'b' }, 'params match for root `application` route in engine');
  assert.deepEqual(route.paramsFor('posts'), { c: 'd' }, 'params match for `posts` route in engine');
});
Пример #7
0
QUnit.test('modelFor considers an engine\'s mountPoint', function() {
  expect(2);

  let applicationModel = { id: '1' };
  let postsModel = { id: '2' };

  let router = {
    _routerMicrolib: {
      activeTransition: {
        resolvedModels: {
          'foo.bar': applicationModel,
          'foo.bar.posts': postsModel
        }
      }
    }
  };

  let engineInstance = buildOwner({
    ownerOptions: {
      routable: true,

      mountPoint: 'foo.bar',

      lookup(name) {
        if (name === 'route:posts') {
          return postsRoute;
        } else if (name === 'route:application') {
          return applicationRoute;
        }
      }
    }
  });

  let applicationRoute = EmberRoute.create({ router, routeName: 'application' });
  let postsRoute = EmberRoute.create({ router, routeName: 'posts' });
  let route = EmberRoute.create({ router });

  setOwner(applicationRoute, engineInstance);
  setOwner(postsRoute, engineInstance);
  setOwner(route, engineInstance);

  strictEqual(route.modelFor('application'), applicationModel);
  strictEqual(route.modelFor('posts'), postsModel);
});
Пример #8
0
  constructor() {
    super();

    let owner = {
      lookup(fullName) {
        return lookupHash[fullName];
      }
    };

    routeOne = EmberRoute.create({ routeName: 'one' });
    routeTwo = EmberRoute.create({ routeName: 'two' });

    setOwner(routeOne, owner);
    setOwner(routeTwo, owner);

    lookupHash = {
      'route:one': routeOne,
      'route:two': routeTwo
    };
  }
Пример #9
0
QUnit.test('An owner can be set with `setOwner` and retrieved with `getOwner`', function() {
  let owner = {};
  let obj = {};

  strictEqual(getOwner(obj), undefined, 'owner has not been set');

  setOwner(obj, owner);

  strictEqual(getOwner(obj), owner, 'owner has been set');

  strictEqual(obj[OWNER], owner, 'owner has been set to the OWNER symbol');
});
Пример #10
0
    ['@test An owner can be set with `setOwner` and retrieved with `getOwner`'](assert) {
      let owner = {};
      let obj = {};

      assert.strictEqual(getOwner(obj), undefined, 'owner has not been set');

      setOwner(obj, owner);

      assert.strictEqual(getOwner(obj), owner, 'owner has been set');

      assert.strictEqual(obj[OWNER], owner, 'owner has been set to the OWNER symbol');
    }
Пример #11
0
function injectionsFor(container, fullName) {
  let registry = container.registry;
  let splitName = fullName.split(':');
  let type = splitName[0];

  let injections = buildInjections(container,
                                   registry.getTypeInjections(type),
                                   registry.getInjections(fullName));
  injections._debugContainerKey = fullName;

  setOwner(injections, container.owner);

  return injections;
}
Пример #12
0
function createRouter(settings, options = {}) {
  let CustomRouter = Router.extend();
  let router = CustomRouter.create(settings);

  if (!options.skipOwner) {
    setOwner(router, owner);
  }

  if (!options.disableSetup) {
    router.setupRouter();
  }

  return router;
}
Пример #13
0
  ['@test modelFor doesn\'t require the router'](assert) {
    let owner = buildOwner();
    setOwner(route, owner);

    let foo = { name: 'foo' };

    let FooRoute = EmberRoute.extend({
      currentModel: foo
    });

    owner.register('route:foo', FooRoute);

    assert.strictEqual(route.modelFor('foo'), foo);
  }
Пример #14
0
QUnit.test('modelFor doesn\'t require the router', function() {
  expect(1);

  let owner = buildOwner();
  setOwner(route, owner);

  let foo = { name: 'foo' };

  let FooRoute = EmberRoute.extend({
    currentModel: foo
  });

  owner.register('route:foo', FooRoute);

  strictEqual(route.modelFor('foo'), foo);
});
Пример #15
0
  create(options = {}) {
    let injectionsCache = this.injections;
    if (injectionsCache === undefined) {
      let { injections, isDynamic } = injectionsFor(this.container, this.normalizedName);
      injectionsCache = injections;
      if (!isDynamic) {
        this.injections = injections;
      }
    }

    let props = assign({}, injectionsCache, options);

    if (DEBUG) {
      let lazyInjections;
      let validationCache = this.container.validationCache;
      // Ensure that all lazy injections are valid at instantiation time
      if (!validationCache[this.fullName] && this.class && typeof this.class._lazyInjections === 'function') {
        lazyInjections = this.class._lazyInjections();
        lazyInjections = this.container.registry.normalizeInjectionsHash(lazyInjections);

        this.container.registry.validateInjections(lazyInjections);
      }

      validationCache[this.fullName] = true;
    }

    if (!this.class.create) {
      throw new Error(`Failed to create an instance of '${this.normalizedName}'. Most likely an improperly defined class or` + ` an invalid module export.`);
    }

    // required to allow access to things like
    // the customized toString, _debugContainerKey,
    // owner, etc. without a double extend and without
    // modifying the objects properties
    if (typeof this.class._initFactory === 'function') {
      this.class._initFactory(this);
    } else {
      // in the non-EmberObject case we need to still setOwner
      // this is required for supporting glimmer environment and
      // template instantiation which rely heavily on
      // `options[OWNER]` being passed into `create`
      // TODO: clean this up, and remove in future versions
      setOwner(props, this.owner);
    }

    return this.class.create(props);
  }
Пример #16
0
  ['@test should not add loading and error routes to a mount if _isRouterMapResult is false'](assert) {
    Router.map(function() {
      this.mount('chat');
    });

    let engineInstance = buildOwner({
      ownerOptions: { routable: true }
    });

    let router = Router.create();
    setOwner(router, engineInstance);
    router._initRouterJs(false);

    assert.ok(router._routerMicrolib.recognizer.names['chat'], 'main route was created');
    assert.ok(!router._routerMicrolib.recognizer.names['chat_loading'], 'loading route was not added');
    assert.ok(!router._routerMicrolib.recognizer.names['chat_error'], 'error route was not added');
  }
Пример #17
0
  ['@test should add loading and error routes to a mount alias if _isRouterMapResult is true'](assert) {
    Router.map(function() {
      this.mount('chat', { as: 'shoutbox' });
    });

    let engineInstance = buildOwner({
      ownerOptions: { routable: true }
    });

    let router = Router.create({
      _hasModuleBasedResolver() { return true; }
    });
    setOwner(router, engineInstance);
    router._initRouterJs();

    assert.ok(router._routerMicrolib.recognizer.names['shoutbox'], 'main route was created');
    assert.ok(router._routerMicrolib.recognizer.names['shoutbox_loading'], 'loading route was added');
    assert.ok(router._routerMicrolib.recognizer.names['shoutbox_error'], 'error route was added');
  }
Пример #18
0
  ['@test should allow mounting of engines'](assert) {
    assert.expect(3);

    Router = Router.map(function() {
      this.route('bleep', function() {
        this.route('bloop', function() {
          this.mount('chat');
        });
      });
    });

    let engineInstance = buildOwner({
      ownerOptions: { routable: true }
    });

    let router = Router.create();
    setOwner(router, engineInstance);
    router._initRouterJs();

    assert.ok(router._routerMicrolib.recognizer.names['bleep'], 'parent name was used as base of nested routes');
    assert.ok(router._routerMicrolib.recognizer.names['bleep.bloop'], 'parent name was used as base of nested routes');
    assert.ok(router._routerMicrolib.recognizer.names['bleep.bloop.chat'], 'parent name was used as base of mounted engine');
  }
Пример #19
0
QUnit.test('default store utilizes the container to acquire the model factory', function() {
  expect(4);

  let Post = EmberObject.extend();
  let post = {};

  Post.reopenClass({
    find(id) {
      return post;
    }
  });

  let ownerOptions = {
    ownerOptions: {
      hasRegistration() {
        return true;
      },
      factoryFor(fullName) {
        equal(fullName, 'model:post', 'correct factory was looked up');

        return {
          class: Post,
          create() {
            return Post.create();
          }
        };
      }
    }
  };

  setOwner(route, buildOwner(ownerOptions));

  route.set('_qp', null);

  equal(route.model({ post_id: 1 }), post);
  equal(route.findModel('post', 1), post, '#findModel returns the correct post');
});
Пример #20
0
    initChildViews(this);
  },

  /**
    Array of child views. You should never edit this array directly.

    @property childViews
    @type Array
    @default []
    @private
  */
  childViews: descriptor({
    configurable: false,
    enumerable: false,
    get() {
      return getChildViews(this);
    }
  }),

  appendChild(view) {
    this.linkChild(view);
    addChildView(this, view);
  },

  linkChild(instance) {
    if (!getOwner(instance)) {
      setOwner(instance, getOwner(this));
    }
  }
});
Пример #21
0
QUnit.test('returns undefined if model is not set', function() {
  equal(route.serialize(undefined, ['post_id']), undefined, 'serialized correctly');
});

QUnit.module('Ember.Route interaction', {
  setup() {
    let owner = {
      lookup(fullName) {
        return lookupHash[fullName];
      }
    };

    routeOne = EmberRoute.create({ routeName: 'one' });
    routeTwo = EmberRoute.create({ routeName: 'two' });

    setOwner(routeOne, owner);
    setOwner(routeTwo, owner);

    lookupHash = {
      'route:one': routeOne,
      'route:two': routeTwo
    };
  },

  teardown() {
    runDestroy(routeOne);
    runDestroy(routeTwo);
  }
});