Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
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
191 changes: 191 additions & 0 deletions metron-interface/metron-alerts/e2e/alerts-list/alerts-list.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,195 @@ describe('metron-alerts App', function() {

});

it('should have all time-range controls', () => {
let quickRanges = [
'Last 7 days', 'Last 30 days', 'Last 60 days', 'Last 90 days', 'Last 6 months', 'Last 1 year', 'Last 2 years', 'Last 5 years',
'Yesterday', 'Day before yesterday', 'This day last week', 'Previous week', 'Previous month', 'Previous year', 'All time',
'Today', 'Today so far', 'This week', 'This week so far', 'This month', 'This year',
'Last 5 minutes', 'Last 15 minutes', 'Last 30 minutes', 'Last 1 hour', 'Last 3 hours', 'Last 6 hours', 'Last 12 hours', 'Last 24 hours'
];

page.clickDateSettings();
expect(page.getTimeRangeTitles()).toEqual(['Time Range', 'Quick Ranges']);
expect(page.getQuickTimeRanges()).toEqual(quickRanges);
expect(page.getValueForManualTimeRange()).toEqual([ 'now', 'now' ]);
expect(page.isManulaTimeRangeApplyButtonPresent()).toEqual(true);
expect(page.getTimeRangeButtonText()).toEqual('All time');
page.clickDateSettings();

});

it('should have all time range values populated - 1', () => {
let secInADay = (24 * 60 * 60 * 1000);

page.clickClearSearch();
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz(['All time'], 'for all-time');

page.clickDateSettings();
page.selectQuickTimeRange('Last 7 days');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz(['Last 7 days', String(secInADay * 7)], 'for last 7 days');

page.clickDateSettings();
page.selectQuickTimeRange('Last 30 days');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz(['Last 30 days', String(secInADay * 30)], 'for last 30 days');

page.clickDateSettings();
page.selectQuickTimeRange('Last 60 days');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz(['Last 60 days', String(secInADay * 60)], 'for last 60 days');

page.clickDateSettings();
page.selectQuickTimeRange('Last 90 days');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz(['Last 90 days', String(secInADay * 90)], 'for last 90 days');


page.clickDateSettings();
page.selectQuickTimeRange('Last 1 year');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz(['Last 1 year', String(secInADay * 365)], 'for last 1 year');

page.clickDateSettings();
page.selectQuickTimeRange('Last 2 years');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz(['Last 2 years', String((secInADay * 365 * 2) + secInADay)], 'for last 2 years');

page.clickDateSettings();
page.selectQuickTimeRange('Last 5 years');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz(['Last 5 years', String((secInADay * 365 * 5) + secInADay)], 'for last 5 years');

page.clickClearSearch();
});

it('should have all time range values populated - 2', () => {
let secInADay = (24*60*60*1000);

page.clickDateSettings();
page.selectQuickTimeRange('Yesterday');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Yesterday', String(secInADay - 1000)], 'yesterday');

page.clickDateSettings();
page.selectQuickTimeRange('Day before yesterday');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Day before yesterday', String(secInADay - 1000)], 'day before yesterday');

page.clickDateSettings();
page.selectQuickTimeRange('This day last week');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'This day last week', String(secInADay - 1000)], 'this day last week');

page.clickDateSettings();
page.selectQuickTimeRange('Previous week');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Previous week', String((secInADay * 7) - (1000))], 'for previous week');

page.clickClearSearch();
});

it('should have all time range values populated - 3', () => {
let secInADay = (24*60*60*1000);

page.clickDateSettings();
page.selectQuickTimeRange('Today');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Today', String(secInADay - 1000)], 'for today');

page.clickDateSettings();
page.selectQuickTimeRange('This week');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'This week', String((secInADay*7) - 1000)], 'for this week');

page.clickClearSearch();
});

it('should have all time range values populated - 4', () => {
let secInADay = (24*60*60*1000);

page.clickDateSettings();
page.selectQuickTimeRange('Last 5 minutes');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Last 5 minutes', String(5 * 60 * 1000)], 'for last 5 minutes');

page.clickDateSettings();
page.selectQuickTimeRange('Last 15 minutes');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Last 15 minutes', String(15 * 60 * 1000)], 'for last 15 minutes');

page.clickDateSettings();
page.selectQuickTimeRange('Last 30 minutes');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Last 30 minutes', String(30 * 60 * 1000)], 'for last 30 minutes');

page.clickDateSettings();
page.selectQuickTimeRange('Last 1 hour');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Last 1 hour', String(60 * 60 * 1000)], 'for last 1 hour');

page.clickDateSettings();
page.selectQuickTimeRange('Last 3 hours');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Last 3 hours', String(3 * 60 * 60 * 1000)], 'for last 3 hours');

page.clickDateSettings();
page.selectQuickTimeRange('Last 6 hours');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Last 6 hours', String(6 * 60 * 60 * 1000)], 'for last 6 hours');

page.clickDateSettings();
page.selectQuickTimeRange('Last 12 hours');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Last 12 hours', String(12 * 60 * 60 * 1000)], 'for last 12 hours');

page.clickDateSettings();
page.selectQuickTimeRange('Last 24 hours');
expect(page.getTimeRangeButtonAndSubText()).toEqualBcoz([ 'Last 24 hours', String(24 * 60 * 60 * 1000)], 'for last 24 hours');

page.clickClearSearch();
});

