Skip to content

Commit

Permalink
test: Migrate last enzyme tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zatteo committed Nov 7, 2024
1 parent c814686 commit 784a6a2
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 2,220 deletions.
14 changes: 7 additions & 7 deletions src/modules/drive/Toolbar/delete/DeleteItem.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount } from 'enzyme'
import { render, fireEvent } from '@testing-library/react'
import React from 'react'

import DeleteItem from './DeleteItem'
Expand All @@ -20,7 +20,7 @@ describe('DeleteItem', () => {

jest.spyOn(store, 'dispatch')
const onLeave = jest.fn()
const root = mount(
const container = render(
<AppLike client={client} store={store}>
<DeleteItem
isSharedWithMe={false}
Expand All @@ -29,13 +29,13 @@ describe('DeleteItem', () => {
/>
</AppLike>
)
return { root, store, displayedFolder }
return { container, store, displayedFolder }
}

it('should show a modal', () => {
const { root, store, displayedFolder } = setup()
const menuItem = root.find('ActionMenuItem')
menuItem.simulate('click')
it('should show a modal', async () => {
const { container, store, displayedFolder } = setup()
const confirmButton = container.getByText('Remove')
fireEvent.click(confirmButton)
expect(store.dispatch).toHaveBeenCalledWith(
expect.objectContaining({
type: 'SHOW_MODAL',
Expand Down
17 changes: 9 additions & 8 deletions src/modules/drive/Toolbar/delete/delete.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { mount } from 'enzyme'
import { render, fireEvent, waitFor } from '@testing-library/react'
import React from 'react'

import { EnhancedDeleteConfirm } from './delete'
import DeleteConfirm from '../../DeleteConfirm'
import AppLike from 'test/components/AppLike'
import { setupStoreAndClient } from 'test/setup'

Expand All @@ -26,7 +25,7 @@ describe('EnhancedDeleteConfirm', () => {
getRecipients: () => [],
getSharingLink: () => null
}
const root = mount(
const container = render(
<AppLike
client={client}
store={store}
Expand All @@ -35,13 +34,15 @@ describe('EnhancedDeleteConfirm', () => {
<EnhancedDeleteConfirm folder={folder} onClose={() => null} />
</AppLike>
)
return { root, folder, client }
return { container, folder, client }
}

it('should trashFiles on confirmation', async () => {
const { root } = setup()
const confirmProps = root.find(DeleteConfirm).props()
await confirmProps.afterConfirmation()
expect(mockNavigate).toHaveBeenCalledWith('/folder/parent-folder-id')
const { container } = setup()
const confirmButton = container.getByText('Remove')
fireEvent.click(confirmButton)
await waitFor(() =>
expect(mockNavigate).toHaveBeenCalledWith('/folder/parent-folder-id')
)
})
})
42 changes: 18 additions & 24 deletions src/modules/filelist/AddFolder.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { mount } from 'enzyme'
import { render, fireEvent } from '@testing-library/react'
import React from 'react'

import { WebVaultClient } from 'cozy-keys-lib'

import AddFolder, { AddFolder as DumbAddFolder } from './AddFolder'
import { createFolder } from 'modules/navigation/duck/actions'
import { AddFolder } from './AddFolder'
import AppLike from 'test/components/AppLike'
import { setupStoreAndClient } from 'test/setup'

Expand All @@ -19,34 +16,31 @@ jest.mock('cozy-keys-lib', () => ({
WebVaultClient: jest.fn().mockReturnValue({})
}))

const CURRENT_FOLDER_ID = 'id'

describe('AddFolder', () => {
const setup = () => {
const { client, store } = setupStoreAndClient({})
const vaultClient = new WebVaultClient('http://alice.cozy.cloud')
jest.spyOn(client, 'create').mockResolvedValue({})
const root = mount(

const onSubmit = jest.fn()

const container = render(
<AppLike client={client} store={store}>
<AddFolder
vaultClient={vaultClient}
currentFolderId={CURRENT_FOLDER_ID}
/>
<AddFolder visible onSubmit={onSubmit} />
</AppLike>
)
const component = root.find(DumbAddFolder)
return { root, client, component, vaultClient }
return { container, onSubmit }
}

it('should dispatch a createFolder action on submit', () => {
const { component, client, vaultClient } = setup()
expect(component.props().onSubmit('Mes photos de chat'))
expect(createFolder).toHaveBeenCalledWith(
client,
vaultClient,
it('should call onSubmit with folder name', async () => {
const { container, onSubmit } = setup()

const input = await container.findByRole('textbox')
fireEvent.change(input, { target: { value: 'Mes photos de chat' } })
input.blur()

expect(onSubmit).toHaveBeenCalledWith(
'Mes photos de chat',
CURRENT_FOLDER_ID,
{ isEncryptedFolder: false }
expect.anything(),
expect.anything()
)
})
})
30 changes: 2 additions & 28 deletions src/modules/upload/Dropzone.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { render } from '@testing-library/react'
import { mount } from 'enzyme'
import React from 'react'

import Dropzone, { Dropzone as DumbDropzone } from './Dropzone'
import AppLike from 'test/components/AppLike'
import { setupFolderContent, mockCozyClientRequestQuery } from 'test/setup'
import { Dropzone as DumbDropzone } from './Dropzone'
import { mockCozyClientRequestQuery } from 'test/setup'

jest.mock('react-dropzone', () => {
const Component = ({
Expand Down Expand Up @@ -45,30 +43,6 @@ jest.mock('cozy-keys-lib', () => ({
mockCozyClientRequestQuery()

describe('Dropzone', () => {
it('should match snapshot', async () => {
// Given
jest.spyOn(console, 'error').mockImplementation()

const displayedFolder = {
id: 'directory-foobar0'
}
const { store, client } = await setupFolderContent({
folderId: 'directory-foobar0'
})

store.dispatch = jest.fn()

// When
const root = mount(
<AppLike client={client} store={store}>
<Dropzone displayedFolder={displayedFolder} />
</AppLike>
)

// Then
expect(root).toMatchSnapshot()
})

it('should dispatch the uploadFiles action', () => {
// Given
const uploadFilesMock = jest.fn()
Expand Down
Loading

0 comments on commit 784a6a2

Please sign in to comment.