From c181968ceaba87d806dd65808d6a65f918c25877 Mon Sep 17 00:00:00 2001
From: dangapay <divin.angapay@lam.fr>
Date: Thu, 6 Oct 2022 10:50:34 +0200
Subject: [PATCH] add test for
 admin/instance/dataset/components/attribute/detail

---
 .../components/attribute/detail/index.spec.ts | 17 +++++
 .../detail/table-detail.component.spec.ts     | 36 +++++++++++
 .../detail/tr-detail.component.spec.ts        | 63 +++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 client/src/app/admin/instance/dataset/components/attribute/detail/index.spec.ts
 create mode 100644 client/src/app/admin/instance/dataset/components/attribute/detail/table-detail.component.spec.ts
 create mode 100644 client/src/app/admin/instance/dataset/components/attribute/detail/tr-detail.component.spec.ts

diff --git a/client/src/app/admin/instance/dataset/components/attribute/detail/index.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/detail/index.spec.ts
new file mode 100644
index 00000000..993b73ad
--- /dev/null
+++ b/client/src/app/admin/instance/dataset/components/attribute/detail/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 { detailComponents } from './index';
+
+describe('[admin][instance][dataset][components][attribute][detail] index', () => {
+    it('Test detail index components', () => {
+        expect(detailComponents.length).toEqual(2);
+    });
+});
+
diff --git a/client/src/app/admin/instance/dataset/components/attribute/detail/table-detail.component.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/detail/table-detail.component.spec.ts
new file mode 100644
index 00000000..e7beb8f1
--- /dev/null
+++ b/client/src/app/admin/instance/dataset/components/attribute/detail/table-detail.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 { TableDetailComponent } from './table-detail.component';
+
+describe('[admin][instance][dataset][components][attribute][detail] TableDetailComponent', () => {
+    let component: TableDetailComponent;
+    let fixture: ComponentFixture<TableDetailComponent>;
+
+    beforeEach(() => {
+        TestBed.configureTestingModule({
+            declarations: [
+                TableDetailComponent,
+            ],
+            imports: [
+                BrowserAnimationsModule,
+            ],
+        });
+        fixture = TestBed.createComponent(TableDetailComponent);
+        component = fixture.componentInstance;
+        fixture.detectChanges();
+    });
+
+    it('should create the component', () => {
+        expect(component).toBeTruthy();
+    });
+});
+
diff --git a/client/src/app/admin/instance/dataset/components/attribute/detail/tr-detail.component.spec.ts b/client/src/app/admin/instance/dataset/components/attribute/detail/tr-detail.component.spec.ts
new file mode 100644
index 00000000..e562209f
--- /dev/null
+++ b/client/src/app/admin/instance/dataset/components/attribute/detail/tr-detail.component.spec.ts
@@ -0,0 +1,63 @@
+/**
+ * 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, OutputFamily } from 'src/app/metamodel/models';
+import { TrDetailComponent } from './tr-detail.component';
+
+describe('[admin][instance][dataset][components][attribute][detail] TrDetailComponent', () => {
+    let component: TrDetailComponent;
+    let fixture: ComponentFixture<TrDetailComponent>;
+
+    beforeEach(() => {
+        TestBed.configureTestingModule({
+            declarations: [
+                TrDetailComponent,
+            ],
+            imports: [
+                BrowserAnimationsModule,
+                ReactiveFormsModule
+            ],
+        });
+        fixture = TestBed.createComponent(TrDetailComponent);
+        component = fixture.componentInstance;
+        let attribute: Attribute;
+        component.attribute = { ...attribute, name: 'test', id_detail_output_category: 0, detail_display: 0 };
+        fixture.detectChanges();
+    });
+
+    it('should create the component', () => {
+        expect(component).toBeTruthy();
+    });
+    it('detailOutputCategoryOnChange() should set form.id_detail_output_category to null', () => {
+        component.form.controls.id_detail_output_category.setValue('');
+        expect(component.form.controls.id_detail_output_category.value).toEqual('');
+        component.detailOutputCategoryOnChange();
+        expect(component.form.controls.id_detail_output_category.value).toEqual(null);
+    });
+    it('getOutputFamilyLabel(idOutputFamilly: number) should return test1', () => {
+        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(2);
+        expect(result).toEqual('test1');
+    })
+    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