From 3e15d8d72b8efcd8ce175d7f3443794a817e6869 Mon Sep 17 00:00:00 2001
From: dangapay <divin.angapay@lam.fr>
Date: Thu, 6 Oct 2022 16:43:25 +0200
Subject: [PATCH] add test for
 admin/instance/dataset/components/attribute/result

---
 .../components/attribute/index.spec.ts        |  18 +++
 .../output/tr-output.component.spec.ts        | 105 +++++++++---------
 .../components/attribute/result/index.spec.ts |  17 +++
 .../result/table-result.component.spec.ts     |  37 ++++++
 .../result/tr-result.component.spec.ts        |  72 ++++++++++++
 .../components/attribute/vo/index.spec.ts     |  18 +++
 .../attribute/vo/table-vo.component.spec.ts   |  36 ++++++
 .../attribute/vo/tr-vo.component.spec.ts      |  47 ++++++++
 8 files changed, 297 insertions(+), 53 deletions(-)
 create mode 100644 client/src/app/admin/instance/dataset/components/attribute/index.spec.ts
 create mode 100644 client/src/app/admin/instance/dataset/components/attribute/result/index.spec.ts
 create mode 100644 client/src/app/admin/instance/dataset/components/attribute/result/table-result.component.spec.ts
 create mode 100644 client/src/app/admin/instance/dataset/components/attribute/result/tr-result.component.spec.ts
 create mode 100644 client/src/app/admin/instance/dataset/components/attribute/vo/index.spec.ts
 create mode 100644 client/src/app/admin/instance/dataset/components/attribute/vo/table-vo.component.spec.ts
 create mode 100644 client/src/app/admin/instance/dataset/components/attribute/vo/tr-vo.component.spec.ts

diff --git a/client/src/app/admin/instance/dataset/components/attribute/index.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/index.spec.ts
new file mode 100644
index 00000000..022a4efa
--- /dev/null
+++ b/client/src/app/admin/instance/dataset/components/attribute/index.spec.ts
@@ -0,0 +1,18 @@
+/**
+ * This file is part of Anis Client.
+ *
+ * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+import { attributeComponents } from './index';
+
+describe('[admin][instance][dataset][components][attribute] index', () => {
+    it('Test output index components', () => {
+        expect(attributeComponents.length).toEqual(6);
+    });
+});
+
+
diff --git a/client/src/app/admin/instance/dataset/components/attribute/output/tr-output.component.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/output/tr-output.component.spec.ts
index 65cf844a..cf15cb95 100644
--- a/client/src/app/admin/instance/dataset/components/attribute/output/tr-output.component.spec.ts
+++ b/client/src/app/admin/instance/dataset/components/attribute/output/tr-output.component.spec.ts
@@ -7,58 +7,57 @@
  * file that was distributed with this source code.
  */
 
- import { ComponentFixture, TestBed } from '@angular/core/testing';
- import { ReactiveFormsModule } from '@angular/forms';
- import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
- import { Attribute, OutputFamily } from 'src/app/metamodel/models';
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { ReactiveFormsModule } from '@angular/forms';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { Attribute, OutputFamily } from 'src/app/metamodel/models';
 import { TrOutputComponent } from './tr-output.component';
