This commit is contained in:
parent
e93852a4e1
commit
c895c099c4
|
@ -129,10 +129,10 @@ describe('Background Search Session Management Table', () => {
|
|||
expect(table.find('tbody td').map((node) => node.text())).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"App",
|
||||
"Namevery background search",
|
||||
"StatusIn progress",
|
||||
"Namevery background search ",
|
||||
"StatusExpired",
|
||||
"Created2 Dec, 2020, 00:19:32",
|
||||
"Expiration7 Dec, 2020, 00:19:32",
|
||||
"Expiration--",
|
||||
"",
|
||||
"",
|
||||
]
|
||||
|
|
|
@ -87,6 +87,35 @@ describe('Search Sessions Management API', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('completed session with expired time is showed as expired', async () => {
|
||||
sessionsClient.find = jest.fn().mockImplementation(async () => {
|
||||
return {
|
||||
saved_objects: [
|
||||
{
|
||||
id: 'hello-pizza-123',
|
||||
attributes: {
|
||||
name: 'Veggie',
|
||||
appId: 'pizza',
|
||||
status: 'complete',
|
||||
expires: moment().subtract(3, 'days'),
|
||||
initialState: {},
|
||||
restoreState: {},
|
||||
},
|
||||
},
|
||||
],
|
||||
} as SavedObjectsFindResponse;
|
||||
});
|
||||
|
||||
const api = new SearchSessionsMgmtAPI(sessionsClient, mockConfig, {
|
||||
urls: mockUrls,
|
||||
notifications: mockCoreStart.notifications,
|
||||
application: mockCoreStart.application,
|
||||
});
|
||||
|
||||
const res = await api.fetchTableData();
|
||||
expect(res[0].status).toBe(SearchSessionStatus.EXPIRED);
|
||||
});
|
||||
|
||||
test('handle error from sessionsClient response', async () => {
|
||||
sessionsClient.find = jest.fn().mockRejectedValue(new Error('implementation is so bad'));
|
||||
|
||||
|
|
|
@ -17,12 +17,16 @@ import {
|
|||
} from '../../../../../../../src/plugins/data/public';
|
||||
import { SearchSessionStatus } from '../../../../../../../src/plugins/data/common';
|
||||
import { ACTION } from '../components/actions';
|
||||
import { PersistedSearchSessionSavedObjectAttributes, UISession } from '../types';
|
||||
import {
|
||||
PersistedSearchSessionSavedObjectAttributes,
|
||||
UISearchSessionState,
|
||||
UISession,
|
||||
} from '../types';
|
||||
import { SessionsConfigSchema } from '..';
|
||||
|
||||
type UrlGeneratorsStart = SharePluginStart['urlGenerators'];
|
||||
|
||||
function getActions(status: SearchSessionStatus) {
|
||||
function getActions(status: UISearchSessionState) {
|
||||
const actions: ACTION[] = [];
|
||||
actions.push(ACTION.INSPECT);
|
||||
actions.push(ACTION.RENAME);
|
||||
|
@ -30,9 +34,33 @@ function getActions(status: SearchSessionStatus) {
|
|||
actions.push(ACTION.EXTEND);
|
||||
actions.push(ACTION.DELETE);
|
||||
}
|
||||
|
||||
if (status === SearchSessionStatus.EXPIRED) {
|
||||
actions.push(ACTION.DELETE);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Status we display on mgtm UI might be different from the one inside the saved object
|
||||
* @param status
|
||||
*/
|
||||
function getUIStatus(session: PersistedSearchSessionSavedObjectAttributes): UISearchSessionState {
|
||||
const isSessionExpired = () => {
|
||||
const curTime = moment();
|
||||
return curTime.diff(moment(session.expires), 'ms') > 0;
|
||||
};
|
||||
|
||||
switch (session.status) {
|
||||
case SearchSessionStatus.COMPLETE:
|
||||
case SearchSessionStatus.IN_PROGRESS:
|
||||
return isSessionExpired() ? SearchSessionStatus.EXPIRED : session.status;
|
||||
}
|
||||
|
||||
return session.status;
|
||||
}
|
||||
|
||||
async function getUrlFromState(
|
||||
urls: UrlGeneratorsStart,
|
||||
urlGeneratorId: string,
|
||||
|
@ -59,12 +87,12 @@ const mapToUISession = (urls: UrlGeneratorsStart, config: SessionsConfigSchema)
|
|||
appId,
|
||||
created,
|
||||
expires,
|
||||
status,
|
||||
urlGeneratorId,
|
||||
initialState,
|
||||
restoreState,
|
||||
} = savedObject.attributes;
|
||||
|
||||
const status = getUIStatus(savedObject.attributes);
|
||||
const actions = getActions(status);
|
||||
|
||||
// TODO: initialState should be saved without the searchSessionID
|
||||
|
|
|
@ -25,13 +25,15 @@ export type PersistedSearchSessionSavedObjectAttributes = SearchSessionSavedObje
|
|||
>
|
||||
>;
|
||||
|
||||
export type UISearchSessionState = SearchSessionStatus;
|
||||
|
||||
export interface UISession {
|
||||
id: string;
|
||||
name: string;
|
||||
appId: string;
|
||||
created: string;
|
||||
expires: string | null;
|
||||
status: SearchSessionStatus;
|
||||
status: UISearchSessionState;
|
||||
actions?: ACTION[];
|
||||
reloadUrl: string;
|
||||
restoreUrl: string;
|
||||
|
|
Binary file not shown.
|
@ -33,7 +33,7 @@ export function SearchSessionsPageProvider({ getService, getPageObjects }: FtrPr
|
|||
const viewCell = await row.findByTestSubject('sessionManagementNameCol');
|
||||
const actionsCell = await row.findByTestSubject('sessionManagementActionsCol');
|
||||
return {
|
||||
name: $.findTestSubject('sessionManagementNameCol').text(),
|
||||
name: $.findTestSubject('sessionManagementNameCol').text().trim(),
|
||||
status: $.findTestSubject('sessionManagementStatusLabel').attr('data-test-status'),
|
||||
mainUrl: $.findTestSubject('sessionManagementNameCol').text(),
|
||||
created: $.findTestSubject('sessionManagementCreatedCol').text(),
|
||||
|
|
|
@ -113,68 +113,79 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
|
||||
const searchSessionList = await PageObjects.searchSessionsManagement.getList();
|
||||
expect(searchSessionList.length).to.be(10);
|
||||
expectSnapshot(searchSessionList.map((ss) => [ss.app, ss.name, ss.created, ss.expires]))
|
||||
.toMatchInline(`
|
||||
expectSnapshot(
|
||||
searchSessionList.map((ss) => [ss.app, ss.name, ss.created, ss.expires, ss.status])
|
||||
).toMatchInline(`
|
||||
Array [
|
||||
Array [
|
||||
"graph",
|
||||
"[eCommerce] Orders Test 6 ",
|
||||
"[eCommerce] Orders Test 6",
|
||||
"16 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
"error",
|
||||
],
|
||||
Array [
|
||||
"lens",
|
||||
"[eCommerce] Orders Test 7",
|
||||
"15 Feb, 2021, 00:00:00",
|
||||
"24 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
"expired",
|
||||
],
|
||||
Array [
|
||||
"apm",
|
||||
"[eCommerce] Orders Test 8",
|
||||
"14 Feb, 2021, 00:00:00",
|
||||
"24 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
"expired",
|
||||
],
|
||||
Array [
|
||||
"appSearch",
|
||||
"[eCommerce] Orders Test 9",
|
||||
"13 Feb, 2021, 00:00:00",
|
||||
"24 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
"expired",
|
||||
],
|
||||
Array [
|
||||
"auditbeat",
|
||||
"[eCommerce] Orders Test 10",
|
||||
"12 Feb, 2021, 00:00:00",
|
||||
"24 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
"expired",
|
||||
],
|
||||
Array [
|
||||
"code",
|
||||
"[eCommerce] Orders Test 11",
|
||||
"11 Feb, 2021, 00:00:00",
|
||||
"24 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
"expired",
|
||||
],
|
||||
Array [
|
||||
"console",
|
||||
"[eCommerce] Orders Test 12",
|
||||
"10 Feb, 2021, 00:00:00",
|
||||
"24 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
"expired",
|
||||
],
|
||||
Array [
|
||||
"security",
|
||||
"[eCommerce] Orders Test 5 ",
|
||||
"[eCommerce] Orders Test 5",
|
||||
"9 Feb, 2021, 00:00:00",
|
||||
"24 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
"expired",
|
||||
],
|
||||
Array [
|
||||
"visualize",
|
||||
"[eCommerce] Orders Test 4 ",
|
||||
"[eCommerce] Orders Test 4",
|
||||
"8 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
"cancelled",
|
||||
],
|
||||
Array [
|
||||
"canvas",
|
||||
"[eCommerce] Orders Test 3",
|
||||
"7 Feb, 2021, 00:00:00",
|
||||
"24 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
"expired",
|
||||
],
|
||||
]
|
||||
`);
|
||||
|
@ -201,13 +212,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
"discover",
|
||||
"[eCommerce] Orders Test 2",
|
||||
"6 Feb, 2021, 00:00:00",
|
||||
"24 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
],
|
||||
Array [
|
||||
"dashboard",
|
||||
"[eCommerce] Revenue Dashboard",
|
||||
"5 Feb, 2021, 00:00:00",
|
||||
"24 Feb, 2021, 00:00:00",
|
||||
"--",
|
||||
],
|
||||
]
|
||||
`);
|
||||
|
|
Loading…
Reference in a new issue