Example #1
0
    [`@test Loading actions bubble to root but don't enter substates above pivot `](assert) {
      let sallyDeferred = RSVP.defer();
      let puppiesDeferred = RSVP.defer();

      this.add(
        'route:application',
        Route.extend({
          actions: {
            loading() {
              assert.ok(true, 'loading action received on ApplicationRoute');
            },
          },
        })
      );

      this.add(
        'route:mom.sally',
        Route.extend({
          model() {
            return sallyDeferred.promise;
          },
        })
      );

      this.add(
        'route:grandma.puppies',
        Route.extend({
          model() {
            return puppiesDeferred.promise;
          },
        })
      );

      let promise = this.visit('/grandma/mom/sally');
      assert.equal(this.currentPath, 'index', 'Initial route fully loaded');

      sallyDeferred.resolve();

      promise
        .then(() => {
          assert.equal(this.currentPath, 'grandma.mom.sally', 'transition completed');

          let visit = this.visit('/grandma/puppies');
          assert.equal(
            this.currentPath,
            'grandma.mom.sally',
            'still in initial state because the only loading state is above the pivot route'
          );

          return visit;
        })
        .then(() => {
          this.runTask(() => puppiesDeferred.resolve());

          assert.equal(this.currentPath, 'grandma.puppies', 'Finished transition');
        });

      return promise;
    }
    constructor() {
      super();

      this.aboutDefer = RSVP.defer();
      this.otherDefer = RSVP.defer();
      this.newsDefer = RSVP.defer();
      let _this = this;

      this.router.map(function() {
        this.route('about');
        this.route('other');
        this.route('news');
      });

      this.add(
        'route:about',
        Route.extend({
          model() {
            return _this.aboutDefer.promise;
          },
        })
      );

      this.add(
        'route:other',
        Route.extend({
          model() {
            return _this.otherDefer.promise;
          },
        })
      );

      this.add(
        'route:news',
        Route.extend({
          model() {
            return _this.newsDefer.promise;
          },
        })
      );

      this.addTemplate(
        'application',
        `
      {{outlet}}
      {{link-to 'Index' 'index' id='index-link'}}
      {{link-to 'About' 'about' id='about-link'}}
      {{link-to 'Other' 'other' id='other-link'}}
      {{link-to 'News' 'news' activeClass=false id='news-link'}}
    `
      );
    }
Example #3
0
    async ['@test Default error event moves into nested route'](assert) {
      await this.visit('/');

      this.addTemplate('grandma.error', 'ERROR: {{model.msg}}');

      this.add(
        'route:mom.sally',
        Route.extend({
          model() {
            step(assert, 1, 'MomSallyRoute#model');
            return RSVP.reject({
              msg: 'did it broke?',
            });
          },
          actions: {
            error() {
              step(assert, 2, 'MomSallyRoute#actions.error');
              return true;
            },
          },
        })
      );

      return this.visit('/grandma/mom/sally').then(() => {
        step(assert, 3, 'App finished loading');

        let text = this.$('#app').text();

        assert.equal(text, 'GRANDMA ERROR: did it broke?', 'error bubbles');
        assert.equal(this.currentPath, 'grandma.error', 'Initial route fully loaded');
      });
    }
Example #4
0
    ['@test Enter child loading state of pivot route'](assert) {
      let deferred = RSVP.defer();
      this.addTemplate('grandma.loading', 'GMONEYLOADING');

      this.add(
        'route:mom.sally',
        Route.extend({
          setupController() {
            step(assert, 1, 'SallyRoute#setupController');
          },
        })
      );

      this.add(
        'route:grandma.puppies',
        Route.extend({
          model() {
            return deferred.promise;
          },
        })
      );

      return this.visit('/grandma/mom/sally').then(() => {
        assert.equal(this.currentPath, 'grandma.mom.sally', 'Initial route fully loaded');

        let promise = this.visit('/grandma/puppies').then(() => {
          assert.equal(this.currentPath, 'grandma.puppies', 'Finished transition');
        });

        assert.equal(this.currentPath, 'grandma.loading', `in pivot route's child loading state`);
        deferred.resolve();

        return promise;
      });
    }
