Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some minor adjustments #12

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/client/client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ export interface ClientEvents {
}

export interface ClientType {
[key: string]: (name: {} | string, data?: string, isRebound?: boolean) => void
[key: string]: (
name: {} | string,
data?: string,
isRebound?: boolean
) => void;
}
50 changes: 26 additions & 24 deletions src/client/client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { Client } from './client';
import { Rebound } from '../rebound/rebound';

describe("Client:", () => {
describe('Client:', () => {
let client: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were you not able to remove this any too ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do then the tests will fail because in typescript you should not be able to access them.

let rebound: any;
let rebound: Rebound;
beforeEach(() => {
client = new Client();
rebound = new Rebound();

rebound.setClient(client);
});

describe("the basic use of this", () => {
it("should have created a client", () => {
describe('the basic use of this', () => {
it('should have created a client', () => {
expect(client).toBeDefined();
});

it("should not be able to set rebound after setting client", () => {
client._rebound._randId = 'test'
it('should not be able to set rebound after setting client', () => {
client._rebound._randId = 'test';
client.setRebound();
expect(client._rebound._randId).toBe('test');
});

it("should be able to set an on event", () => {
it('should be able to set an on event', () => {
client.addEvents('focus');

client.on('focus', () => {
Expand All @@ -37,15 +37,15 @@ describe("Client:", () => {
expect(client._events.focus()).toBe(100);
});

it("should not be able to set an unauthorized event", () => {
it('should not be able to set an unauthorized event', () => {
client.on('notanevent', () => {
return 100;
});

expect(client._events.hasOwnProperty('notanevent')).toBe(false);
});

it("should not be able to set an event after destroying client", () => {
it('should not be able to set an event after destroying client', () => {
expect(client._events).toBeDefined();

client.destroy();
Expand All @@ -59,15 +59,15 @@ describe("Client:", () => {
expect(client._events).toBe(undefined);
});

it("should be able to add a single new possible event", () => {
it('should be able to add a single new possible event', () => {
expect(client._events.hasOwnProperty('testevent')).toBe(false);

client.addEvents('testevent');

expect(client._events.hasOwnProperty('testevent')).toBe(true);
});

it("should be able to add multiple new possible event", () => {
it('should be able to add multiple new possible event', () => {
expect(client._events.hasOwnProperty('testevent')).toBe(false);
expect(client._events.hasOwnProperty('testevent2')).toBe(false);

Expand All @@ -77,9 +77,9 @@ describe("Client:", () => {
expect(client._events.hasOwnProperty('testevent2')).toBe(true);
});

it("should only be able to add strings as new possible event", () => {
it('should only be able to add strings as new possible event', () => {
let numOfKeysBefore = Object.keys(client._events).length;
let eventTypes = [1, [], {}, 1.2, undefined, null, true];
let eventTypes = [1, [], {}, 1.2, undefined, undefined, true];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this null was here as a test case for one of the different types of data that could be thrown at it


expect(client._events.hasOwnProperty('testevent')).toBe(false);

Expand All @@ -99,11 +99,13 @@ describe("Client:", () => {
expect(numOfKeysBefore + 1).toBe(numOfKeysAfter);
});

it("should not be able to overwrite a possible event", () => {
it('should not be able to overwrite a possible event', () => {
expect(client._events.hasOwnProperty('testevent')).toBe(false);

client.addEvents('testevent');
client.on('testevent', function() {});
client.on('testevent', function() {
console.log('testevent');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this so it does not yell at you for having an empty function? because this console.log is not required as it only checking to see if the property is actually there and not what the data is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep just to remove a error

});

expect(client._events.hasOwnProperty('testevent')).toBe(true);
expect(client._events.testevent).toBeDefined();
Expand All @@ -113,15 +115,15 @@ describe("Client:", () => {
expect(client._events.testevent).toBeDefined();
});

it("should not be able to add an empty string as a new possible event", () => {
it('should not be able to add an empty string as a new possible event', () => {
expect(client._events.hasOwnProperty('')).toBe(false);

client.addEvents('');

expect(client._events.hasOwnProperty('')).toBe(false);
});

it("should not be able to add a new possible event after destroying client", () => {
it('should not be able to add a new possible event after destroying client', () => {
expect(client._events).toBeDefined();

client.destroy();
Expand All @@ -130,7 +132,7 @@ describe("Client:", () => {
expect(client._events).toBe(undefined);
});

it("should be able to dispatch an event", () => {
it('should be able to dispatch an event', () => {
client.addEvents('focus');

client.on('focus', () => {
Expand All @@ -141,11 +143,11 @@ describe("Client:", () => {
client.dispatch('focus');
});

it("should not error when not able to dispatch an event", () => {
it('should not error when not able to dispatch an event', () => {
client.dispatch('focus', undefined, true);
});

it("should not be able to dispatch an event after destroying client", () => {
it('should not be able to dispatch an event after destroying client', () => {
expect(client._events).toBeDefined();

client.destroy();
Expand All @@ -159,7 +161,7 @@ describe("Client:", () => {
expect(client._events).toBe(undefined);
});

it("should not be able to dispatch an unauthorized event", () => {
it('should not be able to dispatch an unauthorized event', () => {
client.on('notanevent', () => {
return 100;
});
Expand All @@ -168,7 +170,7 @@ describe("Client:", () => {
client.dispatch('notanevent');
});

it("should be able to remove an event", () => {
it('should be able to remove an event', () => {
client.addEvents(['focus', 'blur']);

client.on('blur', () => {
Expand All @@ -188,13 +190,13 @@ describe("Client:", () => {
expect(client._events.focus).toBe(undefined);
});

it("should not try to remove an event that doesnt exist", () => {
it('should not try to remove an event that doesnt exist', () => {
client.off('notanevent');

expect(client._events.hasOwnProperty('notanevent')).toBe(false);
});

it("should be able to destroy all events", () => {
it('should be able to destroy all events', () => {
client.addEvents('focus');

client.on('focus', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/main.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe("This test", function() {
it("will always pass", function() {
describe('This test', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a comment to this so people know why this is here and that it should not be removed

it('will always pass', function() {
expect(true).toBe(true);
});
});
14 changes: 7 additions & 7 deletions src/rebound/rebound.interface.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Client } from '../client/client';

export interface ReboundEvent {
id?: string,
event: string,
value?: string | number | object
id?: string;
event: string;
value?: string | number | object;
}

export interface ReboundType {
[key: string]: (name: {} | string, data?: string) => void;
}

export interface ReboundConfig {
client: Client,
id?: string,
autoConnect?: boolean
}
client: Client;
id?: string;
autoConnect?: boolean;
}
54 changes: 26 additions & 28 deletions src/rebound/rebound.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Client } from '../client/client';
import { Rebound } from './rebound';


describe("Rebound:", () => {
describe('Rebound:', () => {
let client: any;
let rebound: any;
let testIframe: any;
let windowSpy: any;
let testUrl = 'data:text/html;base64,R0lG';

beforeEach((done) => {
beforeEach(done => {
testIframe = document.createElement('iframe');
testIframe.setAttribute('id', 'testIframe');
testIframe.setAttribute('src', testUrl);
Expand All @@ -19,47 +17,47 @@ describe("Rebound:", () => {
client = new Client();
rebound = new Rebound();
done();
}
};
});

describe("the basic use of this", () => {
it("should have created rebound", () => {
describe('the basic use of this', () => {
it('should have created rebound', () => {
expect(rebound).toBeDefined();
});

it("should not error if the iframe id is not set", () => {
it('should not error if the iframe id is not set', () => {
expect(rebound._iframeId).toBe(undefined);
rebound.setID();
expect(rebound._iframeId).toBe(undefined);
});

it("should be able to set the iframe id", () => {
it('should be able to set the iframe id', () => {
expect(rebound._iframeId).toBe(undefined);
rebound.setID('testIframe');
expect(rebound._iframeId).toBe('testIframe');
});

it("should not error when recieving events without a client", () => {
it('should not error when recieving events without a client', () => {
expect(rebound._randId).toBe(undefined);

rebound.setID('testIframe');

let randId = 'Rebound_' + (Math.random()).toString();
let randId = 'Rebound_' + Math.random().toString();
let init = {
data: {
event: 'connected',
value: 'testvalue',
id: randId
},
origin: '*'
}
};

rebound._onMessage(new MessageEvent('message', init));

expect(rebound._randId).toBe(undefined);
});

it("should not error when recieving events without a rebound id", () => {
it('should not error when recieving events without a rebound id', () => {
expect(rebound._randId).toBe(undefined);

rebound.setID('testIframe');
Expand All @@ -70,14 +68,14 @@ describe("Rebound:", () => {
value: 'testvalue'
},
origin: '*'
}
};

rebound._onMessage(new MessageEvent('message', init));

expect(rebound._randId).toBe(undefined);
});

it("should not dispatch events if ids dont match", () => {
it('should not dispatch events if ids dont match', () => {
expect(rebound._randId).toBe(undefined);

client.addEvents('testevent');
Expand All @@ -92,7 +90,7 @@ describe("Rebound:", () => {
id: 'testid'
},
origin: '*'
}
};

rebound._onMessage(new MessageEvent('message', init));

Expand All @@ -104,7 +102,7 @@ describe("Rebound:", () => {
rebound._onMessage(new MessageEvent('message', init));
});

it("should set rebound id if is undefined and event is connected", () => {
it('should set rebound id if is undefined and event is connected', () => {
expect(rebound._randId).toBe(undefined);

rebound.setID('testIframe');
Expand All @@ -117,53 +115,53 @@ describe("Rebound:", () => {
id: 'testid'
},
origin: '*'
}
};

rebound._onMessage(new MessageEvent('message', init));

expect(rebound._randId).toBe('testid');
});

it("should be able to handle events from child", (done) => {
it('should be able to handle events from child', done => {
expect(rebound._randId).toBe(undefined);

rebound.setID('testIframe');
rebound.setClient(client);
client.addEvents('connected');
client.on('connected', (value: any) => {
client.on('connected', (value: string) => {
expect(value).toEqual('testvalue');
done();
})
});

let randId = 'Rebound_' + (Math.random()).toString();
let randId = 'Rebound_' + Math.random().toString();
let init = {
data: {
event: 'connected',
value: 'testvalue',
id: randId
},
origin: '*'
}
};

rebound._onMessage(new MessageEvent('message', init));

expect(rebound._randId).toEqual(randId);
});

it("should not error if dispatching without client set", () => {
it('should not error if dispatching without client set', () => {
expect(rebound._randId).toBe(undefined);
rebound.setID('testIframe');
rebound.dispatch({event: 'connected'});
rebound.dispatch({ event: 'connected' });
expect(rebound._randId).toBeDefined();
});

it("should not dispatch without a reciever set", () => {
it('should not dispatch without a reciever set', () => {
expect(rebound._randId).toBe(undefined);
rebound.dispatch({event: 'connected'});
rebound.dispatch({ event: 'connected' });
expect(rebound._randId).toBe(undefined);
});

it("should not add client if client is not passed in", () => {
it('should not add client if client is not passed in', () => {
expect(rebound._client).toBe(undefined);
rebound.setClient();
expect(rebound._client).toBe(undefined);
Expand Down
Loading