mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
fix(get-main-actions): Return only enabled Actions
This commit is contained in:
@@ -3,13 +3,13 @@ import { getMainActions } from './get-main-actions.helper';
|
||||
import { DBHOrderItemListItem } from '../schemas';
|
||||
|
||||
describe('getMainActions', () => {
|
||||
it('should return actions from first item', () => {
|
||||
it('should return actions from first item when enabled is true', () => {
|
||||
// Arrange
|
||||
const items: DBHOrderItemListItem[] = [
|
||||
{
|
||||
actions: [
|
||||
{ key: 'action1', value: 'Action 1' },
|
||||
{ key: 'action2', value: 'Action 2' },
|
||||
{ key: 'action1', value: 'Action 1', enabled: true },
|
||||
{ key: 'action2', value: 'Action 2', enabled: true },
|
||||
],
|
||||
} as DBHOrderItemListItem,
|
||||
];
|
||||
@@ -19,12 +19,12 @@ describe('getMainActions', () => {
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual([
|
||||
{ key: 'action1', value: 'Action 1' },
|
||||
{ key: 'action2', value: 'Action 2' },
|
||||
{ key: 'action1', value: 'Action 1', enabled: true },
|
||||
{ key: 'action2', value: 'Action 2', enabled: true },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should filter out actions with enabled boolean property', () => {
|
||||
it('should only include actions where enabled is true', () => {
|
||||
// Arrange
|
||||
const items: DBHOrderItemListItem[] = [
|
||||
{
|
||||
@@ -40,7 +40,9 @@ describe('getMainActions', () => {
|
||||
const result = getMainActions(items);
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual([{ key: 'action1', value: 'Action 1' }]);
|
||||
expect(result).toEqual([
|
||||
{ key: 'action2', value: 'Action 2', enabled: true },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should filter out actions containing FETCHED_PARTIAL when isPartial is true', () => {
|
||||
@@ -48,13 +50,24 @@ describe('getMainActions', () => {
|
||||
const items: DBHOrderItemListItem[] = [
|
||||
{
|
||||
actions: [
|
||||
{ key: 'action1', value: 'Action 1', command: 'DO_SOMETHING' },
|
||||
{
|
||||
key: 'action1',
|
||||
value: 'Action 1',
|
||||
command: 'DO_SOMETHING',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
key: 'action2',
|
||||
value: 'Action 2',
|
||||
command: 'FETCHED_PARTIAL_ACTION',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
key: 'action3',
|
||||
value: 'Action 3',
|
||||
command: 'DO_ANOTHER_THING',
|
||||
enabled: true,
|
||||
},
|
||||
{ key: 'action3', value: 'Action 3', command: 'DO_ANOTHER_THING' },
|
||||
],
|
||||
} as DBHOrderItemListItem,
|
||||
];
|
||||
@@ -64,8 +77,18 @@ describe('getMainActions', () => {
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual([
|
||||
{ key: 'action1', value: 'Action 1', command: 'DO_SOMETHING' },
|
||||
{ key: 'action3', value: 'Action 3', command: 'DO_ANOTHER_THING' },
|
||||
{
|
||||
key: 'action1',
|
||||
value: 'Action 1',
|
||||
command: 'DO_SOMETHING',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
key: 'action3',
|
||||
value: 'Action 3',
|
||||
command: 'DO_ANOTHER_THING',
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -74,11 +97,17 @@ describe('getMainActions', () => {
|
||||
const items: DBHOrderItemListItem[] = [
|
||||
{
|
||||
actions: [
|
||||
{ key: 'action1', value: 'Action 1', command: 'DO_SOMETHING' },
|
||||
{
|
||||
key: 'action1',
|
||||
value: 'Action 1',
|
||||
command: 'DO_SOMETHING',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
key: 'action2',
|
||||
value: 'Action 2',
|
||||
command: 'FETCHED_PARTIAL_ACTION',
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
} as DBHOrderItemListItem,
|
||||
@@ -89,11 +118,17 @@ describe('getMainActions', () => {
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual([
|
||||
{ key: 'action1', value: 'Action 1', command: 'DO_SOMETHING' },
|
||||
{
|
||||
key: 'action1',
|
||||
value: 'Action 1',
|
||||
command: 'DO_SOMETHING',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
key: 'action2',
|
||||
value: 'Action 2',
|
||||
command: 'FETCHED_PARTIAL_ACTION',
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
@@ -149,7 +184,12 @@ describe('getMainActions', () => {
|
||||
const items: DBHOrderItemListItem[] = [
|
||||
{
|
||||
actions: [
|
||||
{ key: 'action1', value: 'Action 1', command: 'DO_SOMETHING' },
|
||||
{
|
||||
key: 'action1',
|
||||
value: 'Action 1',
|
||||
command: 'DO_SOMETHING',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
key: 'action2',
|
||||
value: 'Action 2',
|
||||
@@ -160,8 +200,10 @@ describe('getMainActions', () => {
|
||||
key: 'action3',
|
||||
value: 'Action 3',
|
||||
command: 'FETCHED_PARTIAL_ACTION',
|
||||
enabled: true,
|
||||
},
|
||||
{ key: 'action4', value: 'Action 4', enabled: false },
|
||||
{ key: 'action5', value: 'Action 5', command: 'DO_ANOTHER_THING' },
|
||||
],
|
||||
} as DBHOrderItemListItem,
|
||||
];
|
||||
@@ -171,7 +213,12 @@ describe('getMainActions', () => {
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual([
|
||||
{ key: 'action1', value: 'Action 1', command: 'DO_SOMETHING' },
|
||||
{
|
||||
key: 'action1',
|
||||
value: 'Action 1',
|
||||
command: 'DO_SOMETHING',
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ export const getMainActions = (
|
||||
const firstItem = items?.find((_) => true);
|
||||
return (
|
||||
firstItem?.actions
|
||||
?.filter((action) => typeof action?.enabled !== 'boolean')
|
||||
?.filter((action) => action?.enabled === true)
|
||||
?.filter((action) =>
|
||||
isPartial ? !action?.command?.includes('FETCHED_PARTIAL') : true,
|
||||
) ?? []
|
||||
|
||||
Reference in New Issue
Block a user