Example #5
0
    async ['@test errors that are bubbled are thrown at a higher level if not handled'](assert) {
      await this.visit('/');

      this.add(
        'route:mom.sally',
        Route.extend({
          model() {
            step(assert, 1, 'MomSallyRoute#model');
            return RSVP.reject({
              msg: 'did it broke?',
            });
          },
          actions: {
            error() {
              step(assert, 2, 'MomSallyRoute#actions.error');
              return true;
            },
          },
        })
      );

      await assert.rejects(
        this.visit('/grandma/mom/sally'),
        function(err) {
          return err.msg == 'did it broke?';
        },
        'Correct error was thrown'
      );
    }
Example #6
0
    ['@test Prioritized error substate entry works with preserved-namespaec nested routes'](
      assert
    ) {
      this.addTemplate('foo.bar_error', 'FOOBAR ERROR: {{model.msg}}');
      this.addTemplate('foo.bar', 'YAY');

      this.router.map(function() {
        this.route('foo', function() {
          this.route('bar');
        });
      });

      this.add(
        'route:foo.bar',
        Route.extend({
          model() {
            return RSVP.reject({
              msg: 'did it broke?',
            });
          },
        })
      );

      return this.visit('/').then(() => {
        return this.visit('/foo/bar').then(() => {
          let text = this.$('#app').text();
          assert.equal(
            text,
            'FOOBAR ERROR: did it broke?',
            `foo.bar_error was entered (as opposed to something like foo/foo/bar_error)`
          );
        });
      });
    }
Example #7
0
    [`@test Don't enter loading route unless either route or template defined`](assert) {
      let deferred = RSVP.defer();

      this.router.map(function() {
        this.route('dummy');
      });
      this.add(
        'route:dummy',
        Route.extend({
          model() {
            return deferred.promise;
          },
        })
      );
      this.addTemplate('dummy', 'DUMMY');

      return this.visit('/').then(() => {
        let promise = this.visit('/dummy').then(() => {
          let text = this.$('#app').text();

          assert.equal(text, 'DUMMY', `dummy template has been rendered`);
        });

        assert.ok(
          this.currentPath !== 'loading',
          `
        loading state not entered
      `
        );
        deferred.resolve();

        return promise;
      });
    }
Example #8
0
    ['@test Slow promises returned from ApplicationRoute#model enter application_loading if template present'](
      assert
    ) {
      let appDeferred = RSVP.defer();

      this.addTemplate(
        'application_loading',
        `
      <div id="toplevel-loading">TOPLEVEL LOADING</div>
    `
      );
      this.add(
        'route:application',
        Route.extend({
          model() {
            return appDeferred.promise;
          },
        })
      );

      let promise = this.visit('/').then(() => {
        let length = this.$('#toplevel-loading').length;
        text = this.$('#app').text();

        assert.equal(length, 0, `top-level loading view has been entirely removed from the DOM`);
        assert.equal(text, 'INDEX', 'index has fully rendered');
      });
      let text = this.$('#toplevel-loading').text();

      assert.equal(text, 'TOPLEVEL LOADING', 'still loading the top level');
      appDeferred.resolve();

      return promise;
    }
Example #9
0
    ['@test Slow promises returned from ApplicationRoute#model enter ApplicationLoadingRoute if present'](
      assert
    ) {
      let appDeferred = RSVP.defer();

      this.add(
        'route:application',
        Route.extend({
          model() {
            return appDeferred.promise;
          },
        })
      );
      let loadingRouteEntered = false;
      this.add(
        'route:application_loading',
        Route.extend({
          setupController() {
            loadingRouteEntered = true;
          },
        })
      );

      let promise = this.visit('/').then(() => {
        assert.equal(this.$('#app').text(), 'INDEX', 'index route loaded');
      });
      assert.ok(loadingRouteEntered, 'ApplicationLoadingRoute was entered');
      appDeferred.resolve();

      return promise;
    }
