Skip to content

Commit

Permalink
fix: add conditional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aklkv committed Nov 3, 2023
1 parent c8612c1 commit 1697113
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@ember/optional-features": "^2.0.0",
"@ember/string": "^3.1.1",
"@ember/test-helpers": "^2.9.3",
"@embroider/macros": "^1.13.2",
"@embroider/test-setup": "^2.0.2",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
Expand Down
52 changes: 40 additions & 12 deletions test-app/tests/acceptance/routeable-engine-demo-refresh-test.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,71 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit, find, click } from '@ember/test-helpers';
import { macroCondition, dependencySatisfies } from '@embroider/macros';

module('Acceptance | Engine Router Service | Refresh Method', function (hooks) {
setupApplicationTest(hooks);

test('refresh without params triggers refresh with current route', async function (assert) {
assert.expect(1);

await visit('/routable-engine-demo/ember-blog/new');

let counter = await find('.route-refresh-counter').textContent;
await click('.refresh');

counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.route-refresh-counter').hasText(counter);
if (macroCondition(dependencySatisfies('ember-source', '>= 4.1.0'))) {
counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.route-refresh-counter').hasText(counter);
} else {
// eslint-disable-next-line qunit/no-conditional-assertions
assert.throws(
'Refresh method is not available in ember-source below v4.1'
);
}
});

test('refresh with params triggers refresh on provided route', async function (assert) {
assert.expect(1);

await visit('/routable-engine-demo/ember-blog/new');

let counter = await find('.route-refresh-counter').textContent;
await click('.refresh-route');

counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.route-refresh-counter').hasText(counter);
if (macroCondition(dependencySatisfies('ember-source', '>= 4.1.0'))) {
counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.route-refresh-counter').hasText(counter);
} else {
// eslint-disable-next-line qunit/no-conditional-assertions
assert.throws(
'Refresh method is not available in ember-source below v4.1'
);
}
});

test('refresh external route', async function (assert) {
assert.expect(1);

await visit('/routable-engine-demo/ember-blog/new');

let counter = await find('.route-refresh-counter').textContent;
await click('.refresh-external');

counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.global-refresh-counter').hasText(counter);
if (macroCondition(dependencySatisfies('ember-source', '>= 4.1.0'))) {
counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.global-refresh-counter').hasText(counter);
} else {
// eslint-disable-next-line qunit/no-conditional-assertions
assert.throws(
'Refresh method is not available in ember-source below v4.1'
);
}
});
});

0 comments on commit 1697113

Please sign in to comment.