it('should disable date picker when timestamp is present in search', () => {
page.clickTableText('2017-09-13 18:02:20');
expect(page.isDateSeettingDisabled()).toEqual(true);

page.clickClearSearch();
expect(page.isDateSeettingDisabled()).toEqual(false);

page.clickTableText('alerts_ui_e2e');
expect(page.isDateSeettingDisabled()).toEqual(false);

page.clickClearSearch();
});

it('should have now included when to date is empty', () => {
page.clickDateSettings();
page.setDate(0, '2017', 'September', '13', '23', '29', '35');
page.selectTimeRangeApplyButton();
expect(page.getTimeRangeButtonTextForNow()).toEqual([ 'Date Range', '2017-09-13 23:29:35 to now' ]);

page.clickClearSearch();
});

it('should have all time-range included while searching', () => {
page.clearLocalStorage();
page.clickDateSettings();

/* Select Last 5years for time range */
page.selectQuickTimeRange('Last 5 years');
expect(page.getTimeRangeButtonText()).toEqual('Last 5 years');

/* Select custom date for time range */
page.clickDateSettings();
page.setDate(0, '2017', 'September', '13', '23', '29', '35');
page.setDate(1, '2017', 'September', '13', '23', '29', '40');
page.selectTimeRangeApplyButton();
expect(page.getChangesAlertTableTitle('Alerts (169)')).toEqual('Alerts (5)');

/* Save custom date in saved searches */
page.saveSearch('e2e-2');
page.clickSavedSearch();
expect(page.getRecentSearchOptions()).toContain('timestamp:last-5-years', 'for recent search options');
expect(page.getSavedSearchOptions()).toEqual(['e2e-2'],
'for saved search options');
page.clickCloseSavedSearch();

/* Clear Search should should show all rows */
page.clickClearSearch();
expect(page.getChangesAlertTableTitle('Alerts (5)')).toEqual('Alerts (169)');

/* Load the saved search */
page.clickSavedSearch();
page.loadSavedSearch('e2e-2');
expect(page.getChangesAlertTableTitle('Alerts (169)')).toEqual('Alerts (5)');

/* Load recent search */
page.clickSavedSearch();
page.loadRecentSearch('last-5-years');
expect(page.getChangesAlertTableTitle('Alerts (5)')).toEqual('Alerts (169)');

});

});
138 changes: 118 additions & 20 deletions metron-interface/metron-alerts/e2e/alerts-list/alerts-list.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import {browser, element, by, protractor} from 'protractor';
import {waitForElementVisibility, waitForElementPresence} from '../utils/e2e_util';
import {waitForElementVisibility, waitForElementPresence, waitForElementInVisibility} from '../utils/e2e_util';