Example #10
0
    async ['@test ApplicationRoute#currentPath reflects loading state path'](assert) {
      await this.visit('/');

      let momDeferred = RSVP.defer();

      this.addTemplate('grandma.loading', 'GRANDMALOADING');

      this.add(
        'route:mom',
        Route.extend({
          model() {
            return momDeferred.promise;
          },
        })
      );

      let promise = runTask(() => this.visit('/grandma/mom')).then(() => {
        text = this.$('#app').text();

        assert.equal(text, 'GRANDMA MOM', `Grandma.mom loaded text is displayed`);
        assert.equal(this.currentPath, 'grandma.mom.index', `currentPath reflects final state`);
      });
      let text = this.$('#app').text();

      assert.equal(text, 'GRANDMA GRANDMALOADING', `Grandma.mom loading text displayed`);

      assert.equal(this.currentPath, 'grandma.loading', `currentPath reflects loading state`);

      momDeferred.resolve();

      return promise;
    }
Example #11
0
    async [`@test Non-bubbled errors that re-throw aren't swallowed`](assert) {
      await this.visit('/');

      this.add(
        'route:mom.sally',
        Route.extend({
          model() {
            return RSVP.reject({
              msg: 'did it broke?',
            });
          },
          actions: {
            error(err) {
              // returns undefined which is falsey
              throw err;
            },
          },
        })
      );

      await assert.rejects(
        this.visit('/grandma/mom/sally'),
        function(err) {
          return err.msg === 'did it broke?';
        },
        'it broke'
      );
    }
Example #12
0
    [`@test Slow promises returned from ApplicationRoute#model don't enter LoadingRoute`](assert) {
      let appDeferred = RSVP.defer();

      this.add(
        'route:application',
        Route.extend({
          model() {
            return appDeferred.promise;
          },
        })
      );
      this.add(
        'route:loading',
        Route.extend({
          setupController() {
            assert.ok(false, `shouldn't get here`);
          },
        })
      );

      let promise = this.visit('/').then(() => {
        let text = this.$('#app').text();

        assert.equal(text, 'INDEX', `index template has been rendered`);
      });

      if (this.element) {
        assert.equal(this.element.textContent, '');
      }

      appDeferred.resolve();

      return promise;
    }
Example #13
0
    [`@test Handled errors that are thrown through rejection aren't swallowed`](assert) {
      let handledError;

      this.add(
        'route:mom.sally',
        Route.extend({
          model() {
            step(assert, 1, 'MomSallyRoute#model');
            return RSVP.reject({
              msg: 'did it broke?',
            });
          },
          actions: {
            error(err) {
              step(assert, 2, 'MomSallyRoute#actions.error');
              handledError = err;
              this.transitionTo('mom.this-route-throws');

              return false;
            },
          },
        })
      );

      this.add(
        'route:mom.this-route-throws',
        Route.extend({
          model() {
            step(assert, 3, 'MomThisRouteThrows#model');
            return RSVP.reject(handledError);
          },
        })
      );

      assert.throws(
        () => {
          this.visit('/grandma/mom/sally');
        },
        function(err) {
          return err.msg === 'did it broke?';
        },
        'it broke'
      );

      return this.runLoopSettled();
    }
    constructor() {
      super();
      this.aboutDefer = RSVP.defer();
      this.otherDefer = RSVP.defer();
      let _this = this;

      this.router.map(function() {
        this.route('parent-route', function() {
          this.route('about');
          this.route('other');
        });
      });
      this.add(
        'route:parent-route.about',
        Route.extend({
          model() {
            return _this.aboutDefer.promise;
          },
        })
      );

      this.add(
        'route:parent-route.other',
        Route.extend({
          model() {
            return _this.otherDefer.promise;
          },
        })
      );

      this.addTemplate(
        'application',
        `
      {{outlet}}
      {{#link-to 'index' tagName='li'}}
        {{link-to 'Index' 'index' id='index-link'}}
      {{/link-to}}
      {{#link-to 'parent-route.about' tagName='li'}}
        {{link-to 'About' 'parent-route.about' id='about-link'}}
      {{/link-to}}
      {{#link-to 'parent-route.other' tagName='li'}}
        {{link-to 'Other' 'parent-route.other' id='other-link'}}
      {{/link-to}}
    `
      );
    }
