mirror of
https://github.com/apache/superset.git
synced 2026-04-18 15:44:57 +00:00
feat: alert/report execution log list view (#11937)
This commit is contained in:
@@ -16,17 +16,16 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import thunk from 'redux-thunk';
|
||||
import configureStore from 'redux-mock-store';
|
||||
import fetchMock from 'fetch-mock';
|
||||
import React from 'react';
|
||||
import configureStore from 'redux-mock-store';
|
||||
import thunk from 'redux-thunk';
|
||||
import { styledMount as mount } from 'spec/helpers/theming';
|
||||
|
||||
import AlertList from 'src/views/CRUD/alert/AlertList';
|
||||
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
|
||||
import { Switch } from 'src/common/components/Switch';
|
||||
import ListView from 'src/components/ListView';
|
||||
import SubMenu from 'src/components/Menu/SubMenu';
|
||||
import { Switch } from 'src/common/components/Switch';
|
||||
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
|
||||
import AlertList from 'src/views/CRUD/alert/AlertList';
|
||||
|
||||
// store needed for withToasts(AlertList)
|
||||
const mockStore = configureStore([thunk]);
|
||||
@@ -35,6 +34,7 @@ const store = mockStore({});
|
||||
const alertsEndpoint = 'glob:*/api/v1/report/?*';
|
||||
const alertEndpoint = 'glob:*/api/v1/report/*';
|
||||
const alertsInfoEndpoint = 'glob:*/api/v1/report/_info*';
|
||||
const alertsCreatedByEndpoint = 'glob:*/api/v1/report/related/created_by*';
|
||||
|
||||
const mockalerts = [...new Array(3)].map((_, i) => ({
|
||||
active: true,
|
||||
@@ -74,6 +74,7 @@ fetchMock.get(alertsEndpoint, {
|
||||
fetchMock.get(alertsInfoEndpoint, {
|
||||
permissions: ['can_delete', 'can_edit'],
|
||||
});
|
||||
fetchMock.get(alertsCreatedByEndpoint, { result: [] });
|
||||
fetchMock.put(alertEndpoint, { ...mockalerts[0], active: false });
|
||||
fetchMock.put(alertsEndpoint, { ...mockalerts[0], active: false });
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* 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 fetchMock from 'fetch-mock';
|
||||
import React from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
import configureStore from 'redux-mock-store';
|
||||
import thunk from 'redux-thunk';
|
||||
import { styledMount as mount } from 'spec/helpers/theming';
|
||||
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
|
||||
import ListView from 'src/components/ListView';
|
||||
import ExecutionLog from 'src/views/CRUD/alert/ExecutionLog';
|
||||
|
||||
// store needed for withToasts(ExecutionLog)
|
||||
const mockStore = configureStore([thunk]);
|
||||
const store = mockStore({});
|
||||
|
||||
const executionLogsEndpoint = 'glob:*/api/v1/report/*/log*';
|
||||
const reportEndpoint = 'glob:*/api/v1/report/*';
|
||||
|
||||
fetchMock.delete(executionLogsEndpoint, {});
|
||||
|
||||
const mockannotations = [...new Array(3)].map((_, i) => ({
|
||||
end_dttm: new Date().toISOString,
|
||||
error_message: `report ${i} error message`,
|
||||
id: i,
|
||||
scheduled_dttm: new Date().toISOString,
|
||||
start_dttm: new Date().toISOString,
|
||||
state: 'Success',
|
||||
value: `report ${i} value`,
|
||||
}));
|
||||
|
||||
fetchMock.get(executionLogsEndpoint, {
|
||||
ids: [2, 0, 1],
|
||||
result: mockannotations,
|
||||
count: 3,
|
||||
});
|
||||
|
||||
fetchMock.get(reportEndpoint, {
|
||||
id: 1,
|
||||
result: { name: 'Test 0' },
|
||||
});
|
||||
|
||||
jest.mock('react-router-dom', () => ({
|
||||
...jest.requireActual('react-router-dom'), // use actual for all non-hook parts
|
||||
useParams: () => ({ alertId: '1' }),
|
||||
}));
|
||||
|
||||
async function mountAndWait(props) {
|
||||
const mounted = mount(
|
||||
<Provider store={store}>
|
||||
<ExecutionLog {...props} />
|
||||
</Provider>,
|
||||
);
|
||||
await waitForComponentToPaint(mounted);
|
||||
|
||||
return mounted;
|
||||
}
|
||||
|
||||
describe('ExecutionLog', () => {
|
||||
let wrapper;
|
||||
|
||||
beforeAll(async () => {
|
||||
wrapper = await mountAndWait();
|
||||
});
|
||||
|
||||
it('renders', () => {
|
||||
expect(wrapper.find(ExecutionLog)).toExist();
|
||||
});
|
||||
|
||||
it('renders a ListView', () => {
|
||||
expect(wrapper.find(ListView)).toExist();
|
||||
});
|
||||
|
||||
it('fetches report/alert', () => {
|
||||
const callsQ = fetchMock.calls(/report\/1/);
|
||||
expect(callsQ).toHaveLength(2);
|
||||
expect(callsQ[1][0]).toMatchInlineSnapshot(
|
||||
`"http://localhost/api/v1/report/1"`,
|
||||
);
|
||||
});
|
||||
|
||||
it('fetches execution logs', () => {
|
||||
const callsQ = fetchMock.calls(/report\/1\/log/);
|
||||
expect(callsQ).toHaveLength(1);
|
||||
expect(callsQ[0][0]).toMatchInlineSnapshot(
|
||||
`"http://localhost/api/v1/report/1/log/?q=(order_column:start_dttm,order_direction:desc,page:0,page_size:25)"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user