|
1 | 1 | import { TestBed } from '@angular/core/testing';
|
| 2 | +import { SimpleChange } from '@angular/core'; |
| 3 | + |
2 | 4 | import { VmsSgListComponent } from './vms-sg-list.component';
|
3 |
| -import { SecurityGroup } from '../../../security-group/sg.model'; |
| 5 | +import { getMockSecurityGroup } from '../../../../testutils/mocks/mocks'; |
4 | 6 |
|
5 | 7 | describe('VmsSgListComponent', () => {
|
6 | 8 | let comp: VmsSgListComponent;
|
7 |
| - const securityGroup = { id: 'sg-1', name: 'name', isPreselected: false } as SecurityGroup; |
8 | 9 |
|
9 | 10 | beforeEach(() => {
|
10 | 11 | TestBed.configureTestingModule({});
|
11 | 12 |
|
12 | 13 | comp = new VmsSgListComponent();
|
13 | 14 | });
|
14 | 15 |
|
15 |
| - it('should select security group', () => { |
16 |
| - comp.selectSecurityGroup(securityGroup); |
17 |
| - expect(comp.currentSelectedSecurityGroup).toBe(securityGroup); |
| 16 | + describe('selectSecurityGroup', () => { |
| 17 | + it('should select security group', () => { |
| 18 | + const securityGroup = getMockSecurityGroup({ id: 'sg-1', isPreselected: false }); |
| 19 | + comp.selectSecurityGroup(securityGroup); |
| 20 | + expect(comp.currentSelectedSecurityGroup).toBe(securityGroup); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should not select preselected security group', () => { |
| 24 | + const securityGroup = getMockSecurityGroup({ id: 'sg-1', isPreselected: true }); |
| 25 | + comp.selectSecurityGroup(securityGroup); |
| 26 | + expect(comp.currentSelectedSecurityGroup).toBeUndefined(); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + describe('ngOnChanges', () => { |
| 31 | + it('should change currentSelectedSecurityGroup', () => { |
| 32 | + const securityGroups = [ |
| 33 | + getMockSecurityGroup({ id: 'first_preselected', isPreselected: true }), |
| 34 | + getMockSecurityGroup({ id: 'first_not_selected', isPreselected: false }), |
| 35 | + getMockSecurityGroup({ id: 'second_not_selected', isPreselected: false }), |
| 36 | + ]; |
| 37 | + comp.securityGroups = securityGroups; |
| 38 | + comp.ngOnChanges({ securityGroups: new SimpleChange(null, securityGroups, false) }); |
| 39 | + expect(comp.currentSelectedSecurityGroup).toEqual(securityGroups[1]); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should not change currentSelectedSecurityGroup if it was selected', () => { |
| 43 | + const securityGroups = [ |
| 44 | + getMockSecurityGroup({ id: 'first_preselected', isPreselected: true }), |
| 45 | + getMockSecurityGroup({ id: 'first_not_selected', isPreselected: false }), |
| 46 | + getMockSecurityGroup({ id: 'second_not_selected', isPreselected: false }), |
| 47 | + ]; |
| 48 | + comp.currentSelectedSecurityGroup = securityGroups[2]; |
| 49 | + comp.securityGroups = securityGroups; |
| 50 | + comp.ngOnChanges({ securityGroups: new SimpleChange([], securityGroups, false) }); |
| 51 | + expect(comp.currentSelectedSecurityGroup).toEqual(securityGroups[2]); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should change currentSelectedSecurityGroup if it not in securityGroups', () => { |
| 55 | + const securityGroups = [ |
| 56 | + getMockSecurityGroup({ id: 'first_preselected', isPreselected: true }), |
| 57 | + getMockSecurityGroup({ id: 'first_not_selected', isPreselected: false }), |
| 58 | + getMockSecurityGroup({ id: 'second_not_selected', isPreselected: false }), |
| 59 | + ]; |
| 60 | + comp.currentSelectedSecurityGroup = getMockSecurityGroup(); |
| 61 | + comp.securityGroups = securityGroups; |
| 62 | + comp.ngOnChanges({ securityGroups: new SimpleChange([], securityGroups, false) }); |
| 63 | + expect(comp.currentSelectedSecurityGroup).toEqual(securityGroups[1]); |
| 64 | + }); |
18 | 65 | });
|
19 | 66 | });
|
0 commit comments