- 
- describe('[admin][instance][dataset][components][attribute][] TrOutputComponent', () => {
-     let component: TrOutputComponent;
-     let fixture: ComponentFixture<TrOutputComponent>;
- 
-     beforeEach(() => {
-         TestBed.configureTestingModule({
-             declarations: [
+
+describe('[admin][instance][dataset][components][attribute][] TrOutputComponent', () => {
+    let component: TrOutputComponent;
+    let fixture: ComponentFixture<TrOutputComponent>;
+
+    beforeEach(() => {
+        TestBed.configureTestingModule({
+            declarations: [
                 TrOutputComponent,
-             ],
-             imports: [
-                 BrowserAnimationsModule,
-                 ReactiveFormsModule
-             ],
-         });
-         fixture = TestBed.createComponent(TrOutputComponent);
-         component = fixture.componentInstance;
-         let attribute: Attribute;
-         component.attribute = { ...attribute, name: 'test', output_display: 0, id_output_category: 0 , selected: true};
-         fixture.detectChanges();
-     });
- 
-     it('should create the component', () => {
-         expect(component).toBeTruthy();
-     });
-     it('outputCategoryOnChange() should set form.id_output_category to null', () => {
-         component.form.controls.id_output_category.setValue('');
-         expect(component.form.controls.id_output_category.value).toEqual('');
-         component.outputCategoryOnChange();
-         expect(component.form.controls.id_output_category.value).toEqual(null);
-     });
-     it('getOutputFamilyLabel(idOutputFamilly: number) should return test2', () => {
-         let outputFamilyList: OutputFamily[] = [
-             { display: 0, id: 1, label: 'test0', opened: false },
-             { display: 0, id: 2, label: 'test1', opened: false },
-             { display: 0, id: 3, label: 'test2', opened: false }
-         ]
-         component.outputFamilyList = outputFamilyList;
-         let result: string = component.getOutputFamilyLabel(3);
-         expect(result).toEqual('test2');
-     })
-     it('submit() should emit with attribute and form.value', () => {
-         let spy = jest.spyOn(component.save, 'emit');
-         component.submit();
-         expect(spy).toHaveBeenCalledTimes(1);
-         expect(spy).toHaveBeenCalledWith({ ...component.attribute, ...component.form.value });
-     })
- });
- 
- 
\ No newline at end of file
+            ],
+            imports: [
+                BrowserAnimationsModule,
+                ReactiveFormsModule
+            ],
+        });
+        fixture = TestBed.createComponent(TrOutputComponent);
+        component = fixture.componentInstance;
+        let attribute: Attribute;
+        component.attribute = { ...attribute, name: 'test', output_display: 0, id_output_category: 0, selected: true };
+        fixture.detectChanges();
+    });
+
+    it('should create the component', () => {
+        expect(component).toBeTruthy();
+    });
+    it('outputCategoryOnChange() should set form.id_output_category to null', () => {
+        component.form.controls.id_output_category.setValue('');
+        expect(component.form.controls.id_output_category.value).toEqual('');
+        component.outputCategoryOnChange();
+        expect(component.form.controls.id_output_category.value).toEqual(null);
+    });
+    it('getOutputFamilyLabel(idOutputFamilly: number) should return test2', () => {
+        let outputFamilyList: OutputFamily[] = [
+            { display: 0, id: 1, label: 'test0', opened: false },
+            { display: 0, id: 2, label: 'test1', opened: false },
+            { display: 0, id: 3, label: 'test2', opened: false }
+        ]
+        component.outputFamilyList = outputFamilyList;
+        let result: string = component.getOutputFamilyLabel(3);
+        expect(result).toEqual('test2');
+    })
+    it('submit() should emit with attribute and form.value', () => {
+        let spy = jest.spyOn(component.save, 'emit');
+        component.submit();
+        expect(spy).toHaveBeenCalledTimes(1);
+        expect(spy).toHaveBeenCalledWith({ ...component.attribute, ...component.form.value });
+    })
+});
+
diff --git a/client/src/app/admin/instance/dataset/components/attribute/result/index.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/result/index.spec.ts
new file mode 100644
index 00000000..a5a869c8
--- /dev/null
+++ b/client/src/app/admin/instance/dataset/components/attribute/result/index.spec.ts
@@ -0,0 +1,17 @@
+/**
+ * This file is part of Anis Client.
+ *
+ * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+import { resultComponents } from './index';
+
+describe('[admin][instance][dataset][components][attribute][result] index', () => {
+    it('Test result index components', () => {
+        expect(resultComponents.length).toEqual(3);
+    });
+});
+
diff --git a/client/src/app/admin/instance/dataset/components/attribute/result/table-result.component.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/result/table-result.component.spec.ts
new file mode 100644
index 00000000..aa010462
--- /dev/null
+++ b/client/src/app/admin/instance/dataset/components/attribute/result/table-result.component.spec.ts
@@ -0,0 +1,37 @@
+
+/**
+ * This file is part of Anis Client.
+ *
+ * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { TableResultComponent } from './table-result.component';
+
+describe('[admin][instance][dataset][components][attribute][result] TableResultComponent ', () => {
+    let component: TableResultComponent;
+    let fixture: ComponentFixture<TableResultComponent>;
+
+    beforeEach(() => {
+        TestBed.configureTestingModule({
+            declarations: [
+                TableResultComponent,
+            ],
+            imports: [
+                BrowserAnimationsModule
+            ],
+        });
+        fixture = TestBed.createComponent(TableResultComponent);
+        component = fixture.componentInstance;
+        fixture.detectChanges();
+    });
+
+    it('should create the component', () => {
+        expect(component).toBeTruthy();
+    });
+});
+
diff --git a/client/src/app/admin/instance/dataset/components/attribute/result/tr-result.component.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/result/tr-result.component.spec.ts
new file mode 100644
index 00000000..0cacf9ce
--- /dev/null
+++ b/client/src/app/admin/instance/dataset/components/attribute/result/tr-result.component.spec.ts
@@ -0,0 +1,72 @@
+/**
+ * This file is part of Anis Client.
+ *
+ * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { ReactiveFormsModule, UntypedFormGroup } from '@angular/forms';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { Attribute } from 'src/app/metamodel/models';
+import { RendererFormFactory } from './renderers';
+import { TrResultComponent } from './tr-result.component';
+
+
+describe('[admin][instance][dataset][components][attribute][result] TrResultComponent', () => {
+    let component: TrResultComponent;
+    let fixture: ComponentFixture<TrResultComponent>;
+
+    beforeEach(() => {
+        TestBed.configureTestingModule({
+            declarations: [
+                TrResultComponent,
+            ],
+            imports: [
+                BrowserAnimationsModule,
+                ReactiveFormsModule
+            ],
+        });
+        fixture = TestBed.createComponent(TrResultComponent);
+        component = fixture.componentInstance;
+        let attribute: Attribute;
+        component.attribute = { ...attribute, name: 'test', renderer: '', order_by: false, archive: true };
+        fixture.detectChanges();
+    });
+
+    it('should create the component', () => {
+        expect(component).toBeTruthy();
+    });
+    it('getRendererConfigForm() should form.controls["renderer_config"] as an instance of UntypedFormGroup', () => {
+        let result = component.getRendererConfigForm();
+        expect(result).toBeInstanceOf(UntypedFormGroup);
+
+    })
+    it(' rendererOnChange() should set form.controls.renderer to nul and call setcontrol on the form ', () => {
+        let spy = jest.spyOn(component.form, 'setControl');
+        expect(component.form.controls.renderer.value).toEqual('');
+        component.rendererOnChange();
+        expect(component.form.controls.renderer.value).toEqual(null);
+        expect(spy).toHaveBeenCalledTimes(1);
+
+
+    });
+    it('rendererOnChange() should call RenderFormFactory.create', () => {
+        component.form.controls.renderer.setValue('test');
+        let spy = jest.spyOn(RendererFormFactory, 'create');
+        component.rendererOnChange()
+        expect(spy).toHaveBeenCalledTimes(1);
+
+    });
+    it('submit() should emit with attribute and form.value', () => {
+        let spy = jest.spyOn(component.save, 'emit');
+        component.submit();
+        expect(spy).toHaveBeenCalledTimes(1);
+        expect(spy).toHaveBeenCalledWith({ ...component.attribute, ...component.form.value });
+    })
+
+
+});
+
diff --git a/client/src/app/admin/instance/dataset/components/attribute/vo/index.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/vo/index.spec.ts
new file mode 100644
index 00000000..cabfd99a
--- /dev/null
+++ b/client/src/app/admin/instance/dataset/components/attribute/vo/index.spec.ts
@@ -0,0 +1,18 @@
+/**
+ * This file is part of Anis Client.
+ *
+ * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+import { voComponents } from './index';
+
+describe('[admin][instance][dataset][components][attribute][vo] index', () => {
+    it('Test output index components', () => {
+        expect(voComponents.length).toEqual(2);
+    });
+});
+
+
diff --git a/client/src/app/admin/instance/dataset/components/attribute/vo/table-vo.component.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/vo/table-vo.component.spec.ts
new file mode 100644
index 00000000..8c7ca8e2
--- /dev/null
+++ b/client/src/app/admin/instance/dataset/components/attribute/vo/table-vo.component.spec.ts
@@ -0,0 +1,36 @@
+/**
+ * This file is part of Anis Client.
+ *
+ * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { TableVoComponent } from './table-vo.component';
+
+describe('[admin][instance][dataset][components][attribute][vo] TableVoComponent', () => {
+    let component: TableVoComponent;
+    let fixture: ComponentFixture<TableVoComponent>;
+
+    beforeEach(() => {
+        TestBed.configureTestingModule({
+            declarations: [
+                TableVoComponent,
+            ],
+            imports: [
+                BrowserAnimationsModule,
+            ],
+        });
+        fixture = TestBed.createComponent(TableVoComponent);
+        component = fixture.componentInstance;
+        fixture.detectChanges();
+    });
+
+    it('should create the component', () => {
+        expect(component).toBeTruthy();
+    });
+});
+
diff --git a/client/src/app/admin/instance/dataset/components/attribute/vo/tr-vo.component.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/vo/tr-vo.component.spec.ts
new file mode 100644
index 00000000..bb73f571
--- /dev/null
+++ b/client/src/app/admin/instance/dataset/components/attribute/vo/tr-vo.component.spec.ts
@@ -0,0 +1,47 @@
+/**
+ * This file is part of Anis Client.
+ *
+ * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { ReactiveFormsModule } from '@angular/forms';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { Attribute } from 'src/app/metamodel/models';
+import { TrVoComponent } from './tr-vo.component';
+
+describe('[admin][instance][dataset][components][attribute][vo] TrVoComponent', () => {
+    let component: TrVoComponent;
+    let fixture: ComponentFixture<TrVoComponent>;
+
+    beforeEach(() => {
+        TestBed.configureTestingModule({
+            declarations: [
+                TrVoComponent,
+            ],
+            imports: [
+                BrowserAnimationsModule,
+                ReactiveFormsModule
+            ],
+        });
+        fixture = TestBed.createComponent(TrVoComponent);
+        component = fixture.componentInstance;
+        let attribute: Attribute;
+        component.attribute = { ...attribute, name: 'test', vo_utype: '', vo_ucd: '', vo_unit: '', vo_description: '', vo_datatype: '', vo_size: 1 };
+        fixture.detectChanges();
+    });
+
+    it('should create the component', () => {
+        expect(component).toBeTruthy();
+    });
+    it('submit() should emit with attribute and form.value', () => {
+        let spy = jest.spyOn(component.save, 'emit');
+        component.submit();
+        expect(spy).toHaveBeenCalledTimes(1);
+        expect(spy).toHaveBeenCalledWith({ ...component.attribute, ...component.form.value });
+    })
+});
+
-- 
GitLab