rfellows commented on code in PR #8068:
URL: https://github.com/apache/nifi/pull/8068#discussion_r1409404821
##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-frontend/src/main/nifi/src/app/ui/common/property-table/editors/combo-editor/combo-editor.component.spec.ts:
##########
@@ -69,10 +117,114 @@ describe('ComboEditor', () => {
dirty: false,
type: 'required'
};
- fixture.detectChanges();
});
it('should create', () => {
- expect(component).toBeTruthy();
+ if (item) {
+ component.item = item;
+ fixture.detectChanges();
+
+ expect(component).toBeTruthy();
+ }
+ });
+
+ it('verify combo value', () => {
+ if (item) {
+ component.item = item;
+ fixture.detectChanges();
+
+ const formValue = component.comboEditorForm.get('value')?.value;
+
expect(component.itemLookup.get(formValue)?.value).toEqual(item.value);
+
expect(component.comboEditorForm.get('parameterReference')).toBeNull();
+
+ spyOn(component.ok, 'next');
+ component.okClicked();
+ expect(component.ok.next).toHaveBeenCalledWith(item.value);
+ }
+ });
+
+ it('verify combo not required with null value and default', () => {
+ if (item) {
+ item.value = null;
+ item.descriptor.required = false;
+
+ component.item = item;
+ fixture.detectChanges();
+
+ const formValue = component.comboEditorForm.get('value')?.value;
+
expect(component.itemLookup.get(formValue)?.value).toEqual(item.descriptor.defaultValue);
+
expect(component.comboEditorForm.get('parameterReference')).toBeNull();
+
+ spyOn(component.ok, 'next');
+ component.okClicked();
+
expect(component.ok.next).toHaveBeenCalledWith(item.descriptor.defaultValue);
+ }
+ });
+
+ it('verify combo not required with null value and no default', () => {
+ if (item) {
+ item.value = null;
+ item.descriptor.required = false;
+ item.descriptor.defaultValue = undefined;
+
+ component.item = item;
+ fixture.detectChanges();
+
+ const formValue = component.comboEditorForm.get('value')?.value;
+
expect(component.itemLookup.get(formValue)?.value).toEqual(item.value);
+
expect(component.comboEditorForm.get('parameterReference')).toBeNull();
+
+ spyOn(component.ok, 'next');
+ component.okClicked();
+ expect(component.ok.next).toHaveBeenCalledWith(item.value);
+ }
+ });
+
+ it('verify combo with parameter reference', () => {
+ if (item) {
+ item.value = '#{one}';
+
+ component.item = item;
+ component.getParameters = (sensitive: boolean) => {
+ return of(parameters);
+ };
+ fixture.detectChanges();
+ fixture.whenStable().then(function() {
+ const formValue =
component.comboEditorForm.get('value')?.value;
+
expect(component.itemLookup.get(formValue)?.value).toEqual(item?.value);
+
expect(component.comboEditorForm.get('parameterReference')).toBeDefined();
+
+ const parameterReferenceValue =
component.comboEditorForm.get('parameterReference')?.value;
+
expect(component.itemLookup.get(parameterReferenceValue)?.value).toEqual(item?.value);
+
+ spyOn(component.ok, 'next');
+ component.okClicked();
+ expect(component.ok.next).toHaveBeenCalledWith(item?.value);
+ });
+ }
+ });
+
+ it('verify combo with missing parameter reference', () => {
+ if (item) {
+ item.value = '#{three}';
+
+ component.item = item;
+ component.getParameters = (sensitive: boolean) => {
+ return of(parameters);
+ };
+ fixture.detectChanges();
+ fixture.whenStable().then(function() {
Review Comment:
```suggestion
fixture.whenStable().then(() => {
```
##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-frontend/src/main/nifi/src/app/ui/common/property-table/editors/combo-editor/combo-editor.component.spec.ts:
##########
@@ -69,10 +117,114 @@ describe('ComboEditor', () => {
dirty: false,
type: 'required'
};
- fixture.detectChanges();
});
it('should create', () => {
- expect(component).toBeTruthy();
+ if (item) {
+ component.item = item;
+ fixture.detectChanges();
+
+ expect(component).toBeTruthy();
+ }
+ });
+
+ it('verify combo value', () => {
+ if (item) {
+ component.item = item;
+ fixture.detectChanges();
+
+ const formValue = component.comboEditorForm.get('value')?.value;
+
expect(component.itemLookup.get(formValue)?.value).toEqual(item.value);
+
expect(component.comboEditorForm.get('parameterReference')).toBeNull();
+
+ spyOn(component.ok, 'next');
+ component.okClicked();
+ expect(component.ok.next).toHaveBeenCalledWith(item.value);
+ }
+ });
+
+ it('verify combo not required with null value and default', () => {
+ if (item) {
+ item.value = null;
+ item.descriptor.required = false;
+
+ component.item = item;
+ fixture.detectChanges();
+
+ const formValue = component.comboEditorForm.get('value')?.value;
+
expect(component.itemLookup.get(formValue)?.value).toEqual(item.descriptor.defaultValue);
+
expect(component.comboEditorForm.get('parameterReference')).toBeNull();
+
+ spyOn(component.ok, 'next');
+ component.okClicked();
+
expect(component.ok.next).toHaveBeenCalledWith(item.descriptor.defaultValue);
+ }
+ });
+
+ it('verify combo not required with null value and no default', () => {
+ if (item) {
+ item.value = null;
+ item.descriptor.required = false;
+ item.descriptor.defaultValue = undefined;
+
+ component.item = item;
+ fixture.detectChanges();
+
+ const formValue = component.comboEditorForm.get('value')?.value;
+
expect(component.itemLookup.get(formValue)?.value).toEqual(item.value);
+
expect(component.comboEditorForm.get('parameterReference')).toBeNull();
+
+ spyOn(component.ok, 'next');
+ component.okClicked();
+ expect(component.ok.next).toHaveBeenCalledWith(item.value);
+ }
+ });
+
+ it('verify combo with parameter reference', () => {
+ if (item) {
+ item.value = '#{one}';
+
+ component.item = item;
+ component.getParameters = (sensitive: boolean) => {
+ return of(parameters);
+ };
+ fixture.detectChanges();
+ fixture.whenStable().then(function() {
Review Comment:
```suggestion
fixture.whenStable().then(() => {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]