mgr/dashboard: Simplify frontend test helper

Signed-off-by: Patrick Nawracay <pnawracay@suse.com>
This commit is contained in:
Patrick Nawracay 2018-10-15 15:27:18 +02:00
parent 061704080c
commit c98d5022b7

View 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
});
}
}