Closed knownasilya closed 5 years ago
Not that I know of, one way I tested my notifications is to trigger a manual ServiceWorker update in the Google Chrome developer tools in the Application -> ServiceWorkers tab. Not sure if I changed something here as I don't seem to be able to reproduce this in one of my Apps. It would probably nice to be able to trigger this manually somehow..
@topaxi I tried to reproduce just like you said, but not works.
is there a way we can at least have automated tests for this? Like, we could mock the behavior of service-worker registration, and then test the affected UI? I've added ember-concurrency in #3, and that adds enough complexity, where I think tests will be very welcome :)
Assuming you use #3 - I test this in a few applications with an acceptance test. Something like:
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { t } from 'ember-intl/test-support';
import page from '../pages/index';
import config from 'ember-get-config';
module('Acceptance | new build notification', function(hooks) {
setupApplicationTest(hooks);
hooks.beforeEach(function () {
config.environment = 'staging';
window.isUpdateAvailable = new Promise((resolve) => {
resolve(true);
});
});
hooks.afterEach(function () {
config.environment = 'test';
window.isUpdateAvailable = null;
});
test('new build renders when update is available', async function(assert) {
await visit('/');
assert.equal(currentURL(), '/login');
assert.ok(page.build.isVisible, 'see new build notification');
assert.equal(
page.build.text,
t('components.new-build-notifier.text'),
'notification has correct text'
);
assert.ok(page.build.action.isVisible, 'see action to reload');
assert.equal(
page.build.action.text,
t('components.new-build-notifier.action'),
'action button has correct text'
);
});
});
Note that I only enable this notification in staging
and production
environments, hence the config.environment = 'staging';
. The assumption is also that the polling interval is configurable. For production usage, I use 20 minutes, but in the test
environment I cut that down to 1ms.
What I do for an ad-hoc testing locally is to:
ember s -lr false
This is easier when you set a smaller polling interval in the component with <ServiceWorkerUpdateNotify @pollingInterval={{1000}}>
, for example.
Is there a simple way to test this notification without deploying?