Example #15
0
    async ['@test Setting a query param during a slow transition should work'](assert) {
      await this.visit('/');

      let deferred = RSVP.defer();
      this.addTemplate('memere.loading', 'MMONEYLOADING');

      this.add(
        'route:grandma',
        Route.extend({
          beforeModel: function() {
            this.transitionTo('memere', 1);
          },
        })
      );

      this.add(
        'route:memere',
        Route.extend({
          queryParams: {
            test: { defaultValue: 1 },
          },
        })
      );

      this.add(
        'route:memere.index',
        Route.extend({
          model() {
            return deferred.promise;
          },
        })
      );

      let promise = runTask(() => this.visit('/grandma')).then(() => {
        assert.equal(this.currentPath, 'memere.index', 'Transition should be complete');
      });
      let memereController = this.getController('memere');

      assert.equal(this.currentPath, 'memere.loading', 'Initial route should be loading');

      memereController.set('test', 3);

      assert.equal(this.currentPath, 'memere.loading', 'Initial route should still be loading');

      assert.equal(
        memereController.get('test'),
        3,
        'Controller query param value should have changed'
      );
      deferred.resolve();

      return promise;
    }
Example #16
0
    ['@test Slow promise from a child route of application enters nested loading state'](assert) {
      let turtleDeferred = RSVP.defer();

      this.router.map(function() {
        this.route('turtle');
      });

      this.add(
        'route:application',
        Route.extend({
          setupController() {
            step(assert, 2, 'ApplicationRoute#setupController');
          },
        })
      );

      this.add(
        'route:turtle',
        Route.extend({
          model() {
            step(assert, 1, 'TurtleRoute#model');
            return turtleDeferred.promise;
          },
        })
      );
      this.addTemplate('turtle', 'TURTLE');
      this.addTemplate('loading', 'LOADING');

      let promise = this.visit('/turtle').then(() => {
        text = this.$('#app').text();
        assert.equal(
          text,
          'TURTLE',
          `turtle template has loaded and replaced the loading template`
        );
      });

      let text = this.$('#app').text();
      assert.equal(
        text,
        'LOADING',
        `The Loading template is nested in application template's outlet`
      );

      turtleDeferred.resolve();
      return promise;
    }
Example #17
0
    async [`@test Handled errors that re-throw aren't swallowed`](assert) {
      await this.visit('/');

      let handledError;

      this.add(
        'route:mom.sally',
        Route.extend({
          model() {
            step(assert, 1, 'MomSallyRoute#model');
            return RSVP.reject({
              msg: 'did it broke?',
            });
          },
          actions: {
            error(err) {
              step(assert, 2, 'MomSallyRoute#actions.error');
              handledError = err;
              this.transitionTo('mom.this-route-throws');

              return false;
            },
          },
        })
      );

      this.add(
        'route:mom.this-route-throws',
        Route.extend({
          model() {
            step(assert, 3, 'MomThisRouteThrows#model');
            throw handledError;
          },
        })
      );

      await assert.rejects(
        this.visit('/grandma/mom/sally'),
        function(err) {
          return err.msg === 'did it broke?';
        },
        `it broke`
      );
    }
