Skip to content

Commit

Permalink
Add icons to User Actions Summary SFINT-2374 (#35)
Browse files Browse the repository at this point in the history
* Added icons to recent actions list items SFINT-2374

* Added tests for summary list item icons SFINT-2374

* Added coveo-list-row style class with attributes passed down to direct children SFINT-2374

* Removed overflow css that wasn't being applied SFINT-2374
  • Loading branch information
nathanlb authored and jeremierobert-coveo committed Sep 17, 2019
1 parent dd79a9f commit 5ab73fa
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/components/UserActions/ClickedDocumentList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { UserProfileModel, UserAction } from '../../models/UserProfileModel';
import { ExpandableList } from './ExpandableList';
import { UserActionType } from '../../rest/UserProfilingEndpoint';
import { duplicate } from '../../utils/icons';
import './Strings';

/**
Expand Down Expand Up @@ -70,7 +71,11 @@ export class ClickedDocumentList extends Component {
}),
userId: ComponentOptions.buildStringOption({ required: true }),
template: ComponentOptions.buildTemplateOption({
defaultValue: HtmlTemplate.fromString('<a class="CoveoResultLink"></a>', {
defaultValue: HtmlTemplate.fromString(
`<div class="coveo-list-row">
<div>${duplicate}</div>
<a class="CoveoResultLink" /a>
</div>`, {
layout: 'list'
})
})
Expand Down
12 changes: 11 additions & 1 deletion src/components/UserActions/QueryList.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { Component, IComponentBindings, Initialization, ComponentOptions, get, Omnibox, l } from 'coveo-search-ui';
import { UserProfileModel } from '../../models/UserProfileModel';
import { ExpandableList } from './ExpandableList';
import { search } from '../../utils/icons';
import './Strings';

const DEFAULT_TRANSFORMATION = () => (query: string) => {
const container = document.createElement('div');
container.classList.add('coveo-list-row');

const icon = document.createElement('div');
icon.innerHTML = search;

const span = document.createElement('span');
span.classList.add('coveo-content');
span.innerHTML = query;

return Promise.resolve(span);
container.appendChild(icon);
container.appendChild(span);

return Promise.resolve(container);
};

/**
Expand Down
4 changes: 4 additions & 0 deletions src/components/UserActions/UserActions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ $search-ui-dropdown-header-color: #1d4f76;

li {
margin: 0.25em 0;

.coveo-list-row > * {
display: inline;
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions tests/components/UserActions/ClickedDocumentList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,27 @@ describe('ClickedDocumentList', () => {
});
});

it('should display an icon beside every list item', () => {
sandbox.stub(Initialization, 'automaticallyCreateComponentsInsideResult');

const mock = Mock.advancedComponentSetup<ClickedDocumentList>(
ClickedDocumentList,
new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => {
fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_CLICKS));
return env;
})
);

return delay(() => {
const list = mock.env.element.querySelector<HTMLOListElement>('.coveo-list');

for(let i=0; i<4; i++){
const icon = list.children.item(i).querySelector<HTMLElement>('svg');
expect(icon).toBeDefined;
};
});
});

it('should show all documents when expanded', () => {
sandbox.stub(Initialization, 'automaticallyCreateComponentsInsideResult');

Expand Down
22 changes: 21 additions & 1 deletion tests/components/UserActions/QueryList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ describe('QueryList', () => {
});
});

it('should display a search icon on every list item', () => {
const mock = Mock.advancedComponentSetup<QueryList>(
QueryList,
new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => {
fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_QUERIES));
return env;
})
);

return delay(() => {
const list = mock.env.element.querySelector<HTMLOListElement>('.coveo-list');

for(let i=0; i<4; i++){
const icon = list.children.item(i).querySelector<HTMLElement>('svg');
expect(icon).toBeDefined;
};
})
})

it('should show all queries when expanded', () => {
const mock = Mock.advancedComponentSetup<QueryList>(
QueryList,
Expand Down Expand Up @@ -145,7 +164,8 @@ describe('QueryList', () => {

// Check that the order is respected.
SORTED_AND_TRIMMED_SEARCH_EVENT.forEach((query, i) => {
expect(list.children.item(i).textContent).toBe(query);
const span = list.children.item(i).querySelector<HTMLElement>('.coveo-content');
expect(span.innerText).toBe(query);
});
});
});
Expand Down

0 comments on commit 5ab73fa

Please sign in to comment.