import * as WHS from '../../index';

/*
 * Ignored methods:
 *
 * - .publish() & .unpublish() - Aliases of .add() and .remove();
 *
 */

const composition = {};
const testValue = {test: true};

const manager = new WHS.ModuleManager(composition);
const module = new WHS.SceneModule();

test('.active()', () => {
  manager.active(module);
  expect(manager.currentModule).toBe(module);
});

test('.add()', () => {
  manager.add('immutable', testValue, {immutable: true, alias: '$testkey'});
  manager.add('overwritable', testValue);

  expect(manager.store.immutable[0]).toBe(testValue);
  expect(composition.$testkey).toBe(testValue);
});

test('.get()', () => {
  expect(manager.get('immutable')).toBe(testValue);
});

test('.set()', () => {
  expect(() => {
    manager.set('immutable', 'newValue');
  })
  .toThrowError('@ModuleManager: Dependency \'immutable\' is immutable and already used by another module');

  manager.set('overwritable', 'newValue');

  expect(manager.store.overwritable[0]).toBe('newValue');
});

test('.update()', () => {
  const update = new Promise((resolve, reject) => {
    manager.update({
      overwritable: () => {
        resolve(true);
      }
    });

    setTimeout(reject, 1);
  });

  manager.set('overwritable', 'check update');

  expect(update).toBeTruthy();
});

test('.has()', () => {
  expect(manager.has('immutable'), 'manager has \'immutable\' dependency').toBeTruthy();
  expect(manager.has('whatever'), 'manager doesn\'t have \'whatever\' dependency').toBeFalsy();
});

test('.remove()', () => {
  manager.remove('immutable');
  manager.remove('overwritable');

  expect(manager.store.immutable).toBe(null);
  expect(manager.store.overwritable).toBe(null);
});

test('.reset()', () => {
  manager.reset();
  expect(manager.currentModule).toBe(null);
});

@@ -34,108 +34,8 @@
 ';%0A%0A
-/*%0A * Ignored methods:%0A *%0A * - .publish() & .unpublish() - Aliases of .add() and .remove();%0A *%0A */%0A%0A
 cons
@@ -288,19 +288,19 @@
 %0Atest('.
-add
+set
 ()', () 
@@ -318,208 +318,28 @@
 ger.
-add('immutable', testValue, %7Bimmutable: true, alias: '$testkey'%7D);%0A  manager.add('overwritable', testValue);%0A%0A  expect(manager.store.immutable%5B0%5D).toBe(testValue);%0A  expect(composition.$testkey).toBe(
+set('overwritable', 
 test
@@ -392,28 +392,31 @@
 anager.get('
-immu
+overwri
 table')).toB
@@ -461,182 +461,8 @@
 %3E %7B%0A
-  expect(() =%3E %7B%0A    manager.set('immutable', 'newValue');%0A  %7D)%0A  .toThrowError('@ModuleManager: Dependency %5C'immutable%5C' is immutable and already used by another module');%0A%0A
   ma
@@ -516,32 +516,46 @@
 t(manager.store.
+getState()%5B0%5D.
 overwritable%5B0%5D)
@@ -550,19 +550,16 @@
 writable
-%5B0%5D
 ).toBe('
@@ -909,360 +909,79 @@
 as('
-immutable'), 'manager has %5C'immutable%5C' dependency').toBeTruthy();%0A  expect(manager.has('whatever'), 'manager doesn%5C't have %5C'whatever%5C' dependency').toBeFalsy();%0A%7D);%0A%0Atest('.remove()', () =%3E %7B%0A  manager.remove('immutable');%0A  manager.remove('overwritable');%0A%0A  expect(manager.store.immutable).toBe(null);%0A  expect(manager.store.overwritable).toBe(null
+whatever'), 'manager doesn%5C't have %5C'whatever%5C' dependency').toBeFalsy(
 );%0A%7D

Fix tests