Skip to content
Draft
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
21 changes: 21 additions & 0 deletions jestHelpers/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@ import React from 'react'

global.cozy = {}

global.fetch = jest.fn(() =>
Promise.resolve({
ok: true,
status: 200,
headers: {
get: jest.fn(name => {
if (name.toLowerCase() === 'content-type') {
return 'application/json'
}
return null
})
},
json: async () => ({
rows: [],
data: []
}),
text: async () => '',
blob: async () => new Blob()
})
)

jest.mock('cozy-bar', () => ({
...jest.requireActual('cozy-bar'),
BarComponent: () => <div>Bar</div>,
Expand Down
38 changes: 21 additions & 17 deletions src/components/FolderPicker/FolderPickerHeader.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render } from '@testing-library/react'
import { render, act } from '@testing-library/react'
import React from 'react'

import CozyClient from 'cozy-client'
Expand All @@ -11,7 +11,7 @@ jest.mock('lib/logger', () => ({
}))

describe('FolderPickerHeader', () => {
const setupComponent = ({ entries = [], title, subTitle }) => {
const setupComponent = async ({ entries = [], title, subTitle }) => {
const props = {
entries,

Expand All @@ -20,26 +20,30 @@ describe('FolderPickerHeader', () => {
}
const client = new CozyClient({})

return render(
<AppLike client={client}>
<FolderPickerHeader {...props} />
</AppLike>
)
let component
await act(async () => {
component = render(
<AppLike client={client}>
<FolderPickerHeader {...props} />
</AppLike>
)
})
return component
}
it('should fallback to Move title if no title is given', () => {
const { getByText } = setupComponent({
it('should fallback to Move title if no title is given', async () => {
const { getByText } = await setupComponent({
entries: [{ file: 1 }, { file: 2 }]
})
expect(getByText('2 elements'))
})
it('should display title if title is given and no file', () => {
const { getByText } = setupComponent({
it('should display title if title is given and no file', async () => {
const { getByText } = await setupComponent({
title: 'My Title'
})
expect(getByText('My Title'))
})
it('should display the right title if only one io.cozy.files', () => {
const { getByText } = setupComponent({
it('should display the right title if only one io.cozy.files', async () => {
const { getByText } = await setupComponent({
title: 'My Title',
entries: [
{
Expand All @@ -51,8 +55,8 @@ describe('FolderPickerHeader', () => {
expect(getByText('FileName.txt'))
})

it('should display the right title if it comes from the outside', () => {
const { getByText } = setupComponent({
it('should display the right title if it comes from the outside', async () => {
const { getByText } = await setupComponent({
title: 'My Title',
entries: [
{
Expand All @@ -62,8 +66,8 @@ describe('FolderPickerHeader', () => {
})
expect(getByText('FileName.txt'))
})
it('should display the right title if more than one files', () => {
const { getByText } = setupComponent({
it('should display the right title if more than one files', async () => {
const { getByText } = await setupComponent({
title: 'My Title',
entries: [
{
Expand Down
Loading
Loading