import App from '../../src/models/app';
import Toasts from '../../src/models/toasts';
import { readBootstrapData, documentReady } from '../../src/helpers/dom';
import Raven from '../../src/models/app/raven';

jest.mock('../../src/helpers/dom', () => ({
  readBootstrapData: jest.fn(() => ({ courses: [] })),
  documentReady: jest.fn(() => Promise.resolve()),
}));
jest.mock('../../src/models/app/raven');
jest.mock('../../src/models/toasts', () => ({
  push: jest.fn(),
}));


describe('Tutor App model', () => {
  let app;

  beforeEach(() => app = new App());

  it('sends a toast notice when url changes', () => {
    app.onNotice({ tutor_js_url: 'test.com' });
    expect(app.tutor_js_url).toEqual('test.com');
    expect(Toasts.push).not.toHaveBeenCalled();

    app.onNotice({ tutor_js_url: 'test.com/new-js' });

    expect(app.tutor_js_url).toEqual('test.com');
    expect(Toasts.push).toHaveBeenCalledWith({ handler: 'reload' });
  });

  it('boots after document is ready, starts raven and reads data', async () => {
    await App.boot();
    expect(documentReady).toHaveBeenCalled();
    expect(readBootstrapData).toHaveBeenCalled();
    expect(Raven.boot).toHaveBeenCalled();
  });
});

@@ -592,19 +592,21 @@
 hen 
-url
+assets
  change
-s
 ', (
@@ -637,33 +637,40 @@
 %7B tutor_
-js_url: 'test.com
+assets_hash: 'jasdlkfjla
 ' %7D);%0A  
@@ -680,38 +680,43 @@
 xpect(app.tutor_
-js_url
+assets_hash
 ).toEqual('test.
@@ -706,32 +706,34 @@
 h).toEqual('
-test.com
+jasdlkfjla
 ');%0A    expe
@@ -802,88 +802,172 @@
 tor_
-js_url: 'test.com/new-js' %7D);%0A%0A    expect(app.tutor_js_url).toEqual('test.com');
+assets_hash: 'zjklub' %7D);%0A    // will not update if it's non-null and different%0A    expect(app.tutor_assets_hash).toEqual('jasdlkfjla');%0A    // instead it'll reload
 %0A   

fix spec for assets_hash