export class MetronAlertsPage {
navigateTo() {
Expand Down Expand Up @@ -124,7 +124,7 @@ export class MetronAlertsPage {
}

getSettingsLabels() {
return element.all(by.css('form label:not(.switch)')).getText();
return element.all(by.css('app-configure-rows form label:not(.switch)')).getText();
}

getRefreshRateOptions() {
Expand Down Expand Up @@ -152,12 +152,14 @@ export class MetronAlertsPage {
}

clickConfigureTable() {
element(by.css('app-alerts-list .fa.fa-cog.configure-table-icon')).click();
let gearIcon = element(by.css('app-alerts-list .fa.fa-cog.configure-table-icon'));
waitForElementVisibility(gearIcon).then(() => gearIcon.click());
browser.sleep(1000);
}

clickCloseSavedSearch() {
element(by.css('app-saved-searches .close-button')).click();
browser.sleep(2000);
}

clickSavedSearch() {
Expand All @@ -170,7 +172,7 @@ export class MetronAlertsPage {
}

clickTableText(name: string) {
waitForElementPresence(element.all(by.css('app-table-view tbody tr'))).then(() => element.all(by.linkText(name)).get(0).click());
waitForElementPresence(element.all(by.css('app-table-view tbody tr a'))).then(() => element.all(by.linkText(name)).get(0).click());
}

clickClearSearch() {
Expand All @@ -195,26 +197,22 @@ export class MetronAlertsPage {

getRecentSearchOptions() {
browser.sleep(1000);
let map = {};
let recentSearches = element.all(by.css('app-saved-searches metron-collapse')).get(0);
return recentSearches.all(by.css('a')).getText().then(title => {
return recentSearches.all(by.css('.collapse.show')).getText().then(values => {
map[title] = values;
return map;
});
});
return element(by.linkText('Recent Searches')).element(by.xpath('..')).all(by.css('li')).getText();
}

getDefaultRecentSearchValue() {
browser.sleep(1000);
return element(by.linkText('Recent Searches')).element(by.xpath('..')).all(by.css('i')).getText();
}

getSavedSearchOptions() {
browser.sleep(1000);
let map = {};
let recentSearches = element.all(by.css('app-saved-searches metron-collapse')).get(1);
return recentSearches.all(by.css('a')).getText().then(title => {
return recentSearches.all(by.css('.collapse.show')).getText().then(values => {
map[title] = values;
return map;
});
});
return element(by.linkText('Saved Searches')).element(by.xpath('..')).all(by.css('li')).getText();
}

getDefaultSavedSearchValue() {
browser.sleep(1000);
return element(by.linkText('Saved Searches')).element(by.xpath('..')).all(by.css('i')).getText();
}

getSelectedColumnNames() {
Expand Down Expand Up @@ -288,8 +286,108 @@ export class MetronAlertsPage {
});
}

isDateSeettingDisabled() {
return element.all(by.css('app-time-range button.btn.btn-search[disabled=""]')).count().then((count) => { return (count === 1); });
}

clickDateSettings() {
element(by.css('app-time-range button.btn-search')).click();
browser.sleep(2000);
}

getTimeRangeTitles() {
return element.all(by.css('app-time-range .title')).getText();
}

getQuickTimeRanges() {
return element.all(by.css('app-time-range .quick-ranges span')).getText();
}

getValueForManualTimeRange() {
return element.all(by.css('app-time-range input.form-control')). getAttribute('value');
}

isManulaTimeRangeApplyButtonPresent() {
return element.all(by.css('app-time-range')).all(by.buttonText('APPLY')).count().then(count => count === 1);
}

selectQuickTimeRange(quickRange: string) {
element.all(by.cssContainingText('.quick-ranges span', quickRange)).get(0).click();
browser.sleep(2000);
}

getTimeRangeButtonText() {
return element.all(by.css('app-time-range button.btn-search span')).get(0).getText();
}

setDate(index: number, year: string, month: string, day: string, hour: string, min: string, sec: string) {
element.all(by.css('app-time-range .calendar')).get(index).click()
.then(() => element.all(by.css('.pika-select.pika-select-hour')).get(index).click())
.then(() => element.all(by.css('.pika-select.pika-select-hour')).get(index).element(by.cssContainingText('option', hour)).click())
.then(() => element.all(by.css('.pika-select.pika-select-minute')).get(index).click())
.then(() => element.all(by.css('.pika-select.pika-select-minute')).get(index).element(by.cssContainingText('option', min)).click())
.then(() => element.all(by.css('.pika-select.pika-select-second')).get(index).click())
.then(() => element.all(by.css('.pika-select.pika-select-second')).get(index).element(by.cssContainingText('option', sec)).click())
.then(() => element.all(by.css('.pika-select.pika-select-year')).get(index).click())
.then(() => element.all(by.css('.pika-select.pika-select-year')).get(index).element(by.cssContainingText('option', year)).click())
.then(() => element.all(by.css('.pika-select.pika-select-month')).get(index).click())
.then(() => element.all(by.css('.pika-select.pika-select-month')).get(index).element(by.cssContainingText('option', month)).click())
.then(() => element.all(by.css('.pika-table')).get(index).element(by.buttonText(day)).click())
.then(() => waitForElementInVisibility(element.all(by.css('.pika-single')).get(index)));

browser.sleep(1000);
}

selectTimeRangeApplyButton() {
return element(by.css('app-time-range')).element(by.buttonText('APPLY')).click();
}

getChangesAlertTableTitle(previousText: string) {
// browser.pause();
let title = element(by.css('.col-form-label-lg'));
return this.waitForTextChange(title, previousText).then(() => {
return title.getText();
});
}

getAlertStatusById(id: string) {
return element(by.css('a[title="' + id +'"]'))
.element(by.xpath('../..')).all(by.css('td a')).get(8).getText();
}

loadSavedSearch(name: string) {
element.all(by.css('app-saved-searches metron-collapse')).get(1).element(by.css('li[title="'+ name +'"]')).click();
browser.sleep(1000);
}

loadRecentSearch(name: string) {
element.all(by.css('app-saved-searches metron-collapse')).get(0).all(by.css('li')).get(2).click();
browser.sleep(1000);
}

getTimeRangeButtonTextForNow() {
return element.all(by.css('app-time-range button span')).getText();
}

getTimeRangeButtonAndSubText() {
return waitForElementInVisibility(element(by.css('#time-range')))
.then(() => element.all(by.css('app-time-range button span')).getText())
.then(arr => {
let retArr = [arr[0]];
for (let i=1; i < arr.length; i++) {
let dateStr = arr[i].split(' to ');
let fromTime = new Date(dateStr[0]).getTime();
let toTime = new Date(dateStr[1]).getTime();
retArr.push((toTime - fromTime) + '');
}
return retArr;
});
}

renameColumn(name: string, value: string) {
element(by.cssContainingText('app-configure-table span', name))
.element(by.xpath('../..'))
.element(by.css('.input')).sendKeys(value);
}

}
Loading