Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions components/table/__tests__/table-action-830.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { describe, expect, it, vi } from 'vitest';
import { mount } from '@vue/test-utils';
import FTableCell from '../components/cell';
import { provideKey } from '../const';

const mockColumn = {
id: 1,
props: {
action: [],
},
slots: {},
} as any;

describe('FTableCell action type', () => {
it('renders action with default primary type when no type is provided', () => {
const mockColumnWithDefaultAction = {
...mockColumn,
props: {
action: [
{
label: 'Edit',
func: vi.fn(),
},
],
},
} as any;
const mockRow = { id: 1 };
const wrapper = mount(FTableCell, {
props: {
row: mockRow,
rowIndex: 0,
column: mockColumnWithDefaultAction,
columnIndex: 0,
cellValue: null,
},
global: {
provide: {
[provideKey]: { prefixCls: 'fes-table' },
},
},
});
const btn = wrapper.find('button');
expect(btn.exists()).toBe(true);
expect(btn.classes()).toContain('fes-table-action-item');
expect(btn.classes()).toContain('fes-btn-type-primary');
});

it('renders action with warning type when type="warning"', () => {
const mockColumnWithWarning = {
...mockColumn,
props: {
action: [
{
label: 'Warn',
func: vi.fn(),
type: 'warning',
},
],
},
} as any;
const mockRow = { id: 1 };
const wrapper = mount(FTableCell, {
props: {
row: mockRow,
rowIndex: 0,
column: mockColumnWithWarning,
columnIndex: 0,
cellValue: null,
},
global: {
provide: {
[provideKey]: { prefixCls: 'fes-table' },
},
},
});
const btn = wrapper.find('button');
expect(btn.exists()).toBe(true);
expect(btn.classes()).toContain('fes-btn-type-warning');
});

it('renders action with danger type when type="danger"', () => {
const mockColumnWithDanger = {
...mockColumn,
props: {
action: [
{
label: 'Delete',
func: vi.fn(),
type: 'danger',
},
],
},
} as any;
const mockRow = { id: 1 };
const wrapper = mount(FTableCell, {
props: {
row: mockRow,
rowIndex: 0,
column: mockColumnWithDanger,
columnIndex: 0,
cellValue: null,
},
global: {
provide: {
[provideKey]: { prefixCls: 'fes-table' },
},
},
});
const btn = wrapper.find('button');
expect(btn.exists()).toBe(true);
expect(btn.classes()).toContain('fes-btn-type-danger');
});
});
2 changes: 1 addition & 1 deletion components/table/components/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default defineComponent({
{actions.map((action) => (
<Button
class={`${prefixCls}-action-item`}
type="link"
type={action.type ?? 'primary'}
onClick={() => {
action.func(row);
}}
Expand Down
1 change: 1 addition & 0 deletions components/table/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type RowKey = string | ((row: RowType) => string | number);
export interface ActionType {
label: string | number;
func: (row: any) => void;
type?: 'primary' | 'text' | 'link' | 'info' | 'success' | 'warning' | 'danger' | 'default';
}

export interface TableInst
Expand Down
Loading