]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
bd4cc25058adb2eea63f97659e5de77d28cb272d
[ceph-ci.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { ReactiveFormsModule, Validators } from '@angular/forms';
3
4 import { I18n } from '@ngx-translate/i18n-polyfill';
5 import { PopoverModule } from 'ngx-bootstrap/popover';
6 import { TooltipModule } from 'ngx-bootstrap/tooltip';
7
8 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
9 import { SelectMessages } from '../select/select-messages.model';
10 import { SelectComponent } from '../select/select.component';
11 import { SelectBadgesComponent } from './select-badges.component';
12
13 describe('SelectBadgesComponent', () => {
14   let component: SelectBadgesComponent;
15   let fixture: ComponentFixture<SelectBadgesComponent>;
16
17   configureTestBed({
18     declarations: [SelectBadgesComponent, SelectComponent],
19     imports: [PopoverModule.forRoot(), TooltipModule, ReactiveFormsModule],
20     providers: i18nProviders
21   });
22
23   beforeEach(() => {
24     fixture = TestBed.createComponent(SelectBadgesComponent);
25     component = fixture.componentInstance;
26     fixture.detectChanges();
27   });
28
29   it('should create', () => {
30     expect(component).toBeTruthy();
31   });
32
33   it('should reflect the attributes into CdSelect', () => {
34     const data = ['a', 'b'];
35     const options = [
36       { name: 'option1', description: '', selected: false, enabled: true },
37       { name: 'option2', description: '', selected: false, enabled: true }
38     ];
39     const i18n = TestBed.get(I18n);
40     const messages = new SelectMessages({ empty: 'foo bar' }, i18n);
41     const selectionLimit = 2;
42     const customBadges = true;
43     const customBadgeValidators = [Validators.required];
44
45     component.data = data;
46     component.options = options;
47     component.messages = messages;
48     component.selectionLimit = selectionLimit;
49     component.customBadges = customBadges;
50     component.customBadgeValidators = customBadgeValidators;
51
52     fixture.detectChanges();
53
54     expect(component.cdSelect.data).toEqual(data);
55     expect(component.cdSelect.options).toEqual(options);
56     expect(component.cdSelect.messages).toEqual(messages);
57     expect(component.cdSelect.selectionLimit).toEqual(selectionLimit);
58     expect(component.cdSelect.customBadges).toEqual(customBadges);
59     expect(component.cdSelect.customBadgeValidators).toEqual(customBadgeValidators);
60   });
61 });