Created
April 8, 2019 10:40
-
-
Save gearmobile/17793a0a4b93bcaafc2e31180610c257 to your computer and use it in GitHub Desktop.
file
This file contains hidden or 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
import { CommonModule } from '@angular/common'; | |
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; | |
import { HttpClient } from '@angular/common/http'; | |
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | |
import { FormsModule } from '@angular/forms'; | |
import { ENDPOINTS } from '@api/constants/endpoints'; | |
import { endpoint } from '@api/endpoint/endpoint.service'; | |
import { Distributor } from '@api/contracts/distributor.class'; | |
import { DistributorsConfigurationComponent } from './distributors-configuration.component'; | |
import { ConfigurationModule } from '../../configuration.module'; | |
describe('[Modules] Component: DistributorsConfigurationComponent', () => { | |
let component: DistributorsConfigurationComponent; | |
let fixture: ComponentFixture<DistributorsConfigurationComponent>; | |
beforeEach(async(() => { | |
TestBed.configureTestingModule({ | |
imports: [ | |
CommonModule, | |
FormsModule, | |
HttpClientTestingModule, | |
ConfigurationModule | |
] | |
}) | |
.compileComponents(); | |
})); | |
beforeEach(() => { | |
fixture = TestBed.createComponent(DistributorsConfigurationComponent); | |
component = fixture.componentInstance; | |
component.rulesTree = [ | |
{ | |
name: 'documents', | |
displayName: 'Документы', | |
children: [ | |
{ | |
name: 'name', | |
typeId: 100, | |
displayName: 'displayName', | |
children: [ | |
{ name: 'attr1', displayName: 'attr1D', id: '123', selected: true }, | |
{ name: 'attr2', displayName: 'attr2D', id: '123', selected: true }, | |
{ name: 'attr3', displayName: 'attr3D', id: '123', selected: true }, | |
{ name: 'attr4', displayName: 'attr4D', id: '123', selected: true } | |
], | |
id: '123' | |
}], | |
id: '123' | |
}, | |
{ | |
name: 'references', | |
displayName: 'Справочники', | |
children: [ | |
{ | |
name: 'name', | |
typeId: 200, | |
displayName: 'displayName', | |
children: [ | |
{ name: 'attr1', displayName: 'attr1D', id: '123', selected: true }, | |
{ name: 'attr2', displayName: 'attr2D', id: '123', selected: true }, | |
{ name: 'attr3', displayName: 'attr3D', id: '123', selected: true }, | |
{ name: 'attr4', displayName: 'attr4D', id: '123', selected: true } | |
], | |
id: '123' | |
}], | |
id: '123' | |
}, | |
{ name: 'registers', displayName: 'Регистры', children: [], id: '123' } | |
]; | |
component.rulesList[0] = { | |
name: 'store', | |
displayName: 'Склад', | |
selected: true, | |
id: '123' | |
}; | |
component.rulesList[1] = { | |
name: 'owner', | |
displayName: 'Владелец', | |
selected: true, | |
id: '123' | |
}; | |
component.rulesList[2] = { | |
name: 'outlet', | |
displayName: 'Торговая точка', | |
selected: true, | |
id: '123' | |
}; | |
}); | |
it('should be created', () => { | |
expect(component).toBeTruthy(); | |
}); | |
describe('.getDistributorsConfiguration', () => { | |
it('should fetch settings and merge rules from backend', inject([HttpClient, HttpTestingController], (http: HttpClient, backend: HttpTestingController) => { | |
component['getDistributorConfiguration']('1000'); | |
component.activeDistributor = Object.assign(new Distributor(), { id: '1000' }); | |
const flushedMergeRules = { | |
documents: [ | |
{ name: 'name', typeId: 100, displayName: 'displayName', attributes: [ | |
{ name: 'attr1', displayName: 'attr1D', updatable: true }, | |
{ name: 'attr2', displayName: 'attr2D', updatable: true }, | |
{ name: 'attr3', displayName: 'attr3D', updatable: true }, | |
{ name: 'attr4', displayName: 'attr4D', updatable: true }, | |
] } | |
], | |
references: [ | |
{ name: 'name', typeId: 200, displayName: 'displayName', attributes: [ | |
{ name: 'attr1', displayName: 'attr1D', updatable: true }, | |
{ name: 'attr2', displayName: 'attr2D', updatable: true }, | |
{ name: 'attr3', displayName: 'attr3D', updatable: true }, | |
{ name: 'attr4', displayName: 'attr4D', updatable: true }, | |
] } | |
], | |
registers: [] | |
}; | |
const flushedSettings = { | |
'distributorId': '1000', | |
'exchange': { | |
'useReplicator4000': true, | |
'incomingType': 'ftp', | |
'ftpHost': 'Ftp://:21', | |
'listenEmail': '', | |
'senderEmail': '' | |
}, | |
'informer': { | |
'recipient': '876', | |
'cc': '', | |
'onlyErrors': false | |
}, | |
'cleanupObjects': [ | |
{ 'displayName': 'Owner', 'isCleanupable': false, 'name': 'Owner' }, | |
{ 'displayName': 'Owner', 'isCleanupable': false, 'name': 'Owner' }, | |
{ 'displayName': 'Owner', 'isCleanupable': false, 'name': 'Owner' } | |
] | |
}; | |
backend.expectOne(endpoint(ENDPOINTS.R4000_DISTRIBUTORS_MERGE_RULES, { distributorId: '1000' })) | |
.flush(flushedMergeRules); | |
backend.expectOne(endpoint(ENDPOINTS.R4000_DISTRIBUTORS_SETTINGS, { distributorId: '1000' })) | |
.flush(flushedSettings); | |
expect(component.distributorSettings).toEqual(flushedSettings as any); | |
expect(component.rulesTree[0]).toEqual( | |
{ name: 'documents', | |
displayName: 'Документы', | |
children: [ | |
{ name: 'name', | |
typeId: 100, | |
displayName: 'displayName', | |
children: [ | |
{ name: 'attr1', displayName: 'attr1D', id: jasmine.any(String), selected: true }, | |
{ name: 'attr2', displayName: 'attr2D', id: jasmine.any(String), selected: true }, | |
{ name: 'attr3', displayName: 'attr3D', id: jasmine.any(String), selected: true }, | |
{ name: 'attr4', displayName: 'attr4D', id: jasmine.any(String), selected: true } | |
], | |
attributes: [ | |
{ name: 'attr1', displayName: 'attr1D', updatable: true }, | |
{ name: 'attr2', displayName: 'attr2D', updatable: true }, | |
{ name: 'attr3', displayName: 'attr3D', updatable: true }, | |
{ name: 'attr4', displayName: 'attr4D', updatable: true }, | |
], | |
id: jasmine.any(String) } ], | |
id: jasmine.any(String) } as any | |
); | |
expect(component.rulesTree[1]).toEqual( | |
{ name: 'references', displayName: 'Справочники', | |
children: [ | |
{ name: 'name', | |
typeId: 200, | |
displayName: 'displayName', | |
children: [ | |
{ name: 'attr1', displayName: 'attr1D', id: jasmine.any(String), selected: true }, | |
{ name: 'attr2', displayName: 'attr2D', id: jasmine.any(String), selected: true }, | |
{ name: 'attr3', displayName: 'attr3D', id: jasmine.any(String), selected: true }, | |
{ name: 'attr4', displayName: 'attr4D', id: jasmine.any(String), selected: true } | |
], | |
attributes: [ | |
{ name: 'attr1', displayName: 'attr1D', updatable: true }, | |
{ name: 'attr2', displayName: 'attr2D', updatable: true }, | |
{ name: 'attr3', displayName: 'attr3D', updatable: true }, | |
{ name: 'attr4', displayName: 'attr4D', updatable: true }, | |
], | |
id: jasmine.any(String) } ], | |
id: jasmine.any(String) } as any | |
); | |
expect(component.rulesTree[2]).toEqual({ name: 'registers', displayName: 'Регистры', children: [ ], id: jasmine.any(String) } as any); | |
expect(component.rulesList).toEqual([ | |
{ | |
name: 'store', | |
displayName: 'Склад', | |
selected: true, | |
id: '123' | |
}, | |
{ | |
name: 'owner', | |
displayName: 'Владелец', | |
selected: true, | |
id: '123' | |
}, | |
{ | |
name: 'outlet', | |
displayName: 'Торговая точка', | |
selected: true, | |
id: '123' | |
} | |
] as any); | |
})); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment