Skip to content

Commit

Permalink
826 fix bntable function that disables the action button (#827) 🚑
Browse files Browse the repository at this point in the history
* fix: disabled action in table

* test: table

---------

Co-authored-by: Iury Nogueira <[email protected]>
  • Loading branch information
deeved-hiuston-brisa and iurynogueira authored Sep 13, 2023
1 parent 79991bc commit ad031cd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
[circularButton]="true"
(ionOnClick)="handleEvent(row, action)"
[disabled]="
action.disabled ? !disableAction(row, action) : false
action.disabled ? disableAction(row, action) : false
"
></ion-button>
</div>
Expand Down
16 changes: 15 additions & 1 deletion projects/ion/src/lib/smart-table/smart-table.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,27 @@ describe('Table > Actions', () => {
);
});

it('should render trash button disabled when he caracther is less than 160cm', async () => {
it('should render trash button enable when he character is less than 160cm', async () => {
const tableItemDeleted = {
...tableWithActions,
} as IonSmartTableProps<Character>;

tableItemDeleted.config.data = [{ height: 96, name: 'RS-D2', mass: 96 }];

await sut(tableItemDeleted);
expect(screen.getByTestId('row-0-Desabilitar')).toHaveAttribute(
'ng-reflect-disabled',
'false'
);
});

it('should render trash button disabled when he character is taller than 160cm', async () => {
const tableItemDeleted = {
...tableWithActions,
} as IonSmartTableProps<Character>;

tableItemDeleted.config.data = [{ height: 196, name: 'RS-D2', mass: 96 }];

await sut(tableItemDeleted);
expect(screen.getByTestId('row-0-Desabilitar')).toHaveAttribute(
'ng-reflect-disabled',
Expand Down
2 changes: 1 addition & 1 deletion projects/ion/src/lib/table/table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
[circularButton]="true"
(ionOnClick)="handleEvent(row, action)"
[disabled]="
action.disabled ? !disableAction(row, action) : false
action.disabled ? disableAction(row, action) : false
"
></ion-button>
</div>
Expand Down
18 changes: 17 additions & 1 deletion projects/ion/src/lib/table/table.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ describe('Table > Actions', () => {
label: 'Desabilitar',
icon: 'block',
disabled: (row: SafeAny): boolean => {
return !row.deleted;
return row.deleted;
},
},
{
Expand Down Expand Up @@ -337,6 +337,22 @@ describe('Table > Actions', () => {
expect(within(rowAction).getByRole('button')).toHaveClass('danger');
});

it('should render trash button enabled when the item is not deleted', async () => {
const tableItemDeleted = {
...tableWithActions,
} as IonTableProps<Disco>;

tableItemDeleted.config.data = [
{ id: 1, name: 'Item Deleted', deleted: false },
];

await sut(tableItemDeleted);
expect(screen.getByTestId('row-0-Desabilitar')).toHaveAttribute(
'ng-reflect-disabled',
'false'
);
});

it('should render trash button disabled when the item is deleted', async () => {
const tableItemDeleted = {
...tableWithActions,
Expand Down

0 comments on commit ad031cd

Please sign in to comment.