Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
richgt committed Jul 19, 2020
1 parent a4bb230 commit 3163b0d
Showing 1 changed file with 67 additions and 6 deletions.
73 changes: 67 additions & 6 deletions tests/router_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,67 @@ scenarios.forEach(function(scenario) {
});
});

test('abort query param only', function(assert) {
assert.expect(6);
map(assert, function(match) {
match('/').to('index');
});

routes = {
search: createHandler('search'),
};

let newParam = false;
let initial = true;

router.updateURL = function(updateUrl) {
url = updateUrl;
if (!initial) {
assert.ok(false, 'updateURL should not be called');
}
};

router.routeWillChange = (transition: Transition) => {
if (!transition.isAborted) {
if (newParam) {
assert.deepEqual(transition.to!.queryParams, { term: 'b' }, 'going to page with qps');
assert.deepEqual(
isPresent(transition.from) && transition.from!.queryParams,
{},
'from never has qps'
);
} else {
assert.equal(transition.from, null);
assert.deepEqual(transition.to!.queryParams, {});
}
}
if (!initial) {
if (!transition.isAborted) {
newParam = false;
transition.abort();
}
}
};

router.routeDidChange = (transition: Transition) => {
if (!transition.isAborted) {
if (newParam) {
assert.deepEqual(transition.to!.queryParams, { term: 'b' });
assert.deepEqual(isPresent(transition.from) && transition.from!.queryParams, {});
} else {
assert.equal(transition.from, null);
assert.deepEqual(transition.to!.queryParams, {});
}
}
};

router.transitionTo('/').then(() => {
newParam = true;
initial = false;
return router.transitionTo({ queryParams: { term: 'b' } });
});
});

test('always has a transition through the substates', function(assert) {
map(assert, function(match) {
match('/').to('index');
Expand Down Expand Up @@ -4511,7 +4572,7 @@ scenarios.forEach(function(scenario) {
});

/* TODO: revisit this idea
test("exceptions thrown from model hooks aren't swallowed", function(assert) {
test("exceptions thrown from model hooks aren't swallowed", function(assert) {
assert.expect(7);
enableErrorHandlingDeferredActionQueue();
Expand Down Expand Up @@ -4548,8 +4609,8 @@ test("exceptions thrown from model hooks aren't swallowed", function(assert) {
flush(anError);
assert.ok(routeWasEntered, "route was finally entered");
});
*/
});
*/

test('Transition#followRedirects() returns a promise that fulfills when any redirecting transitions complete', function(assert) {
assert.expect(3);
Expand Down Expand Up @@ -5148,7 +5209,7 @@ test("exceptions thrown from model hooks aren't swallowed", function(assert) {
});

/* TODO revisit
test("A failed handler's setup shouldn't prevent future transitions", function(assert) {
test("A failed handler's setup shouldn't prevent future transitions", function(assert) {
assert.expect(2);
enableErrorHandlingDeferredActionQueue();
Expand Down Expand Up @@ -5185,8 +5246,8 @@ test("A failed handler's setup shouldn't prevent future transitions", function(a
router.handleURL('/parent/articles');
flush(error);
});
*/
});
*/

test("beforeModel shouldn't be refired with incorrect params during redirect", function(assert) {
// Source: https://github.com/emberjs/ember.js/issues/3407
Expand Down

0 comments on commit 3163b0d

Please sign in to comment.