Example #18
0
    ['@test Rejected promises returned from ApplicationRoute transition into top-level application_error'](
      assert
    ) {
      let reject = true;

      this.addTemplate('index', '<div id="index">INDEX</div>');
      this.add(
        'route:application',
        Route.extend({
          init() {
            this._super(...arguments);
          },
          model() {
            if (reject) {
              return RSVP.reject({ msg: 'BAD NEWS BEARS' });
            } else {
              return {};
            }
          },
        })
      );

      this.addTemplate(
        'application_error',
        `
      <p id="toplevel-error">TOPLEVEL ERROR: {{model.msg}}</p>
    `
      );

      return this.visit('/')
        .then(() => {
          let text = this.$('#toplevel-error').text();
          assert.equal(text, 'TOPLEVEL ERROR: BAD NEWS BEARS', 'toplevel error rendered');
          reject = false;
        })
        .then(() => {
          return this.visit('/');
        })
        .then(() => {
          let text = this.$('#index').text();
          assert.equal(text, 'INDEX', 'the index route resolved');
        });
    }
Example #19
0
    ['@test Handled errors that bubble can be handled at a higher level'](assert) {
      let handledError;

      this.add(
        'route:mom',
        Route.extend({
          actions: {
            error(err) {
              step(assert, 3, 'MomRoute#actions.error');
              assert.equal(
                err,
                handledError,
                `error handled and rebubbled is handleable at higher route`
              );
            },
          },
        })
      );

      this.add(
        'route:mom.sally',
        Route.extend({
          model() {
            step(assert, 1, 'MomSallyRoute#model');
            return RSVP.reject({
              msg: 'did it broke?',
            });
          },
          actions: {
            error(err) {
              step(assert, 2, 'MomSallyRoute#actions.error');
              handledError = err;

              return true;
            },
          },
        })
      );

      return this.visit('/grandma/mom/sally');
    }
Example #20
0
    ['@test Prioritized loading substate entry works with auto-generated index routes'](assert) {
      let deferred = RSVP.defer();
      this.addTemplate('foo.index_loading', 'FOO LOADING');
      this.addTemplate('foo.index', 'YAY');
      this.addTemplate('foo', '{{outlet}}');

      this.router.map(function() {
        this.route('foo', function() {
          this.route('bar');
        });
      });

      this.add(
        'route:foo.index',
        Route.extend({
          model() {
            return deferred.promise;
          },
        })
      );
      this.add(
        'route:foo',
        Route.extend({
          model() {
            return true;
          },
        })
      );

      let promise = this.visit('/foo').then(() => {
        text = this.$('#app').text();

        assert.equal(text, 'YAY', 'foo.index was rendered');
      });
      let text = this.$('#app').text();
      assert.equal(text, 'FOO LOADING', 'foo.index_loading was entered');

      deferred.resolve();

      return promise;
    }
Example #21
0
    ['@test Prioritized substate entry works with reset-namespace nested routes'](assert) {
      let deferred = RSVP.defer();

      this.addTemplate('bar_loading', 'BAR LOADING');
      this.addTemplate('bar.index', 'YAY');

      this.router.map(function() {
        this.route('foo', function() {
          this.route('bar', { path: '/bar', resetNamespace: true }, function() {});
        });
      });

      this.add(
        'route:bar',
        Route.extend({
          model() {
            return deferred.promise;
          },
        })
      );

      return this.visit('/').then(() => {
        let promise = this.visit('/foo/bar').then(() => {
          text = this.$('#app').text();

          assert.equal(text, 'YAY', 'bar.index fully loaded');
        });

        let text = this.$('#app').text();

        assert.equal(
          text,
          'BAR LOADING',
          `foo.bar_loading was entered (as opposed to something likefoo/foo/bar_loading)`
        );
        deferred.resolve();

        return promise;
      });
    }
