superdesk/superdesk-client-core

View on GitHub
e2e/client/specs/saved_search_spec.ts

Summary

Maintainability
A
0 mins
Test Coverage
/* eslint-disable newline-per-chained-call */

import {element, browser, by} from 'protractor';

import {globalSearch} from './helpers/search';
import {nav, waitForSuperdesk, login} from './helpers/utils';
import {LoginModal, logout} from './helpers/pages';
import {ECE} from '@superdesk/end-to-end-testing-helpers';

describe('saved_search', () => {
    beforeEach(() => {
        nav('/search').then(globalSearch.setListView());
    });

    it('can save a private search', () => {
        expect(globalSearch.getItems().count()).toBe(16);
        globalSearch.openFilterPanel();
        globalSearch.toggleSearchTabs('filters');
        expect(globalSearch.getItems().count()).toBe(16);
        expect(globalSearch.getPriorityElements().count()).toBe(3);
        var priority = globalSearch.getPriorityElementByIndex(0);

        priority.click();

        globalSearch.waitForItemCount(1);

        element(by.id('save_search_init')).click();
        var searchPanel = element(by.className('save-search-panel'));

        searchPanel.all(by.id('search_name')).sendKeys('A Search');
        searchPanel.all(by.id('search_description')).sendKeys('Description for search');
        searchPanel.all(by.id('search_save')).click();
        var savedSearch = element.all(by.repeater('search in userSavedSearches')).get(0);

        expect(savedSearch.element(by.css('.search-name')).getText()).toBe('A Search');
    });

    it('can save a global search and another user sees it', () => {
        globalSearch.waitForItemCount(16);
        globalSearch.openFilterPanel();
        globalSearch.toggleSearchTabs('filters');
        globalSearch.waitForItemCount(16);
        browser.wait(ECE.hasElementCount(globalSearch.getPriorityElements(), 3), 2000);
        var priority = globalSearch.getPriorityElementByIndex(0);

        priority.click();
        globalSearch.waitForItemCount(1);
        element(by.id('save_search_init')).click();
        var searchPanel = element(by.className('save-search-panel'));

        searchPanel.all(by.id('search_name')).sendKeys('A Global Search');
        searchPanel.all(by.id('search_description')).sendKeys('Description for search');
        searchPanel.all(by.id('search_global')).click();
        searchPanel.all(by.id('search_save')).click();
        var savedSearch = element.all(by.repeater('search in userSavedSearches')).get(0);

        expect(savedSearch.element(by.css('.search-name')).getText()).toBe('A Global Search [Global]');

        logout();

        var modal = new LoginModal();

        modal.login('admin1', 'admin');

        browser.get('/#/search').then(login('admin1')).then(waitForSuperdesk);
        globalSearch.openFilterPanel();
        browser.sleep(500);

        globalSearch.openSavedSearchTab();
        browser.sleep(200);
        savedSearch = element.all(by.repeater('search in globalSavedSearches')).get(0);
        expect(savedSearch.element(by.css('.search-name')).getText()).toBe('A Global Search by first name last name');
    });
});