]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Simplify frontend test helper
authorPatrick Nawracay <pnawracay@suse.com>
Mon, 15 Oct 2018 13:27:18 +0000 (15:27 +0200)
committerPatrick Nawracay <pnawracay@suse.com>
Wed, 24 Oct 2018 08:02:31 +0000 (10:02 +0200)
Signed-off-by: Patrick Nawracay <pnawracay@suse.com>
src/pybind/mgr/dashboard/frontend/src/testing/unit-test-helper.ts

index be0c6c333d50f8e64be8d71297dc2e09f43859e7..e83975126aba4dbc747614a7d310bd04e54806a7 100644 (file)
@@ -63,41 +63,31 @@ export class PermissionHelper {
     singleExecuting?: any; // uses 'single' if not defined
     multiple?: any; // uses 'empty' if not defined
   }) {
-    this.testSingleScenario(
+    this.testScenario( // 'multiple selections'
       [{}, {}],
-      'multiple selections',
       fn,
       _.isUndefined(multiple) ? empty : multiple
     );
-    this.testSingleScenario(
+    this.testScenario( // 'select executing item'
       [{ cdExecuting: 'someAction' }],
-      'select executing item',
       fn,
       _.isUndefined(singleExecuting) ? single : singleExecuting
     );
-    this.testSingleScenario([{}], 'select non-executing item', fn, single);
-    this.testSingleScenario([], 'no selection', fn, empty);
+    this.testScenario([{}], fn, single); // 'select non-executing item'
+    this.testScenario([], fn, empty); // 'no selection'
   }
 
-  private testSingleScenario(
+  private testScenario(
     selection: object[],
-    description: string,
     fn: () => any,
     expected: any
   ) {
     this.setSelection(selection);
-    this.readableExpect(description, fn, expected);
+    expect(fn()).toBe(expected);
   }
 
   setSelection(selection: object[]) {
     this.tableActions.selection.selected = selection;
     this.tableActions.selection.update();
   }
-
-  private readableExpect(task: string, fn: () => any, expected: any) {
-    expect({ task: task, expected: fn() }).toEqual({
-      task: task,
-      expected: expected
-    });
-  }
 }