This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(security-group): select first not preselected sg (#595)
- Loading branch information
Showing
3 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
57 changes: 52 additions & 5 deletions
57
src/app/vm/vm-sidebar/vms-sg-list/vms-sg-list.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,66 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { SimpleChange } from '@angular/core'; | ||
|
||
import { VmsSgListComponent } from './vms-sg-list.component'; | ||
import { SecurityGroup } from '../../../security-group/sg.model'; | ||
import { getMockSecurityGroup } from '../../../../testutils/mocks/mocks'; | ||
|
||
describe('VmsSgListComponent', () => { | ||
let comp: VmsSgListComponent; | ||
const securityGroup = { id: 'sg-1', name: 'name', isPreselected: false } as SecurityGroup; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
|
||
comp = new VmsSgListComponent(); | ||
}); | ||
|
||
it('should select security group', () => { | ||
comp.selectSecurityGroup(securityGroup); | ||
expect(comp.currentSelectedSecurityGroup).toBe(securityGroup); | ||
describe('selectSecurityGroup', () => { | ||
it('should select security group', () => { | ||
const securityGroup = getMockSecurityGroup({ id: 'sg-1', isPreselected: false }); | ||
comp.selectSecurityGroup(securityGroup); | ||
expect(comp.currentSelectedSecurityGroup).toBe(securityGroup); | ||
}); | ||
|
||
it('should not select preselected security group', () => { | ||
const securityGroup = getMockSecurityGroup({ id: 'sg-1', isPreselected: true }); | ||
comp.selectSecurityGroup(securityGroup); | ||
expect(comp.currentSelectedSecurityGroup).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('ngOnChanges', () => { | ||
it('should change currentSelectedSecurityGroup', () => { | ||
const securityGroups = [ | ||
getMockSecurityGroup({ id: 'first_preselected', isPreselected: true }), | ||
getMockSecurityGroup({ id: 'first_not_selected', isPreselected: false }), | ||
getMockSecurityGroup({ id: 'second_not_selected', isPreselected: false }), | ||
]; | ||
comp.securityGroups = securityGroups; | ||
comp.ngOnChanges({ securityGroups: new SimpleChange(null, securityGroups, false) }); | ||
expect(comp.currentSelectedSecurityGroup).toEqual(securityGroups[1]); | ||
}); | ||
|
||
it('should not change currentSelectedSecurityGroup if it was selected', () => { | ||
const securityGroups = [ | ||
getMockSecurityGroup({ id: 'first_preselected', isPreselected: true }), | ||
getMockSecurityGroup({ id: 'first_not_selected', isPreselected: false }), | ||
getMockSecurityGroup({ id: 'second_not_selected', isPreselected: false }), | ||
]; | ||
comp.currentSelectedSecurityGroup = securityGroups[2]; | ||
comp.securityGroups = securityGroups; | ||
comp.ngOnChanges({ securityGroups: new SimpleChange([], securityGroups, false) }); | ||
expect(comp.currentSelectedSecurityGroup).toEqual(securityGroups[2]); | ||
}); | ||
|
||
it('should change currentSelectedSecurityGroup if it not in securityGroups', () => { | ||
const securityGroups = [ | ||
getMockSecurityGroup({ id: 'first_preselected', isPreselected: true }), | ||
getMockSecurityGroup({ id: 'first_not_selected', isPreselected: false }), | ||
getMockSecurityGroup({ id: 'second_not_selected', isPreselected: false }), | ||
]; | ||
comp.currentSelectedSecurityGroup = getMockSecurityGroup(); | ||
comp.securityGroups = securityGroups; | ||
comp.ngOnChanges({ securityGroups: new SimpleChange([], securityGroups, false) }); | ||
expect(comp.currentSelectedSecurityGroup).toEqual(securityGroups[1]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { SecurityGroup } from '../../app/security-group/sg.model'; | ||
|
||
export function getMockSecurityGroup(updates: Partial<SecurityGroup> = {}): SecurityGroup { | ||
return { | ||
id: null, | ||
account: null, | ||
description: null, | ||
domain: null, | ||
domainid: null, | ||
name: null, | ||
tags: [], | ||
virtualmachinecount: null, | ||
virtualmachineids: [], | ||
egressrule: [], | ||
ingressrule: [], | ||
...updates, | ||
}; | ||
} |