Skip to content

Commit

Permalink
Merge pull request #36 from Vastra-Gotalandsregionen/readonly_långa_namn
Browse files Browse the repository at this point in the history
Readonly långa namn
  • Loading branch information
sheriffenjohn authored Nov 3, 2017
2 parents 450ebab + e7cbf77 commit 2f0c6ca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<ng-template #readonlyTemplate>
<div class="dropdown__multiselect-readonlylist">
<ul>
<li *ngFor="let selectedItem of selectedItems">{{selectedItem | dropdownItemToSelectedText}}</li>
<li *ngFor="let selectedItem of selectedItems">{{selectedItem | dropdownItemToSelectedText:readonly}}</li>
</ul>
</div>
</ng-template>
4 changes: 2 additions & 2 deletions component-package/controls/dropdown/dropdown.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="validation">
<div class="dropdown" [ngClass]="{'dropdown--open' : expanded, 'dropdown--filter-visible' : filterVisible, 'dropdown--scroll-visible' : scrollVisible}"
(mousedown)="onDropdownMouseDown($event)" (focusout)="onLeave()" (focusin)="onEnter()" tabindex="{{disabled ? -1 : 0}}">
<span tabIndex="0" *ngIf="selectedItem" title="{{selectedItem.displayName}}">{{selectedItem | dropdownItemToSelectedText | truncate:14 }}</span>
<span tabIndex="0" *ngIf="selectedItem" title="{{selectedItem.displayName}}">{{selectedItem | dropdownItemToSelectedText:readonly | truncate:14 }}</span>
<span tabIndex="0" *ngIf="!selectedItem" title="{{noItemSelectedLabel}}">{{noItemSelectedLabel | truncate:14 }}</span>
<div class="dropdown__menu">
<vgr-filter-textbox class="dropdown__filterTextbox" (valueChanged)="filterItems($event)"></vgr-filter-textbox>
Expand All @@ -26,4 +26,4 @@
<div class="validation__status__icon"></div>
<div class="validation__status__message">{{validationErrorMessage | truncate:50}}</div>
</div>
</div>
</div>
7 changes: 3 additions & 4 deletions component-package/pipes/dropdownItemToSelectedTextPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { IDropdownItem } from '../models/dropdownItem.model';
})

export class DropdownItemToSelectedTextPipe implements PipeTransform {
transform(item: IDropdownItem): string {

return item.displayNameWhenSelected ? item.displayNameWhenSelected : item.displayName ? item.displayName : '';
transform(item: IDropdownItem, isReadonly?: boolean): string {
return isReadonly ? item.displayName : item.displayNameWhenSelected ? item.displayNameWhenSelected : item.displayName ? item.displayName : '';
}
}
}
17 changes: 17 additions & 0 deletions tests/pipes/dropdownItemToSelectedTextPipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ import { IDropdownItem } from '../../component-package/models/dropdownItem.model

describe('DropdownItemToSelectedTextPipe', () => {
const dropdownPipe = new DropdownItemToSelectedTextPipe();
describe('When readonly is true', () => {
it('display name is returned', () => {
const result = dropdownPipe.transform(
{ displayName: 'DisplayName', displayNameWhenSelected: 'DisplayNameWhenSelected' } as IDropdownItem
, true);
expect(result).toBe('DisplayName');
});
});
describe('When readonly is false', () => {
it('display name is returned', () => {
const result = dropdownPipe.transform(
{ displayName: 'DisplayName', displayNameWhenSelected: 'DisplayNameWhenSelected' } as IDropdownItem
, false);

expect(result).toBe('DisplayNameWhenSelected');
});
});
describe('When displayNameWhenSelected is undefined', () => {
it('display name is returned', () => {
const result = dropdownPipe.transform(
Expand Down

0 comments on commit 2f0c6ca

Please sign in to comment.