Example #22
0
    [`@test Error events that aren't bubbled don't throw application assertions`](assert) {
      this.add(
        'route:mom.sally',
        Route.extend({
          model() {
            step(assert, 1, 'MomSallyRoute#model');
            return RSVP.reject({
              msg: 'did it broke?',
            });
          },
          actions: {
            error(err) {
              step(assert, 2, 'MomSallyRoute#actions.error');
              assert.equal(err.msg, 'did it broke?', `it didn't break`);
              return false;
            },
          },
        })
      );

      return this.visit('/grandma/mom/sally');
    }
Example #23
0
    ['@test Enter loading route only if loadingRoute is defined'](assert) {
      let deferred = RSVP.defer();

      this.router.map(function() {
        this.route('dummy');
      });

      this.add(
        'route:dummy',
        Route.extend({
          model() {
            step(assert, 1, 'DummyRoute#model');
            return deferred.promise;
          },
        })
      );
      this.add(
        'route:loading',
        Route.extend({
          setupController() {
            step(assert, 2, 'LoadingRoute#setupController');
          },
        })
      );
      this.addTemplate('dummy', 'DUMMY');

      return this.visit('/').then(() => {
        let promise = this.visit('/dummy').then(() => {
          let text = this.$('#app').text();

          assert.equal(text, 'DUMMY', `dummy template has been rendered`);
        });

        assert.equal(this.currentPath, 'loading', `loading state entered`);
        deferred.resolve();

        return promise;
      });
    }
Example #24
0
    async ['@test Default error events move into nested route, prioritizing more specifically named error routes - NEW'](
      assert
    ) {
      await this.visit('/');

      this.addTemplate('grandma.error', 'ERROR: {{model.msg}}');
      this.addTemplate('mom_error', 'MOM ERROR: {{model.msg}}');

      this.add(
        'route:mom.sally',
        Route.extend({
          model() {
            step(assert, 1, 'MomSallyRoute#model');
            return RSVP.reject({
              msg: 'did it broke?',
            });
          },
          actions: {
            error() {
              step(assert, 2, 'MomSallyRoute#actions.error');
              return true;
            },
          },
        })
      );

      await this.visit('/grandma/mom/sally');

      step(assert, 3, 'Application finished booting');

      assert.equal(
        this.$('#app').text(),
        'GRANDMA MOM ERROR: did it broke?',
        'the more specifically named mome error substate was entered over the other error route'
      );

      assert.equal(this.currentPath, 'grandma.mom_error', 'Initial route fully loaded');
    }
Example #25
0
    ['@test Prioritized error substate entry works with auto-generated index routes'](assert) {
      this.addTemplate('foo.index_error', 'FOO ERROR: {{model.msg}}');
      this.addTemplate('foo.index', 'YAY');
      this.addTemplate('foo', '{{outlet}}');

      this.router.map(function() {
        this.route('foo', function() {
          this.route('bar');
        });
      });

      this.add(
        'route:foo.index',
        Route.extend({
          model() {
            return RSVP.reject({
              msg: 'did it broke?',
            });
          },
        })
      );
      this.add(
        'route:foo',
        Route.extend({
          model() {
            return true;
          },
        })
      );

      return this.visit('/').then(() => {
        return this.visit('/foo').then(() => {
          let text = this.$('#app').text();

          assert.equal(text, 'FOO ERROR: did it broke?', 'foo.index_error was entered');
        });
      });
    }
