Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrag1 committed Jul 8, 2022
1 parent 8f07349 commit 2bc4942
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions superset-frontend/src/middleware/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,39 @@ describe('logger middleware', () => {
SupersetClient.post.getCall(0).args[0].postPayload.events,
).toHaveLength(3);
});

it('should use navigator.sendBeacon if it exists', () => {
const clock = sinon.useFakeTimers();
const beaconMock = jest.fn();
Object.defineProperty(navigator, 'sendBeacon', {
writable: true,
value: beaconMock,
});

logger(mockStore)(next)(action);
expect(beaconMock.mock.calls.length).toBe(0);
clock.tick(2000);

expect(beaconMock.mock.calls.length).toBe(1);
const endpoint = beaconMock.mock.calls[0][0];
expect(endpoint).toMatch('/superset/log/');
});

it('should pass a guest token to sendBeacon if present', () => {
const clock = sinon.useFakeTimers();
const beaconMock = jest.fn();
Object.defineProperty(navigator, 'sendBeacon', {
writable: true,
value: beaconMock,
});
SupersetClient.configure({ guestToken: 'token' });

logger(mockStore)(next)(action);
expect(beaconMock.mock.calls.length).toBe(0);
clock.tick(2000);
expect(beaconMock.mock.calls.length).toBe(1);

const formData = beaconMock.mock.calls[0][1];
expect(formData.getAll('guest_token')[0]).toMatch('token');
});
});

0 comments on commit 2bc4942

Please sign in to comment.