import isAppReady from "../src/actions/isAppReady";

const WAIT = 1000;

describe('isAppReady', () => {
    let resolve;
    beforeEach(() => {
        const promise = new Promise(r => {
            resolve = r;
        });

        window.__components = {
            a: { _dashprivate_isLazyComponentReady: promise },
            b: {}
        };
    });

    it('executes if app is ready', async () => {
        let done = false;
        Promise.resolve(isAppReady(
            [{ namespace: '__components', type: 'b', props: { id: 'comp1' } }],
            { comp1: [0] },
            ['comp1']
        )).then(() => {
            done = true
        });

        await new Promise(r => setTimeout(r, WAIT));
        expect(done).toEqual(true);
    });

    it('waits on app to be ready', async () => {
        let done = false;
        Promise.resolve(isAppReady(
            [{ namespace: '__components', type: 'a', props: { id: 'comp1' } }],
            { comp1: [0] },
            ['comp1']
        )).then(() => {
            done = true
        });

        await new Promise(r => setTimeout(r, WAIT));
        expect(done).toEqual(false);

        resolve();

        await new Promise(r => setTimeout(r, WAIT));
        expect(done).toEqual(true);
    });
});
@@ -547,32 +547,40 @@
 %5D,%0A            %7B
+ strs: %7B
  comp1: %5B0%5D %7D,%0A 
@@ -569,32 +569,44 @@
  %7B comp1: %5B0%5D %7D,
+ objs: %7B%7D %7D,
 %0A            %5B'c
@@ -975,16 +975,24 @@
        %7B
+ strs: %7B
  comp1: 
@@ -997,16 +997,28 @@
 : %5B0%5D %7D,
+ objs: %7B%7D %7D,
 %0A       
@@ -1304,8 +1304,9 @@
  %7D);%0A%7D);
+%0A

fix isAppReady test