Giter Site home page Giter Site logo

Comments (6)

jonpitch avatar jonpitch commented on May 20, 2024 3

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.

from ember-service-worker-update-notify.

miguelcobain avatar miguelcobain commented on May 20, 2024 1

What I do for an ad-hoc testing locally is to:

  • start a development server with live-reload disabled with ember s -lr false
  • open app
  • make some change on the app to trigger another build
  • wait for the polling to run

This is easier when you set a smaller polling interval in the component with <ServiceWorkerUpdateNotify @pollingInterval={{1000}}>, for example.

from ember-service-worker-update-notify.

NullVoxPopuli avatar NullVoxPopuli commented on May 20, 2024 1

Resolved via: https://github.com/topaxi/ember-service-worker-update-notify#testing-in-your-app

from ember-service-worker-update-notify.

topaxi avatar topaxi commented on May 20, 2024

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..

from ember-service-worker-update-notify.

pablogravielseo avatar pablogravielseo commented on May 20, 2024

@topaxi I tried to reproduce just like you said, but not works.

from ember-service-worker-update-notify.

NullVoxPopuli avatar NullVoxPopuli commented on May 20, 2024

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 :)

from ember-service-worker-update-notify.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.