Example #26
0
    async ['@test Slow promises waterfall on startup'](assert) {
      await this.visit('/');

      let grandmaDeferred = RSVP.defer();
      let sallyDeferred = RSVP.defer();

      this.addTemplate('loading', 'LOADING');
      this.addTemplate('mom', 'MOM {{outlet}}');
      this.addTemplate('mom.loading', 'MOMLOADING');
      this.addTemplate('mom.sally', 'SALLY');

      this.add(
        'route:grandma',
        Route.extend({
          model() {
            step(assert, 1, 'GrandmaRoute#model');
            return grandmaDeferred.promise;
          },
        })
      );

      this.add(
        'route:mom',
        Route.extend({
          model() {
            step(assert, 2, 'MomRoute#model');
            return {};
          },
        })
      );

      this.add(
        'route:mom.sally',
        Route.extend({
          model() {
            step(assert, 3, 'SallyRoute#model');
            return sallyDeferred.promise;
          },
          setupController() {
            step(assert, 4, 'SallyRoute#setupController');
          },
        })
      );

      let promise = runTask(() => this.visit('/grandma/mom/sally')).then(() => {
        text = this.$('#app').text();

        assert.equal(text, 'GRANDMA MOM SALLY', `Sally template displayed`);
      });
      let text = this.$('#app').text();

      assert.equal(
        text,
        'LOADING',
        `The loading template is nested in application template's outlet`
      );

      runTask(() => grandmaDeferred.resolve());
      text = this.$('#app').text();

      assert.equal(
        text,
        'GRANDMA MOM MOMLOADING',
        `Mom's child loading route is displayed due to sally's slow promise`
      );

      sallyDeferred.resolve();

      return promise;
    }
Example #27
0
    [`@test Ember Islands-style setup`](assert) {
      let xFooInitCalled = false;
      let xFooDidInsertElementCalled = false;

      let xBarInitCalled = false;
      let xBarDidInsertElementCalled = false;

      this.router.map(function() {
        this.route('show', { path: '/:component_name' });
      });

      this.add(
        'route:show',
        Route.extend({
          queryParams: {
            data: { refreshModel: true },
          },

          model(params) {
            return {
              componentName: params.component_name,
              componentData: params.data ? JSON.parse(params.data) : undefined,
            };
          },
        })
      );

      let Counter = EmberObject.extend({
        value: 0,

        increment() {
          this.incrementProperty('value');
        },
      });

      this.add('service:isolatedCounter', Counter);
      this.add('service:sharedCounter', Counter.create());
      this.application.registerOptions('service:sharedCounter', {
        instantiate: false,
      });

      this.addTemplate('show', '{{component model.componentName model=model.componentData}}');

      this.addTemplate(
        'components/x-foo',
        `
      <h1>X-Foo</h1>
      <p>Hello {{model.name}}, I have been clicked {{isolatedCounter.value}} times ({{sharedCounter.value}} times combined)!</p>
    `
      );

      this.add(
        'component:x-foo',
        Component.extend({
          tagName: 'x-foo',

          isolatedCounter: injectService(),
          sharedCounter: injectService(),

          init() {
            this._super();
            xFooInitCalled = true;
          },

          didInsertElement() {
            xFooDidInsertElementCalled = true;
          },

          click() {
            this.get('isolatedCounter').increment();
            this.get('sharedCounter').increment();
          },
        })
      );

      this.addTemplate(
        'components/x-bar',
        `
      <h1>X-Bar</h1>
      <button {{action "incrementCounter"}}>Join {{counter.value}} others in clicking me!</button>
    `
      );

      this.add(
        'component:x-bar',
        Component.extend({
          counter: injectService('sharedCounter'),

          actions: {
            incrementCounter() {
              this.get('counter').increment();
            },
          },

          init() {
            this._super();
            xBarInitCalled = true;
          },

          didInsertElement() {
            xBarDidInsertElementCalled = true;
          },
        })
      );

      let fixtureElement = document.querySelector('#qunit-fixture');
      let foo = document.createElement('div');
      let bar = document.createElement('div');
      fixtureElement.appendChild(foo);
      fixtureElement.appendChild(bar);

      let data = encodeURIComponent(JSON.stringify({ name: 'Godfrey' }));
      let instances = [];

      return RSVP.all([
        this.runTask(() => {
          return this.application.visit(`/x-foo?data=${data}`, {
            rootElement: foo,
          });
        }),
        this.runTask(() => {
          return this.application.visit('/x-bar', { rootElement: bar });
        }),
      ])
        .then(_instances => {
          instances = _instances;

          assert.ok(xFooInitCalled);
          assert.ok(xFooDidInsertElementCalled);

          assert.ok(xBarInitCalled);
          assert.ok(xBarDidInsertElementCalled);

          assert.equal(foo.querySelector('h1').textContent, 'X-Foo');
          assert.equal(
            foo.querySelector('p').textContent,
            'Hello Godfrey, I have been clicked 0 times (0 times combined)!'
          );
          assert.ok(foo.textContent.indexOf('X-Bar') === -1);

          assert.equal(bar.querySelector('h1').textContent, 'X-Bar');
          assert.equal(bar.querySelector('button').textContent, 'Join 0 others in clicking me!');
          assert.ok(bar.textContent.indexOf('X-Foo') === -1);

          this.runTask(() => {
            this.click(foo.querySelector('x-foo'));
          });

          assert.equal(
            foo.querySelector('p').textContent,
            'Hello Godfrey, I have been clicked 1 times (1 times combined)!'
          );
          assert.equal(bar.querySelector('button').textContent, 'Join 1 others in clicking me!');

          this.runTask(() => {
            this.click(bar.querySelector('button'));
            this.click(bar.querySelector('button'));
          });

          assert.equal(
            foo.querySelector('p').textContent,
            'Hello Godfrey, I have been clicked 1 times (3 times combined)!'
          );
          assert.equal(bar.querySelector('button').textContent, 'Join 3 others in clicking me!');
        })
        .finally(() => {
          this.runTask(() => {
            instances.forEach(instance => {
              instance.destroy();
            });
          });
        });
    }
