mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
SIP-32: Moving frontend code to the base of the repo (#9098)
* move assets out, get webpack dev working * update docs to reference superset-frontend * draw the rest of the owl * fix docs * fix webpack script * rats * correct docs * fix tox dox
This commit is contained in:
committed by
GitHub
parent
0cf354cc88
commit
2913063924
112
superset-frontend/spec/javascripts/middleware/logger_spec.js
Normal file
112
superset-frontend/spec/javascripts/middleware/logger_spec.js
Normal file
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import sinon from 'sinon';
|
||||
import { SupersetClient } from '@superset-ui/connection';
|
||||
import logger from '../../../src/middleware/loggerMiddleware';
|
||||
import { LOG_EVENT } from '../../../src/logger/actions';
|
||||
import { LOG_ACTIONS_LOAD_CHART } from '../../../src/logger/LogUtils';
|
||||
|
||||
describe('logger middleware', () => {
|
||||
const next = sinon.spy();
|
||||
const mockStore = {
|
||||
getState: () => ({
|
||||
dashboardInfo: {
|
||||
id: 1,
|
||||
},
|
||||
impressionId: 'impression_id',
|
||||
}),
|
||||
};
|
||||
const action = {
|
||||
type: LOG_EVENT,
|
||||
payload: {
|
||||
eventName: LOG_ACTIONS_LOAD_CHART,
|
||||
eventData: {
|
||||
key: 'value',
|
||||
start_offset: 100,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let postStub;
|
||||
beforeEach(() => {
|
||||
postStub = sinon.stub(SupersetClient, 'post');
|
||||
});
|
||||
afterEach(() => {
|
||||
next.reset();
|
||||
postStub.restore();
|
||||
});
|
||||
|
||||
it('should listen to LOG_EVENT action type', () => {
|
||||
const action1 = {
|
||||
type: 'ACTION_TYPE',
|
||||
payload: {
|
||||
some: 'data',
|
||||
},
|
||||
};
|
||||
logger(mockStore)(next)(action1);
|
||||
expect(next.callCount).toBe(1);
|
||||
});
|
||||
|
||||
it('should POST an event to /superset/log/ when called', () => {
|
||||
const clock = sinon.useFakeTimers();
|
||||
logger(mockStore)(next)(action);
|
||||
expect(next.callCount).toBe(0);
|
||||
|
||||
clock.tick(2000);
|
||||
expect(SupersetClient.post.callCount).toBe(1);
|
||||
expect(SupersetClient.post.getCall(0).args[0].endpoint).toMatch(
|
||||
'/superset/log/',
|
||||
);
|
||||
});
|
||||
|
||||
it('should include ts, start_offset, event_name, impression_id, source, and source_id in every event', () => {
|
||||
const clock = sinon.useFakeTimers();
|
||||
logger(mockStore)(next)(action);
|
||||
clock.tick(2000);
|
||||
|
||||
expect(SupersetClient.post.callCount).toBe(1);
|
||||
const events = SupersetClient.post.getCall(0).args[0].postPayload.events;
|
||||
const mockEventdata = action.payload.eventData;
|
||||
const mockEventname = action.payload.eventName;
|
||||
expect(events[0]).toMatchObject({
|
||||
key: mockEventdata.key,
|
||||
event_name: mockEventname,
|
||||
impression_id: mockStore.getState().impressionId,
|
||||
source: 'dashboard',
|
||||
source_id: mockStore.getState().dashboardInfo.id,
|
||||
event_type: 'timing',
|
||||
});
|
||||
|
||||
expect(typeof events[0].ts).toBe('number');
|
||||
expect(typeof events[0].start_offset).toBe('number');
|
||||
});
|
||||
|
||||
it('should debounce a few log requests to one', () => {
|
||||
const clock = sinon.useFakeTimers();
|
||||
logger(mockStore)(next)(action);
|
||||
logger(mockStore)(next)(action);
|
||||
logger(mockStore)(next)(action);
|
||||
clock.tick(2000);
|
||||
|
||||
expect(SupersetClient.post.callCount).toBe(1);
|
||||
expect(
|
||||
SupersetClient.post.getCall(0).args[0].postPayload.events,
|
||||
).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user