-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bound confirm on resource delete (#2568)
* bound confirm on resource delete * increased tests coverage * fexed tests
- Loading branch information
1 parent
c291100
commit a067c74
Showing
3 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
tests/unit/containers/my-resources/MyResourcesTable.spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { fireEvent, screen } from '@testing-library/react' | ||
|
||
import MyResourcesTable from '~/containers/my-resources/my-resources-table/MyResourcesTable' | ||
|
||
import { renderWithProviders } from '~tests/test-utils' | ||
|
||
vi.mock('~/components/enhanced-table/EnhancedTable', () => ({ | ||
default: ({ rowActions }) => ( | ||
<div data-testid='table'> | ||
{rowActions.map(({ label, func }) => ( | ||
<button data-testid={label} key={label} onClick={func}> | ||
{label} | ||
</button> | ||
))} | ||
</div> | ||
) | ||
})) | ||
|
||
vi.mock('~/components/app-pagination/AppPagination', () => ({ | ||
default: () => <div data-testid='pagination' /> | ||
})) | ||
|
||
vi.mock( | ||
'~/containers/change-resource-confirm-modal/ChangeResourceConfirmModal', | ||
() => ({ | ||
default: () => <div data-testid='confirmModal' /> | ||
}) | ||
) | ||
|
||
const lessonMock = { | ||
_id: '64e49ce305b3353b2ae6309e', | ||
author: '648afee884936e09a37deaaa', | ||
title: 'eew', | ||
description: 'dsdfd', | ||
attachments: [], | ||
createdAt: '2023-08-22T11:32:51.995Z', | ||
updatedAt: '2023-08-22T11:32:51.995Z' | ||
} | ||
|
||
const responseItemsMock = Array(10) | ||
.fill() | ||
.map((_, index) => ({ | ||
...lessonMock, | ||
_id: `${index}`, | ||
title: index + lessonMock.title | ||
})) | ||
|
||
const props = { | ||
resource: 'lessons', | ||
pagination: { | ||
page: 1, | ||
onChange: vi.fn() | ||
}, | ||
data: { | ||
response: { | ||
items: responseItemsMock, | ||
count: 10 | ||
}, | ||
getData: vi.fn() | ||
}, | ||
actions: { | ||
onEdit: vi.fn(), | ||
onDuplicate: vi.fn() | ||
}, | ||
services: { | ||
deleteService: vi.fn() | ||
} | ||
} | ||
|
||
describe('MyResourcesTable test', () => { | ||
beforeEach(async () => { | ||
renderWithProviders(<MyResourcesTable {...props} />) | ||
}) | ||
|
||
it('should render table and pagination', () => { | ||
const table = screen.getByTestId('table') | ||
const pagination = screen.getByTestId('pagination') | ||
|
||
expect(table).toBeInTheDocument() | ||
expect(pagination).toBeInTheDocument() | ||
}) | ||
|
||
it('should render table action buttons', async () => { | ||
const editButton = await screen.findByTestId('common.edit') | ||
const deleteButton = await screen.findByText('common.delete') | ||
const duplicateButton = await screen.findByText('common.duplicate') | ||
|
||
expect(editButton).toBeInTheDocument() | ||
expect(deleteButton).toBeInTheDocument() | ||
expect(duplicateButton).toBeInTheDocument() | ||
}) | ||
|
||
it('should run onDelete action', async () => { | ||
const deleteButton = await screen.findByText('common.delete') | ||
|
||
fireEvent.click(deleteButton) | ||
|
||
const modal = await screen.findByTestId('confirmModal') | ||
|
||
expect(modal).toBeInTheDocument() | ||
}) | ||
}) |