Example #28
0
 testAdapter('errors in promise constructor', error => {
   RSVP.resolve().then(() => {
     throw error;
   });
 })
Example #29
0
 .then(val => {
   assert.equal(val, objectValue, 'can resolve to an object');
   return testHelpers.wait(RSVP.resolve(promiseObjectValue));
 })
    ['@test link-to default query params while in active transition regression test'](assert) {
      this.router.map(function() {
        this.route('foos');
        this.route('bars');
      });
      let foos = RSVP.defer();
      let bars = RSVP.defer();

      this.addTemplate(
        'application',
        `
      {{link-to 'Foos' 'foos' id='foos-link'}}
      {{link-to 'Baz Foos' 'foos' (query-params baz=true) id='baz-foos-link'}}
      {{link-to 'Quux Bars' 'bars' (query-params quux=true) id='bars-link'}}
    `
      );
      this.add(
        'controller:foos',
        Controller.extend({
          queryParams: ['status'],
          baz: false,
        })
      );
      this.add(
        'route:foos',
        Route.extend({
          model() {
            return foos.promise;
          },
        })
      );
      this.add(
        'controller:bars',
        Controller.extend({
          queryParams: ['status'],
          quux: false,
        })
      );
      this.add(
        'route:bars',
        Route.extend({
          model() {
            return bars.promise;
          },
        })
      );

      return this.visit('/').then(() => {
        let router = this.appRouter;
        let foosLink = this.$('#foos-link');
        let barsLink = this.$('#bars-link');
        let bazLink = this.$('#baz-foos-link');

        assert.equal(foosLink.attr('href'), '/foos');
        assert.equal(bazLink.attr('href'), '/foos?baz=true');
        assert.equal(barsLink.attr('href'), '/bars?quux=true');
        assert.equal(router.get('location.path'), '/');
        this.shouldNotBeActive(assert, '#foos-link');
        this.shouldNotBeActive(assert, '#baz-foos-link');
        this.shouldNotBeActive(assert, '#bars-link');

        this.runTask(() => barsLink.click());
        this.shouldNotBeActive(assert, '#bars-link');

        this.runTask(() => foosLink.click());
        this.shouldNotBeActive(assert, '#foos-link');

        this.runTask(() => foos.resolve());

        assert.equal(router.get('location.path'), '/foos');
        this.shouldBeActive(assert, '#foos-link');
      });
    }