mirror of
https://github.com/fergalmoran/onearmy-community-platform.git
synced 2026-01-04 16:04:32 +00:00
chore: clenaup unit tests
This commit is contained in:
@@ -43,9 +43,9 @@ describe('SEO', () => {
|
||||
beforeAll(async () => {
|
||||
db = admin.firestore()
|
||||
// Test will only create entries for accepted howtos and research
|
||||
for (const doc of testDocs) {
|
||||
await db.collection(doc.endpoint).add(doc)
|
||||
}
|
||||
await Promise.all(
|
||||
testDocs.map((doc) => db.collection(doc.endpoint).add(doc)),
|
||||
)
|
||||
})
|
||||
afterAll(firebaseTest.cleanup)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import '@testing-library/jest-dom/vitest'
|
||||
|
||||
import { fireEvent, waitFor } from '@testing-library/react'
|
||||
import { fireEvent } from '@testing-library/react'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { render } from '../test/utils'
|
||||
@@ -60,12 +60,10 @@ describe('CreateReply', () => {
|
||||
|
||||
fireEvent.click(submitButton)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
screen.getByText(
|
||||
'Unable to leave a comment at this time. Please try again later.',
|
||||
),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -17,27 +17,27 @@ describe('DiscussionContainer', () => {
|
||||
expect(() => getByText('reply')).toThrow()
|
||||
})
|
||||
|
||||
it('allows replying to a comment', async () => {
|
||||
it('allows replying to a comment', () => {
|
||||
const screen = render(<WithReplies.render />)
|
||||
|
||||
// Show reply form
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
const replyButton = screen.getAllByText('2 replies to', {
|
||||
exact: false,
|
||||
})[0]
|
||||
expect(replyButton).toBeInTheDocument()
|
||||
|
||||
await fireEvent.click(replyButton)
|
||||
fireEvent.click(replyButton)
|
||||
|
||||
expect(screen.getAllByText('Leave a reply')).toHaveLength(1)
|
||||
})
|
||||
|
||||
// Hide reply form
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
const replyButton = screen.getAllByText('2 replies to', {
|
||||
exact: false,
|
||||
})[0]
|
||||
await fireEvent.click(replyButton)
|
||||
fireEvent.click(replyButton)
|
||||
expect(() => {
|
||||
screen.getAllByText('Leave a reply')
|
||||
}).toThrow()
|
||||
@@ -49,14 +49,14 @@ describe('DiscussionContainer', () => {
|
||||
expect(SecondReplyButton).toBeInTheDocument()
|
||||
|
||||
// Show reply form
|
||||
await act(async () => {
|
||||
await fireEvent.click(SecondReplyButton)
|
||||
act(() => {
|
||||
fireEvent.click(SecondReplyButton)
|
||||
expect(screen.getAllByText('Leave a reply')).toHaveLength(1)
|
||||
})
|
||||
|
||||
// Hide reply form
|
||||
await act(async () => {
|
||||
await fireEvent.click(SecondReplyButton)
|
||||
act(() => {
|
||||
fireEvent.click(SecondReplyButton)
|
||||
expect(() => {
|
||||
screen.getAllByText('Send your reply')
|
||||
}).toThrow()
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('DonationRequest', () => {
|
||||
expect(iframe).toHaveAttribute('src', iframeSrc)
|
||||
})
|
||||
|
||||
it('calls the callback when user skips', async () => {
|
||||
it('calls the callback when user skips', () => {
|
||||
const body = 'All of the content here is free.'
|
||||
const mockCallback = vi.fn()
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ describe('EditComment', () => {
|
||||
)
|
||||
expect(screen.getByTestId('edit-comment-submit')).toBeDisabled()
|
||||
})
|
||||
it('should dispaly error message when the comment is empty', async () => {
|
||||
it('should dispaly error message when the comment is empty', () => {
|
||||
const screen = render(
|
||||
<EditComment
|
||||
isReply={false}
|
||||
@@ -69,7 +69,7 @@ describe('EditComment', () => {
|
||||
/>,
|
||||
)
|
||||
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
const commentInput = screen.getByLabelText('Edit Comment')
|
||||
fireEvent.change(commentInput, { target: { value: '' } })
|
||||
fireEvent.blur(commentInput)
|
||||
|
||||
@@ -156,7 +156,7 @@ describe('ImageGallery', () => {
|
||||
expect(image?.getAttribute('src')).toEqual(testImages[0].downloadUrl)
|
||||
})
|
||||
|
||||
it('hides thumbnail for single image', async () => {
|
||||
it('hides thumbnail for single image', () => {
|
||||
const { getAllByTestId } = render(
|
||||
<HideThumbnailForSingleImage
|
||||
{...(HideThumbnailForSingleImage.args as ImageGalleryProps)}
|
||||
@@ -168,7 +168,7 @@ describe('ImageGallery', () => {
|
||||
}).toThrow()
|
||||
})
|
||||
|
||||
it('supports no thumbnail option', async () => {
|
||||
it('supports no thumbnail option', () => {
|
||||
const { getAllByTestId } = render(
|
||||
<NoThumbnails {...(NoThumbnails.args as ImageGalleryProps)} />,
|
||||
)
|
||||
@@ -178,7 +178,7 @@ describe('ImageGallery', () => {
|
||||
}).toThrow()
|
||||
})
|
||||
|
||||
it('supports show next/previous buttons', async () => {
|
||||
it('supports show next/previous buttons', () => {
|
||||
const { getByRole } = render(
|
||||
<ShowNextPrevButtons
|
||||
{...(ShowNextPrevButtons.args as ImageGalleryProps)}
|
||||
@@ -192,7 +192,7 @@ describe('ImageGallery', () => {
|
||||
expect(previousBtn).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not support show next/previous buttons because only one image', async () => {
|
||||
it('does not support show next/previous buttons because only one image', () => {
|
||||
const { queryByRole } = render(
|
||||
<DoNotShowNextPrevButtons
|
||||
{...(DoNotShowNextPrevButtons.args as ImageGalleryProps)}
|
||||
|
||||
@@ -16,7 +16,7 @@ describe('MapMemberCard', () => {
|
||||
expect(() => getByTestId('MapMemberCard: moderation comments')).toThrow()
|
||||
})
|
||||
|
||||
it('shows moderation comments if they exist', async () => {
|
||||
it('shows moderation comments if they exist', () => {
|
||||
const { getByText, getByTestId } = render(
|
||||
<MapMemberCard {...ModerationComments.args} />,
|
||||
)
|
||||
|
||||
@@ -15,10 +15,10 @@ describe('TabbedContent', () => {
|
||||
expect(() => wrapper.getByText('Tab Panel #2')).toThrow()
|
||||
})
|
||||
|
||||
it('basic interaction', async () => {
|
||||
it('basic interaction', () => {
|
||||
const wrapper = render(<Default />)
|
||||
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper.getByText('Tab #2').click()
|
||||
})
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ vi.mock('src/common/hooks/useCommonStores', () => ({
|
||||
|
||||
// Happy path well tested in cypress
|
||||
describe('DiscussionWrapper', () => {
|
||||
it('initally renders a loading before moving on', async () => {
|
||||
it('initally renders a loading before moving on', () => {
|
||||
const discussionProps = {
|
||||
sourceType: 'question' as IDiscussion['sourceType'],
|
||||
sourceId: '82364tdf',
|
||||
@@ -47,7 +47,7 @@ describe('DiscussionWrapper', () => {
|
||||
})
|
||||
expect(wrapper.getByTestId('loader')).toBeVisible()
|
||||
|
||||
await waitFor(async () => {
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText('Start the discussion')).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -6,7 +6,7 @@ import { describe, expect, it } from 'vitest'
|
||||
import { HideDiscussionContainer } from './HideDiscussionContainer'
|
||||
|
||||
describe('HideDiscussionContainer', () => {
|
||||
it('can be opened/closed', async () => {
|
||||
it('can be opened/closed', () => {
|
||||
const { getByText } = render(
|
||||
<HideDiscussionContainer commentCount={0}>
|
||||
<>Hidden</>
|
||||
|
||||
@@ -13,14 +13,14 @@ vi.mock('react-router-dom', async () => ({
|
||||
}))
|
||||
|
||||
describe('ScrollToTop', () => {
|
||||
it('should scroll to top when pathname changes', async () => {
|
||||
it('should scroll to top when pathname changes', () => {
|
||||
const scrollToSpy = vi.fn()
|
||||
global.window.scrollTo = scrollToSpy
|
||||
;(useLocation as Mock).mockImplementation(() => ({
|
||||
pathname: '/initial',
|
||||
}))
|
||||
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
render(<ScrollToTop />)
|
||||
})
|
||||
|
||||
@@ -34,7 +34,7 @@ describe('ScrollToTop', () => {
|
||||
pathname: '/changed',
|
||||
}))
|
||||
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
render(<ScrollToTop />)
|
||||
})
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('HowtoCategoryGuidance', () => {
|
||||
await screen.findByText(filesGuidance, { exact: false })
|
||||
})
|
||||
|
||||
it('renders nothing when not visible', async () => {
|
||||
it('renders nothing when not visible', () => {
|
||||
const { container } = render(
|
||||
<HowtoProvider>
|
||||
<HowtoCategoryGuidance category={undefined} type="main" />
|
||||
|
||||
@@ -38,7 +38,7 @@ describe('HowtoErrors', () => {
|
||||
await screen.findByText('Step 2')
|
||||
})
|
||||
|
||||
it('renders nothing when not visible', async () => {
|
||||
it('renders nothing when not visible', () => {
|
||||
const errors = {
|
||||
title: 'Make sure this field is filled correctly',
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from 'react-router-dom'
|
||||
import { ThemeProvider } from '@emotion/react'
|
||||
import { faker } from '@faker-js/faker'
|
||||
import { act, render, within } from '@testing-library/react'
|
||||
import { act, render, waitFor, within } from '@testing-library/react'
|
||||
import { Provider } from 'mobx-react'
|
||||
import { preciousPlasticTheme } from 'oa-themes'
|
||||
import { FactoryHowto, FactoryHowtoStep } from 'src/test/factories/Howto'
|
||||
@@ -50,7 +50,7 @@ import { IModerationStatus } from 'oa-shared'
|
||||
|
||||
import { Howto } from './Howto'
|
||||
|
||||
const factory = async (howtoStore?: Partial<HowtoStore>) => {
|
||||
const factory = (howtoStore?: Partial<HowtoStore>) => {
|
||||
const router = createMemoryRouter(
|
||||
createRoutesFromElements(
|
||||
<Route path="/howto/:slug" key={1} element={<Howto />} />,
|
||||
@@ -70,69 +70,73 @@ const factory = async (howtoStore?: Partial<HowtoStore>) => {
|
||||
}
|
||||
describe('Howto', () => {
|
||||
describe('moderator feedback', () => {
|
||||
it('displays feedback for items which are not accepted', async () => {
|
||||
it('displays feedback for items which are not accepted', () => {
|
||||
let wrapper
|
||||
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
howto.moderation = IModerationStatus.AWAITING_MODERATION
|
||||
howto.moderatorFeedback = 'Moderation comments'
|
||||
|
||||
wrapper = await factory()
|
||||
wrapper = factory()
|
||||
})
|
||||
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText('Moderation comments')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('hides feedback when how-to is accepted', async () => {
|
||||
it('hides feedback when how-to is accepted', () => {
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
howto.moderation = IModerationStatus.ACCEPTED
|
||||
howto.moderatorFeedback = 'Moderation comments'
|
||||
wrapper = await factory()
|
||||
wrapper = factory()
|
||||
})
|
||||
|
||||
expect(() => wrapper.getByText('Moderation comments')).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
it('displays content statistics', async () => {
|
||||
it('displays content statistics', () => {
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
howto._id = 'testid'
|
||||
howto._createdBy = 'HowtoAuthor'
|
||||
howto.steps = [FactoryHowtoStep({})]
|
||||
howto.moderation = IModerationStatus.ACCEPTED
|
||||
howto.total_views = 0
|
||||
|
||||
wrapper = await factory()
|
||||
wrapper = factory()
|
||||
})
|
||||
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText('0 views')).toBeInTheDocument()
|
||||
expect(wrapper.getByText('0 useful')).toBeInTheDocument()
|
||||
expect(wrapper.getByText('0 comments')).toBeInTheDocument()
|
||||
expect(wrapper.getByText('1 step')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('shows verified badge', async () => {
|
||||
it('shows verified badge', () => {
|
||||
let wrapper
|
||||
|
||||
howto._createdBy = 'HowtoAuthor'
|
||||
|
||||
await act(async () => {
|
||||
wrapper = await factory()
|
||||
act(() => {
|
||||
wrapper = factory()
|
||||
})
|
||||
|
||||
expect(() => {
|
||||
wrapper.getAllByTestId('Username: verified badge')
|
||||
}).not.toThrow()
|
||||
waitFor(() => {
|
||||
expect(() => wrapper.getAllByTestId('Username: verified badge'))
|
||||
})
|
||||
})
|
||||
|
||||
it('does not show verified badge', async () => {
|
||||
it('does not show verified badge', () => {
|
||||
let wrapper
|
||||
howto._createdBy = 'NotHowtoAuthor'
|
||||
|
||||
await act(async () => {
|
||||
wrapper = await factory()
|
||||
act(() => {
|
||||
wrapper = factory()
|
||||
})
|
||||
|
||||
expect(() => {
|
||||
@@ -141,10 +145,10 @@ describe('Howto', () => {
|
||||
})
|
||||
|
||||
describe('steps', () => {
|
||||
it('shows 1 step', async () => {
|
||||
it('shows 1 step', () => {
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await factory({
|
||||
act(() => {
|
||||
wrapper = factory({
|
||||
...mockHowtoStore(),
|
||||
activeHowto: FactoryHowto({
|
||||
_createdBy: 'HowtoAuthor',
|
||||
@@ -153,28 +157,28 @@ describe('Howto', () => {
|
||||
})
|
||||
})
|
||||
|
||||
expect(() => {
|
||||
wrapper.getAllByText('1 step')
|
||||
}).not.toThrow()
|
||||
waitFor(() => {
|
||||
expect(() => wrapper.getAllByText('1 step'))
|
||||
})
|
||||
})
|
||||
|
||||
it('shows 2 steps', async () => {
|
||||
it('shows 2 steps', () => {
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
howto.steps = [FactoryHowtoStep(), FactoryHowtoStep()]
|
||||
wrapper = await factory()
|
||||
wrapper = factory()
|
||||
})
|
||||
|
||||
expect(() => {
|
||||
wrapper.getAllByText('2 steps')
|
||||
}).not.toThrow()
|
||||
waitFor(() => {
|
||||
expect(() => wrapper.getAllByText('2 steps'))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Breadcrumbs', () => {
|
||||
it('displays breadcrumbs with category', async () => {
|
||||
it('displays breadcrumbs with category', () => {
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
howto.title = 'DIY Recycling Machine'
|
||||
howto.category = {
|
||||
label: 'DIY',
|
||||
@@ -184,10 +188,10 @@ describe('Howto', () => {
|
||||
_deleted: faker.datatype.boolean(),
|
||||
_contentModifiedTimestamp: faker.date.past().toString(),
|
||||
}
|
||||
wrapper = await factory()
|
||||
wrapper = factory()
|
||||
})
|
||||
|
||||
expect(() => {
|
||||
waitFor(() => {
|
||||
const breadcrumbItems = wrapper.getAllByTestId('breadcrumbsItem')
|
||||
expect(breadcrumbItems).toHaveLength(3)
|
||||
expect(breadcrumbItems[0]).toHaveTextContent('How To')
|
||||
@@ -203,18 +207,18 @@ describe('Howto', () => {
|
||||
// Assert: Check for the correct number of chevrons
|
||||
const chevrons = wrapper.getAllByTestId('breadcrumbsChevron')
|
||||
expect(chevrons).toHaveLength(2)
|
||||
}).not.toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
it('displays breadcrumbs without category', async () => {
|
||||
it('displays breadcrumbs without category', () => {
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
howto.title = 'DIY Recycling Machine'
|
||||
howto.category = undefined
|
||||
wrapper = await factory()
|
||||
wrapper = factory()
|
||||
})
|
||||
|
||||
expect(() => {
|
||||
waitFor(() => {
|
||||
const breadcrumbItems = wrapper.getAllByTestId('breadcrumbsItem')
|
||||
expect(breadcrumbItems).toHaveLength(2)
|
||||
expect(breadcrumbItems[0]).toHaveTextContent('How To')
|
||||
@@ -227,7 +231,7 @@ describe('Howto', () => {
|
||||
// Assert: Check for the correct number of chevrons
|
||||
const chevrons = wrapper.getAllByTestId('breadcrumbsChevron')
|
||||
expect(chevrons).toHaveLength(1)
|
||||
}).not.toThrow()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -40,7 +40,7 @@ vi.mock('../../config/config', () => ({
|
||||
}))
|
||||
|
||||
describe('howtos.search', () => {
|
||||
it('searches for text', async () => {
|
||||
it('searches for text', () => {
|
||||
// prepare
|
||||
const words = ['test', 'text']
|
||||
|
||||
@@ -61,7 +61,7 @@ describe('howtos.search', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('filters by category', async () => {
|
||||
it('filters by category', () => {
|
||||
// prepare
|
||||
const category = 'cat1'
|
||||
|
||||
@@ -78,7 +78,7 @@ describe('howtos.search', () => {
|
||||
expect(mockWhere).toHaveBeenCalledWith('category._id', '==', category)
|
||||
})
|
||||
|
||||
it('should not call orderBy if sorting by most relevant', async () => {
|
||||
it('should not call orderBy if sorting by most relevant', () => {
|
||||
// act
|
||||
exportedForTesting.createQueries(
|
||||
['test'],
|
||||
@@ -92,7 +92,7 @@ describe('howtos.search', () => {
|
||||
expect(mockOrderBy).toHaveBeenCalledTimes(0)
|
||||
})
|
||||
|
||||
it('should call orderBy when sorting is not MostRelevant', async () => {
|
||||
it('should call orderBy when sorting is not MostRelevant', () => {
|
||||
// act
|
||||
exportedForTesting.createQueries(
|
||||
['test'],
|
||||
|
||||
@@ -51,7 +51,7 @@ vi.mock('src/common/hooks/useCommonStores', () => ({
|
||||
}))
|
||||
|
||||
describe('Maps', () => {
|
||||
it('prompts on load for user current position', async () => {
|
||||
it('prompts on load for user current position', () => {
|
||||
Object.defineProperty(global.navigator, 'geolocation', {
|
||||
writable: true,
|
||||
value: {
|
||||
@@ -59,28 +59,30 @@ describe('Maps', () => {
|
||||
},
|
||||
})
|
||||
|
||||
await act(async () => {
|
||||
await Wrapper()
|
||||
act(() => {
|
||||
Wrapper()
|
||||
})
|
||||
|
||||
waitFor(() => {
|
||||
expect(global.navigator.geolocation.getCurrentPosition).toBeCalled()
|
||||
})
|
||||
|
||||
it('loads individual map card', async () => {
|
||||
let wrapper: any
|
||||
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper('/map#abc')
|
||||
})
|
||||
|
||||
await waitFor(async () => {
|
||||
it('loads individual map card', () => {
|
||||
let wrapper: any
|
||||
|
||||
act(() => {
|
||||
wrapper = Wrapper('/map#abc')
|
||||
})
|
||||
|
||||
waitFor(() => {
|
||||
expect(wrapper.mockMapPinService.getMapPinByUserId).toBeCalledWith('abc')
|
||||
expect(wrapper.renderResult.getByText('description')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const Wrapper = async (path = '/map') => {
|
||||
const Wrapper = (path = '/map') => {
|
||||
const router = createMemoryRouter(
|
||||
createRoutesFromElements(<Route path="/map" element={<Maps />} />),
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from 'react-router-dom'
|
||||
import { ThemeProvider } from '@emotion/react'
|
||||
import { faker } from '@faker-js/faker'
|
||||
import { act, render, within } from '@testing-library/react'
|
||||
import { act, render, waitFor, within } from '@testing-library/react'
|
||||
import { Provider } from 'mobx-react'
|
||||
import { UserRole } from 'oa-shared'
|
||||
import { useQuestionStore } from 'src/stores/Question/question.store'
|
||||
@@ -84,7 +84,7 @@ describe('Questions', () => {
|
||||
})
|
||||
|
||||
describe('Breadcrumbs', () => {
|
||||
it('displays breadcrumbs with category', async () => {
|
||||
it('displays breadcrumbs with category', () => {
|
||||
// Arrange
|
||||
mockQuestionItem.title =
|
||||
'Do you prefer camping near a lake or in a forest?'
|
||||
@@ -106,11 +106,12 @@ describe('Questions', () => {
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper = getWrapper()
|
||||
})
|
||||
|
||||
// Assert: Check the breadcrumb items and chevrons
|
||||
waitFor(() => {
|
||||
const breadcrumbItems = wrapper.getAllByTestId('breadcrumbsItem')
|
||||
expect(breadcrumbItems).toHaveLength(3)
|
||||
expect(breadcrumbItems[0]).toHaveTextContent('Question')
|
||||
@@ -129,8 +130,9 @@ describe('Questions', () => {
|
||||
const chevrons = wrapper.getAllByTestId('breadcrumbsChevron')
|
||||
expect(chevrons).toHaveLength(2)
|
||||
})
|
||||
})
|
||||
|
||||
it('displays breadcrumbs without category', async () => {
|
||||
it('displays breadcrumbs without category', () => {
|
||||
// Arrange
|
||||
mockQuestionItem.title =
|
||||
'Do you prefer camping near a lake or in a forest?'
|
||||
@@ -145,11 +147,12 @@ describe('Questions', () => {
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper = getWrapper()
|
||||
})
|
||||
|
||||
// Assert: Check the breadcrumb items and chevrons
|
||||
waitFor(() => {
|
||||
const breadcrumbItems = wrapper.getAllByTestId('breadcrumbsItem')
|
||||
expect(breadcrumbItems).toHaveLength(2)
|
||||
expect(breadcrumbItems[0]).toHaveTextContent('Question')
|
||||
@@ -166,6 +169,7 @@ describe('Questions', () => {
|
||||
expect(chevrons).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const getWrapper = () => {
|
||||
|
||||
@@ -144,14 +144,14 @@ describe('question.routes', () => {
|
||||
expect(wrapper.getByText(/loading/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders an empty state', async () => {
|
||||
it('renders an empty state', () => {
|
||||
let wrapper
|
||||
|
||||
act(() => {
|
||||
wrapper = renderFn('/questions')
|
||||
})
|
||||
|
||||
await waitFor(async () => {
|
||||
waitFor(() => {
|
||||
expect(
|
||||
wrapper.getByText(/Ask your questions and help others out/),
|
||||
).toBeInTheDocument()
|
||||
@@ -469,7 +469,7 @@ describe('question.routes', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('redirects non-author', async () => {
|
||||
it('redirects non-author', () => {
|
||||
let wrapper
|
||||
mockActiveUser = FactoryUser({ userName: 'not-author' })
|
||||
;(useQuestionStore as Mock).mockReturnValue({
|
||||
@@ -487,7 +487,7 @@ describe('question.routes', () => {
|
||||
wrapper = renderFn('/questions/slug/edit')
|
||||
})
|
||||
|
||||
await waitFor(async () => {
|
||||
waitFor(() => {
|
||||
expect(() => wrapper.getByText(editFormTitle)).toThrow()
|
||||
expect(mockedUsedNavigate).toBeCalledWith('/questions/slug')
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ vi.mock('../../config/config', () => ({
|
||||
}))
|
||||
|
||||
describe('question.search', () => {
|
||||
it('searches for text', async () => {
|
||||
it('searches for text', () => {
|
||||
// prepare
|
||||
const words = ['test', 'text']
|
||||
|
||||
@@ -51,7 +51,7 @@ describe('question.search', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('filters by category', async () => {
|
||||
it('filters by category', () => {
|
||||
// prepare
|
||||
const category = 'cat1'
|
||||
|
||||
@@ -66,7 +66,7 @@ describe('question.search', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not call orderBy if sorting by most relevant', async () => {
|
||||
it('should not call orderBy if sorting by most relevant', () => {
|
||||
// act
|
||||
exportedForTesting.createQueries(['test'], '', 'MostRelevant')
|
||||
|
||||
@@ -74,7 +74,7 @@ describe('question.search', () => {
|
||||
expect(mockOrderBy).toHaveBeenCalledTimes(0)
|
||||
})
|
||||
|
||||
it('should call orderBy when sorting is not MostRelevant', async () => {
|
||||
it('should call orderBy when sorting is not MostRelevant', () => {
|
||||
// act
|
||||
exportedForTesting.createQueries(['test'], '', 'Newest')
|
||||
|
||||
@@ -82,7 +82,7 @@ describe('question.search', () => {
|
||||
expect(mockOrderBy).toHaveBeenLastCalledWith('_created', 'desc')
|
||||
})
|
||||
|
||||
it('should limit results', async () => {
|
||||
it('should limit results', () => {
|
||||
// prepare
|
||||
const take = 12
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('ResearchErrors', () => {
|
||||
await screen.findByText(descriptionTitle, { exact: false })
|
||||
})
|
||||
|
||||
it('renders nothing when not visible', async () => {
|
||||
it('renders nothing when not visible', () => {
|
||||
const errors = {}
|
||||
const labels = {}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ vi.mock('src/stores/Research/research.store', () => {
|
||||
|
||||
describe('Research update form', () => {
|
||||
describe('Invalid file warning', () => {
|
||||
it('Does not appear when submitting only fileLink', async () => {
|
||||
it('Does not appear when submitting only fileLink', () => {
|
||||
const formValues = FactoryResearchItemUpdate({
|
||||
fileLink: 'www.filedonwload.test',
|
||||
})
|
||||
@@ -46,7 +46,7 @@ describe('Research update form', () => {
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('Does not appear when submitting only files', async () => {
|
||||
it('Does not appear when submitting only files', () => {
|
||||
// Arrange
|
||||
const formValues = FactoryResearchItemUpdate({
|
||||
files: [new File(['test file content'], 'test-file.zip')],
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('Research Article', () => {
|
||||
incrementViewCount: vi.fn(),
|
||||
}
|
||||
|
||||
it('displays content statistics', async () => {
|
||||
it('displays content statistics', () => {
|
||||
// Arrange
|
||||
const activeResearchItem = FactoryResearchItem({
|
||||
collaborators: undefined,
|
||||
@@ -89,11 +89,12 @@ describe('Research Article', () => {
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper = getWrapper()
|
||||
})
|
||||
|
||||
// Assert
|
||||
waitFor(() => {
|
||||
expect(
|
||||
wrapper.getByText(`${activeResearchItem.total_views} views`),
|
||||
).toBeInTheDocument()
|
||||
@@ -102,8 +103,9 @@ describe('Research Article', () => {
|
||||
expect(wrapper.getByText('0 comments')).toBeInTheDocument()
|
||||
expect(wrapper.getByText('1 step')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('does not display contributors when undefined', async () => {
|
||||
it('does not display contributors when undefined', () => {
|
||||
// Arrange
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -114,7 +116,7 @@ describe('Research Article', () => {
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper = getWrapper()
|
||||
})
|
||||
|
||||
@@ -124,7 +126,7 @@ describe('Research Article', () => {
|
||||
}).toThrow()
|
||||
})
|
||||
|
||||
it('displays contributors', async () => {
|
||||
it('displays contributors', () => {
|
||||
// Arrange
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -135,18 +137,20 @@ describe('Research Article', () => {
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper = getWrapper()
|
||||
})
|
||||
|
||||
// Assert
|
||||
waitFor(() => {
|
||||
expect(wrapper.getAllByText('With contributions from:')).toHaveLength(1)
|
||||
expect(wrapper.getAllByText('example-username')).toHaveLength(2)
|
||||
expect(wrapper.getAllByText('another-example-username')).toHaveLength(2)
|
||||
expect(wrapper.getAllByTestId('Username: known flag')).toHaveLength(4)
|
||||
})
|
||||
})
|
||||
|
||||
it('displays "Follow" button for non-subscriber', async () => {
|
||||
it('displays "Follow" button for non-subscriber', () => {
|
||||
// Arrange
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -158,9 +162,11 @@ describe('Research Article', () => {
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper = getWrapper()
|
||||
})
|
||||
|
||||
waitFor(() => {
|
||||
const followButton = wrapper.getAllByTestId('follow-button')[0]
|
||||
|
||||
// Assert
|
||||
@@ -168,11 +174,12 @@ describe('Research Article', () => {
|
||||
expect(followButton).toHaveTextContent('Follow')
|
||||
expect(followButton).not.toHaveTextContent('Following')
|
||||
})
|
||||
})
|
||||
|
||||
it.todo('displays "Following" button for subscriber')
|
||||
|
||||
// TODO: Work out how to simulate store subscribe functionality
|
||||
// it('displays "Following" button for subscriber', async () => {
|
||||
// it('displays "Following" button for subscriber', () => {
|
||||
// // Arrange
|
||||
// ;(useResearchStore as Mock).mockReturnValue({
|
||||
// ...mockResearchStore,
|
||||
@@ -185,7 +192,7 @@ describe('Research Article', () => {
|
||||
|
||||
// // Act
|
||||
// let wrapper
|
||||
// await act(async () => {
|
||||
// act( () => {
|
||||
// wrapper = getWrapper()
|
||||
// })
|
||||
// const followButton = wrapper.getAllByTestId('follow-button')[0]
|
||||
@@ -195,7 +202,7 @@ describe('Research Article', () => {
|
||||
// })
|
||||
|
||||
describe('Research Update', () => {
|
||||
it('displays contributors', async () => {
|
||||
it('displays contributors', () => {
|
||||
// Arrange
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -229,11 +236,12 @@ describe('Research Article', () => {
|
||||
|
||||
// wait for Promise to resolve and state to update
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper = getWrapper()
|
||||
})
|
||||
|
||||
// Assert
|
||||
waitFor(() => {
|
||||
expect(wrapper.getAllByText('With contributions from:')).toHaveLength(1)
|
||||
expect(wrapper.getAllByText('example-username')).toHaveLength(2)
|
||||
expect(wrapper.getAllByText('another-example-username')).toHaveLength(2)
|
||||
@@ -242,8 +250,9 @@ describe('Research Article', () => {
|
||||
expect(wrapper.getAllByTestId('collaborator/creator')).toHaveLength(1)
|
||||
expect(wrapper.getAllByTestId('Username: known flag')).toHaveLength(5)
|
||||
})
|
||||
})
|
||||
|
||||
it('does not show edit timestamp, when create displays the same value', async () => {
|
||||
it('does not show edit timestamp, when create displays the same value', () => {
|
||||
const created = faker.date.past()
|
||||
const modified = new Date(created)
|
||||
modified.setHours(15)
|
||||
@@ -267,14 +276,14 @@ describe('Research Article', () => {
|
||||
const wrapper = getWrapper()
|
||||
|
||||
// Assert
|
||||
await waitFor(async () => {
|
||||
waitFor(() => {
|
||||
expect(() =>
|
||||
wrapper.getAllByText(`edited ${formatDate(modified)}`),
|
||||
).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
it('does show both created and edit timestamp, when different', async () => {
|
||||
it('does show both created and edit timestamp, when different', () => {
|
||||
const modified = faker.date.future()
|
||||
const update = FactoryResearchItemUpdate({
|
||||
_created: faker.date.past().toString(),
|
||||
@@ -298,7 +307,7 @@ describe('Research Article', () => {
|
||||
const wrapper = getWrapper()
|
||||
|
||||
// Assert
|
||||
await waitFor(async () => {
|
||||
waitFor(() => {
|
||||
expect(() =>
|
||||
wrapper.getAllByText(`edited ${formatDate(modified)}`),
|
||||
).not.toThrow()
|
||||
@@ -306,7 +315,7 @@ describe('Research Article', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('shows only published updates', async () => {
|
||||
it('shows only published updates', () => {
|
||||
// Arrange
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -329,17 +338,19 @@ describe('Research Article', () => {
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper = getWrapper()
|
||||
})
|
||||
|
||||
// Assert
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText('Research Update #1')).toBeInTheDocument()
|
||||
expect(wrapper.queryByText('Research Update #2')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Breadcrumbs', () => {
|
||||
it('displays breadcrumbs with category', async () => {
|
||||
it('displays breadcrumbs with category', () => {
|
||||
// Arrange
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -358,11 +369,12 @@ describe('Research Article', () => {
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper = getWrapper()
|
||||
})
|
||||
|
||||
// Assert: Check the breadcrumb items and chevrons
|
||||
waitFor(() => {
|
||||
const breadcrumbItems = wrapper.getAllByTestId('breadcrumbsItem')
|
||||
expect(breadcrumbItems).toHaveLength(3)
|
||||
expect(breadcrumbItems[0]).toHaveTextContent('Research')
|
||||
@@ -379,8 +391,9 @@ describe('Research Article', () => {
|
||||
const chevrons = wrapper.getAllByTestId('breadcrumbsChevron')
|
||||
expect(chevrons).toHaveLength(2)
|
||||
})
|
||||
})
|
||||
|
||||
it('displays breadcrumbs without category', async () => {
|
||||
it('displays breadcrumbs without category', () => {
|
||||
// Arrange
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -392,11 +405,12 @@ describe('Research Article', () => {
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
act(() => {
|
||||
wrapper = getWrapper()
|
||||
})
|
||||
|
||||
// Assert: Check the breadcrumb items and chevrons
|
||||
waitFor(() => {
|
||||
const breadcrumbItems = wrapper.getAllByTestId('breadcrumbsItem')
|
||||
expect(breadcrumbItems).toHaveLength(2)
|
||||
expect(breadcrumbItems[0]).toHaveTextContent('Research')
|
||||
@@ -411,6 +425,7 @@ describe('Research Article', () => {
|
||||
expect(chevrons).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const getWrapper = () => {
|
||||
|
||||
@@ -108,7 +108,7 @@ describe('research.routes', () => {
|
||||
})
|
||||
|
||||
describe('/research/', () => {
|
||||
it('renders the research listing', async () => {
|
||||
it('renders the research listing', () => {
|
||||
const researchTitle = faker.lorem.words(3)
|
||||
const researchSlug = faker.lorem.slug()
|
||||
|
||||
@@ -132,7 +132,7 @@ describe('research.routes', () => {
|
||||
|
||||
const wrapper = renderFn('/research')
|
||||
|
||||
await vi.waitFor(
|
||||
vi.waitFor(
|
||||
() =>
|
||||
expect(
|
||||
wrapper.getByText(/Help out with Research & Development/),
|
||||
@@ -145,13 +145,13 @@ describe('research.routes', () => {
|
||||
})
|
||||
|
||||
describe('/research/:slug', () => {
|
||||
it('renders an individual research article', async () => {
|
||||
it('renders an individual research article', () => {
|
||||
let wrapper
|
||||
act(() => {
|
||||
wrapper = renderFn('/research/research-slug')
|
||||
})
|
||||
|
||||
await vi.waitFor(
|
||||
vi.waitFor(
|
||||
() => {
|
||||
expect(wrapper.queryByTestId('research-title')).toHaveTextContent(
|
||||
'Research article title',
|
||||
@@ -165,34 +165,34 @@ describe('research.routes', () => {
|
||||
})
|
||||
|
||||
describe('/research/create', () => {
|
||||
it('rejects a request without a user present', async () => {
|
||||
it('rejects a request without a user present', () => {
|
||||
mockActiveUser.userRoles = []
|
||||
let wrapper
|
||||
act(() => {
|
||||
wrapper = renderFn('/research/create')
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(
|
||||
wrapper.getByText(/role required to access this page/),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects a logged in user missing required role', async () => {
|
||||
it('rejects a logged in user missing required role', () => {
|
||||
let wrapper
|
||||
act(() => {
|
||||
wrapper = renderFn('/research/create')
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(
|
||||
wrapper.getByText(/role required to access this page/),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('accepts a logged in user with required role [research_creator]', async () => {
|
||||
it('accepts a logged in user with required role [research_creator]', () => {
|
||||
let wrapper
|
||||
act(() => {
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_CREATOR]
|
||||
@@ -200,7 +200,7 @@ describe('research.routes', () => {
|
||||
wrapper = renderFn('/research/create')
|
||||
})
|
||||
|
||||
await vi.waitFor(
|
||||
vi.waitFor(
|
||||
() => {
|
||||
expect(wrapper.getByText(/start your research/i)).toBeInTheDocument()
|
||||
},
|
||||
@@ -210,14 +210,14 @@ describe('research.routes', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('accepts a logged in user with required role [research_creator]', async () => {
|
||||
it('accepts a logged in user with required role [research_creator]', () => {
|
||||
let wrapper
|
||||
act(() => {
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_EDITOR]
|
||||
|
||||
wrapper = renderFn('/research/create')
|
||||
})
|
||||
await vi.waitFor(
|
||||
vi.waitFor(
|
||||
() => {
|
||||
expect(wrapper.getByText(/start your research/i)).toBeInTheDocument()
|
||||
},
|
||||
@@ -229,7 +229,7 @@ describe('research.routes', () => {
|
||||
})
|
||||
|
||||
describe('/research/:slug/edit', () => {
|
||||
it('rejects a request without a user present', async () => {
|
||||
it('rejects a request without a user present', () => {
|
||||
mockActiveUser.userRoles = []
|
||||
|
||||
let wrapper
|
||||
@@ -237,14 +237,14 @@ describe('research.routes', () => {
|
||||
wrapper = renderFn('/research/an-example/edit')
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(
|
||||
wrapper.getByText(/role required to access this page/),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('accepts a logged in user with required role', async () => {
|
||||
it('accepts a logged in user with required role', () => {
|
||||
let wrapper
|
||||
act(() => {
|
||||
mockActiveUser.userName = 'Jaasper'
|
||||
@@ -253,12 +253,12 @@ describe('research.routes', () => {
|
||||
wrapper = renderFn('/research/an-example/edit')
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(wrapper.getByText(/edit your research/i)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects a logged in user with required role but not author of document', async () => {
|
||||
it('rejects a logged in user with required role but not author of document', () => {
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_EDITOR]
|
||||
|
||||
// Arrange
|
||||
@@ -275,12 +275,12 @@ describe('research.routes', () => {
|
||||
renderFn('/research/an-example/edit')
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(mockedUsedNavigate).toHaveBeenCalledWith('/research/an-example')
|
||||
})
|
||||
})
|
||||
|
||||
it('blocks a valid editor when document is locked by another user', async () => {
|
||||
it('blocks a valid editor when document is locked by another user', () => {
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_EDITOR]
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -300,7 +300,7 @@ describe('research.routes', () => {
|
||||
wrapper = renderFn('/research/an-example/edit')
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(
|
||||
wrapper.getByText(
|
||||
'The research description is currently being edited by another editor.',
|
||||
@@ -309,7 +309,7 @@ describe('research.routes', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('accepts a user when document is mark locked by them', async () => {
|
||||
it('accepts a user when document is mark locked by them', () => {
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_EDITOR]
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -329,12 +329,12 @@ describe('research.routes', () => {
|
||||
wrapper = renderFn('/research/an-example/edit')
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(wrapper.getByText('Edit your Research')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('accepts a user with required role and contributor acccess', async () => {
|
||||
it('accepts a user with required role and contributor acccess', () => {
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_EDITOR]
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -350,14 +350,14 @@ describe('research.routes', () => {
|
||||
wrapper = renderFn('/research/an-example/edit')
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(wrapper.getByText(/edit your research/i)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('/research/:slug/new-update', () => {
|
||||
it('rejects a request without a user present', async () => {
|
||||
it('rejects a request without a user present', () => {
|
||||
mockActiveUser.userRoles = []
|
||||
|
||||
let wrapper
|
||||
@@ -365,41 +365,41 @@ describe('research.routes', () => {
|
||||
wrapper = renderFn('/research/an-example/new-update')
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(
|
||||
wrapper.getByText(/role required to access this page/),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('accepts a logged in user with required role', async () => {
|
||||
it('accepts a logged in user with required role', () => {
|
||||
let wrapper
|
||||
act(() => {
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_EDITOR]
|
||||
wrapper = renderFn('/research/an-example/new-update')
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(wrapper.getByTestId('EditResearchUpdate')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('/research/:slug/edit-update/:id', () => {
|
||||
it('rejects a request without a user present', async () => {
|
||||
it('rejects a request without a user present', () => {
|
||||
mockActiveUser.userRoles = []
|
||||
const wrapper = renderFn(
|
||||
'/research/an-example/edit-update/nested-research-update',
|
||||
)
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(
|
||||
wrapper.getByText(/role required to access this page/),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('accept logged in author present', async () => {
|
||||
it('accept logged in author present', () => {
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_EDITOR]
|
||||
// Arrange
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
@@ -424,12 +424,12 @@ describe('research.routes', () => {
|
||||
)
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(wrapper.getByTestId(/EditResearchUpdate/i)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('blocks valid author when document is locked', async () => {
|
||||
it('blocks valid author when document is locked', () => {
|
||||
// Arrange
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_EDITOR]
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
@@ -455,7 +455,7 @@ describe('research.routes', () => {
|
||||
'/research/an-example/edit-update/nested-research-update',
|
||||
)
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(
|
||||
wrapper.getByText(
|
||||
/This research update is currently being edited by another editor/,
|
||||
@@ -464,7 +464,7 @@ describe('research.routes', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('accepts a user when document is mark locked by them', async () => {
|
||||
it('accepts a user when document is mark locked by them', () => {
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_EDITOR]
|
||||
;(useResearchStore as Mock).mockReturnValue({
|
||||
...mockResearchStore,
|
||||
@@ -488,12 +488,12 @@ describe('research.routes', () => {
|
||||
'/research/an-example/edit-update/nested-research-update',
|
||||
)
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(wrapper.getByText('Edit your update')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects logged in user who is not author', async () => {
|
||||
it('rejects logged in user who is not author', () => {
|
||||
mockActiveUser.userRoles = []
|
||||
|
||||
let wrapper
|
||||
@@ -503,14 +503,14 @@ describe('research.routes', () => {
|
||||
)
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(
|
||||
wrapper.getByText(/role required to access this page/),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('accept logged in user who is collaborator', async () => {
|
||||
it('accept logged in user who is collaborator', () => {
|
||||
mockActiveUser.userRoles = [UserRole.RESEARCH_EDITOR]
|
||||
|
||||
// Arrange
|
||||
@@ -535,7 +535,7 @@ describe('research.routes', () => {
|
||||
)
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
vi.waitFor(() => {
|
||||
expect(wrapper.getByTestId(/EditResearchUpdate/i)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -37,7 +37,7 @@ vi.mock('../../config/config', () => ({
|
||||
}))
|
||||
|
||||
describe('research.search', () => {
|
||||
it('searches for text', async () => {
|
||||
it('searches for text', () => {
|
||||
// prepare
|
||||
const words = ['test', 'text']
|
||||
|
||||
@@ -52,7 +52,7 @@ describe('research.search', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('filters by category', async () => {
|
||||
it('filters by category', () => {
|
||||
// prepare
|
||||
const category = 'cat1'
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('research.search', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not call orderBy if sorting by most relevant', async () => {
|
||||
it('should not call orderBy if sorting by most relevant', () => {
|
||||
// act
|
||||
exportedForTesting.createSearchQuery(['test'], '', 'MostRelevant', null)
|
||||
|
||||
@@ -75,7 +75,7 @@ describe('research.search', () => {
|
||||
expect(mockOrderBy).toHaveBeenCalledTimes(0)
|
||||
})
|
||||
|
||||
it('should call orderBy when sorting is not MostRelevant', async () => {
|
||||
it('should call orderBy when sorting is not MostRelevant', () => {
|
||||
// act
|
||||
exportedForTesting.createSearchQuery(['test'], '', 'Newest', null)
|
||||
|
||||
@@ -83,7 +83,7 @@ describe('research.search', () => {
|
||||
expect(mockOrderBy).toHaveBeenLastCalledWith('_created', 'desc')
|
||||
})
|
||||
|
||||
it('should filter by research status', async () => {
|
||||
it('should filter by research status', () => {
|
||||
// act
|
||||
exportedForTesting.createSearchQuery(
|
||||
['test'],
|
||||
@@ -100,7 +100,7 @@ describe('research.search', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should limit results', async () => {
|
||||
it('should limit results', () => {
|
||||
// prepare
|
||||
const take = 12
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { IResearch, IUserPPDB } from 'src/models'
|
||||
|
||||
describe('Research Helpers', () => {
|
||||
describe('Research Update Status Filter', () => {
|
||||
it('should not show item when deleted', async () => {
|
||||
it('should not show item when deleted', () => {
|
||||
// prepare
|
||||
const user = { _id: 'author' } as IUserPPDB
|
||||
const item = { _createdBy: user._id } as IResearch.Item
|
||||
@@ -20,7 +20,7 @@ describe('Research Helpers', () => {
|
||||
expect(show).toEqual(false)
|
||||
})
|
||||
|
||||
it('should not show item when deleted and draft', async () => {
|
||||
it('should not show item when deleted and draft', () => {
|
||||
// prepare
|
||||
const user = { _id: 'author' } as IUserPPDB
|
||||
const item = { _createdBy: user._id } as IResearch.Item
|
||||
@@ -36,7 +36,7 @@ describe('Research Helpers', () => {
|
||||
expect(show).toEqual(false)
|
||||
})
|
||||
|
||||
it('should not show when draft and not author', async () => {
|
||||
it('should not show when draft and not author', () => {
|
||||
// prepare
|
||||
const user = { _id: 'non-author' } as IUserPPDB
|
||||
const item = { _createdBy: 'author' } as IResearch.Item
|
||||
@@ -49,7 +49,7 @@ describe('Research Helpers', () => {
|
||||
expect(show).toEqual(false)
|
||||
})
|
||||
|
||||
it('should not show when draft and not authenticated', async () => {
|
||||
it('should not show when draft and not authenticated', () => {
|
||||
// prepare
|
||||
const user = { _id: 'author' } as IUserPPDB
|
||||
const item = { _createdBy: user._id } as IResearch.Item
|
||||
@@ -62,7 +62,7 @@ describe('Research Helpers', () => {
|
||||
expect(show).toEqual(false)
|
||||
})
|
||||
|
||||
it('should show when not draft and not deleted', async () => {
|
||||
it('should show when not draft and not deleted', () => {
|
||||
// prepare
|
||||
const user = { _id: 'author' } as IUserPPDB
|
||||
const item = { _createdBy: user._id } as IResearch.Item
|
||||
@@ -77,7 +77,7 @@ describe('Research Helpers', () => {
|
||||
expect(show).toEqual(true)
|
||||
})
|
||||
|
||||
it('should show when draft and current user is the author', async () => {
|
||||
it('should show when draft and current user is the author', () => {
|
||||
// prepare
|
||||
const user = { _id: 'author' } as IUserPPDB
|
||||
const item = { _createdBy: user._id } as IResearch.Item
|
||||
@@ -90,7 +90,7 @@ describe('Research Helpers', () => {
|
||||
expect(show).toEqual(true)
|
||||
})
|
||||
|
||||
it('should show when draft and current user is a collaborator', async () => {
|
||||
it('should show when draft and current user is a collaborator', () => {
|
||||
// prepare
|
||||
const user = { _id: 'author' } as IUserPPDB
|
||||
const item = { collaborators: [user._id] } as IResearch.Item
|
||||
@@ -103,7 +103,7 @@ describe('Research Helpers', () => {
|
||||
expect(show).toEqual(true)
|
||||
})
|
||||
|
||||
it('should show when draft and current user is an Admin', async () => {
|
||||
it('should show when draft and current user is an Admin', () => {
|
||||
// prepare
|
||||
const user = { _id: 'admin', userRoles: [UserRole.ADMIN] } as IUserPPDB
|
||||
const item = {} as IResearch.Item
|
||||
|
||||
@@ -57,7 +57,7 @@ describe('UserContactForm', () => {
|
||||
await screen.findByText(contact.successMessage)
|
||||
})
|
||||
|
||||
it('renders nothing if not profile is not contactable', async () => {
|
||||
it('renders nothing if not profile is not contactable', () => {
|
||||
const uncontactable = FactoryUser({ isContactableByPublic: false })
|
||||
|
||||
const { container } = render(
|
||||
|
||||
@@ -64,7 +64,7 @@ describe('Impact', () => {
|
||||
await screen.findByText('45 volunteers')
|
||||
await screen.findByText('23,000 Kg of plastic recycled')
|
||||
await screen.findByText('$ 54,000 revenue')
|
||||
const machineField = await screen.queryByText('13 machines built')
|
||||
const machineField = screen.queryByText('13 machines built')
|
||||
expect(machineField).toBe(null)
|
||||
|
||||
for (const year of IMPACT_YEARS) {
|
||||
|
||||
@@ -16,7 +16,7 @@ describe('ImpactField', () => {
|
||||
await screen.findByText('23,000 Kg of plastic recycled')
|
||||
})
|
||||
|
||||
it('renders nothing when field is not set to be visible', async () => {
|
||||
it('renders nothing when field is not set to be visible', () => {
|
||||
const field = {
|
||||
id: 'plastic',
|
||||
value: 3,
|
||||
@@ -28,7 +28,7 @@ describe('ImpactField', () => {
|
||||
expect(container.innerHTML).toBe('')
|
||||
})
|
||||
|
||||
it("renders nothing when field isn't found in question data", async () => {
|
||||
it("renders nothing when field isn't found in question data", () => {
|
||||
const field = {
|
||||
id: 'nothing',
|
||||
value: 3,
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
RouterProvider,
|
||||
} from 'react-router-dom'
|
||||
import { ThemeProvider } from '@emotion/react'
|
||||
import { act, render } from '@testing-library/react'
|
||||
import { act, render, waitFor } from '@testing-library/react'
|
||||
import { Provider } from 'mobx-react'
|
||||
import { useCommonStores } from 'src/common/hooks/useCommonStores'
|
||||
import { FactoryUser } from 'src/test/factories/User'
|
||||
@@ -58,32 +58,36 @@ describe('User', () => {
|
||||
vi.resetAllMocks()
|
||||
})
|
||||
|
||||
it('displays user page', async () => {
|
||||
it('displays user page', () => {
|
||||
const user = FactoryUser()
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await getWrapper(user)
|
||||
act(() => {
|
||||
wrapper = getWrapper(user)
|
||||
})
|
||||
|
||||
// Assert
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText(user.displayName)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('displays user not found page', async () => {
|
||||
it('displays user not found page', () => {
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await getWrapper(null, '/u/does-not-exist')
|
||||
act(() => {
|
||||
wrapper = getWrapper(null, '/u/does-not-exist')
|
||||
})
|
||||
|
||||
// Assert
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText('User not found')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('workspace', () => {
|
||||
it('handles workspace with no images', async () => {
|
||||
it('handles workspace with no images', () => {
|
||||
const user = FactoryUser({
|
||||
profileType: 'workspace',
|
||||
coverImages: [],
|
||||
@@ -91,17 +95,19 @@ describe('User', () => {
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await getWrapper(user)
|
||||
act(() => {
|
||||
wrapper = getWrapper(user)
|
||||
})
|
||||
|
||||
// Assert
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText('No images available.')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const getWrapper = async (user, url?) => {
|
||||
const getWrapper = (user, url?) => {
|
||||
mockGetUserProfile.mockResolvedValue(user)
|
||||
|
||||
const router = createMemoryRouter(createRoutesFromElements(UserRoutes), {
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
RouterProvider,
|
||||
} from 'react-router-dom'
|
||||
import { ThemeProvider } from '@emotion/react'
|
||||
import { act, render } from '@testing-library/react'
|
||||
import { act, render, waitFor } from '@testing-library/react'
|
||||
import { Provider } from 'mobx-react'
|
||||
import { IModerationStatus } from 'oa-shared'
|
||||
import { useCommonStores } from 'src/common/hooks/useCommonStores'
|
||||
@@ -19,6 +19,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { SettingsPage } from './SettingsPage'
|
||||
|
||||
import type { IUserPPDB } from 'src/models'
|
||||
|
||||
const Theme = testingThemeStyles
|
||||
|
||||
// eslint-disable-next-line prefer-const
|
||||
@@ -67,81 +69,101 @@ describe('UserSettings', () => {
|
||||
vi.resetAllMocks()
|
||||
})
|
||||
|
||||
it('displays user settings', async () => {
|
||||
it('displays user settings', () => {
|
||||
mockUser = FactoryUser()
|
||||
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser)
|
||||
})
|
||||
|
||||
// Assert
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText('Edit profile'))
|
||||
})
|
||||
})
|
||||
|
||||
it('displays one photo for member', async () => {
|
||||
it('displays one photo for member', () => {
|
||||
mockUser = FactoryUser({ profileType: 'member' })
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser)
|
||||
})
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(1)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser)
|
||||
})
|
||||
|
||||
it('displays four photos for collection point', async () => {
|
||||
waitFor(() => {
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
it('displays four photos for collection point', () => {
|
||||
mockUser = FactoryUser({ profileType: 'collection-point' })
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser)
|
||||
})
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(4)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser)
|
||||
})
|
||||
|
||||
it('displays four photos for community builder', async () => {
|
||||
waitFor(() => {
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(4)
|
||||
})
|
||||
})
|
||||
|
||||
it('displays four photos for community builder', () => {
|
||||
mockUser = FactoryUser({ profileType: 'community-builder' })
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser)
|
||||
})
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(4)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser)
|
||||
})
|
||||
|
||||
it('displays four photos for machine builder', async () => {
|
||||
waitFor(() => {
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(4)
|
||||
})
|
||||
})
|
||||
|
||||
it('displays four photos for machine builder', () => {
|
||||
mockUser = FactoryUser({ profileType: 'machine-builder' })
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser)
|
||||
})
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(4)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser)
|
||||
})
|
||||
|
||||
it('displays four photos for space', async () => {
|
||||
waitFor(() => {
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(4)
|
||||
})
|
||||
})
|
||||
|
||||
it('displays four photos for space', () => {
|
||||
mockUser = FactoryUser({ profileType: 'space' })
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser)
|
||||
})
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(4)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser)
|
||||
})
|
||||
|
||||
it('displays four photos for workspace', async () => {
|
||||
waitFor(() => {
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(4)
|
||||
})
|
||||
})
|
||||
|
||||
it('displays four photos for workspace', () => {
|
||||
mockUser = FactoryUser({ profileType: 'workspace' })
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser)
|
||||
})
|
||||
|
||||
waitFor(() => {
|
||||
expect(wrapper.getAllByTestId('cover-image')).toHaveLength(4)
|
||||
})
|
||||
})
|
||||
|
||||
describe('map pin', () => {
|
||||
it('displays moderation comments to user', async () => {
|
||||
it('displays moderation comments to user', () => {
|
||||
mockUser = FactoryUser({ profileType: 'workspace' })
|
||||
mockGetPin.mockResolvedValue(
|
||||
FactoryMapPin({
|
||||
@@ -151,13 +173,16 @@ describe('UserSettings', () => {
|
||||
)
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser)
|
||||
})
|
||||
expect(wrapper.getByText('Moderator comment')).toBeInTheDocument()
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser)
|
||||
})
|
||||
|
||||
it('does not show moderation comments for approved pin', async () => {
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText('Moderator comment')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('does not show moderation comments for approved pin', () => {
|
||||
mockUser = FactoryUser({ profileType: 'workspace' })
|
||||
mockGetPin.mockResolvedValue(
|
||||
FactoryMapPin({
|
||||
@@ -167,8 +192,8 @@ describe('UserSettings', () => {
|
||||
)
|
||||
// Act
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser)
|
||||
})
|
||||
|
||||
expect(() => wrapper.getByText('Moderator comment')).toThrow()
|
||||
@@ -178,7 +203,7 @@ describe('UserSettings', () => {
|
||||
const scrollIntoViewMock = vi.fn()
|
||||
window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock
|
||||
|
||||
it('expands and scrolls to impact section if a #impact_year hash is provided and year is valid', async () => {
|
||||
it('expands and scrolls to impact section if a #impact_year hash is provided and year is valid', () => {
|
||||
mockUser = FactoryUser({
|
||||
profileType: 'workspace',
|
||||
})
|
||||
@@ -187,14 +212,15 @@ describe('UserSettings', () => {
|
||||
const { expandClose } = buttons.impact
|
||||
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser, impactHash)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser, impactHash)
|
||||
})
|
||||
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText(expandClose)).toBeInTheDocument()
|
||||
expect(scrollIntoViewMock).toBeCalled()
|
||||
})
|
||||
it('does not expand impact section if hash syntax is not correct', async () => {
|
||||
})
|
||||
it('does not expand impact section if hash syntax is not correct', () => {
|
||||
mockUser = FactoryUser({
|
||||
profileType: 'workspace',
|
||||
})
|
||||
@@ -203,15 +229,17 @@ describe('UserSettings', () => {
|
||||
const { expandOpen } = buttons.impact
|
||||
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser, impactHash)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser, impactHash)
|
||||
})
|
||||
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText(expandOpen)).toBeInTheDocument()
|
||||
expect(scrollIntoViewMock).not.toBeCalled()
|
||||
})
|
||||
})
|
||||
|
||||
it('does not expand impact section if no impact hash is provided', async () => {
|
||||
it('does not expand impact section if no impact hash is provided', () => {
|
||||
mockUser = FactoryUser({
|
||||
profileType: 'workspace',
|
||||
})
|
||||
@@ -219,17 +247,19 @@ describe('UserSettings', () => {
|
||||
const { expandOpen } = buttons.impact
|
||||
|
||||
let wrapper
|
||||
await act(async () => {
|
||||
wrapper = await Wrapper(mockUser, impactHash)
|
||||
act(() => {
|
||||
wrapper = Wrapper(mockUser, impactHash)
|
||||
})
|
||||
|
||||
waitFor(() => {
|
||||
expect(wrapper.getByText(expandOpen)).toBeInTheDocument()
|
||||
expect(scrollIntoViewMock).not.toBeCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const Wrapper = async (user, routerInitialEntry?) => {
|
||||
const Wrapper = (user: IUserPPDB, routerInitialEntry?: string) => {
|
||||
if (routerInitialEntry !== undefined) {
|
||||
// impact section is only displayed if isPreciousPlastic() is true
|
||||
window.localStorage.setItem('platformTheme', 'precious-plastic')
|
||||
|
||||
@@ -13,7 +13,7 @@ const supportedProfileTypes = getSupportedProfileTypes().map(
|
||||
)
|
||||
|
||||
describe('Focus', () => {
|
||||
it('render focus section if more than one activity available', async () => {
|
||||
it('render focus section if more than one activity available', () => {
|
||||
const badges = supportedProfileTypes.reduce(
|
||||
(a, v) => ({
|
||||
...a,
|
||||
@@ -36,7 +36,7 @@ describe('Focus', () => {
|
||||
expect(screen.queryByText(headings.focus)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not render focus section if less than two activities available', async () => {
|
||||
it('does not render focus section if less than two activities available', () => {
|
||||
const badges = {
|
||||
[supportedProfileTypes[0]]: {
|
||||
lowDetail: '',
|
||||
|
||||
@@ -122,8 +122,8 @@ describe('PatreonIntegration', () => {
|
||||
expect(screen.getByText(REMOVE_BUTTON_TEXT)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls removePatreonConnection when "Remove Connection" button is clicked', async () => {
|
||||
await act(async () => {
|
||||
it('calls removePatreonConnection when "Remove Connection" button is clicked', () => {
|
||||
act(() => {
|
||||
fireEvent.click(screen.getByText(REMOVE_BUTTON_TEXT))
|
||||
})
|
||||
expect(mockRemovePatreonConnection).toHaveBeenCalledWith(
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('SettingsErrors', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('renders nothing when not visible', async () => {
|
||||
it('renders nothing when not visible', () => {
|
||||
const errors = {
|
||||
title: 'Make sure this field is filled correctly',
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { DiscussionStore } from './discussions.store'
|
||||
import type { IDiscussion, IUserPPDB } from 'src/models'
|
||||
import type { IRootStore } from '../RootStore'
|
||||
|
||||
const factory = async (
|
||||
const factory = (
|
||||
discussions: IDiscussion[] = [FactoryDiscussion({})],
|
||||
activeUser: IUserPPDB = FactoryUser(),
|
||||
) => {
|
||||
@@ -70,7 +70,7 @@ describe('discussion.store', () => {
|
||||
it('fetches a discussion by sourceId', async () => {
|
||||
const fakeSourceId = faker.internet.password()
|
||||
const fakePrimaryContentId = faker.internet.password()
|
||||
const { store, getWhereFn } = await factory([
|
||||
const { store, getWhereFn } = factory([
|
||||
FactoryDiscussion({ sourceId: fakeSourceId }),
|
||||
])
|
||||
|
||||
@@ -85,7 +85,7 @@ describe('discussion.store', () => {
|
||||
})
|
||||
|
||||
it('creates a discussion if one does not exist', async () => {
|
||||
const { store, getWhereFn, setFn } = await factory()
|
||||
const { store, getWhereFn, setFn } = factory()
|
||||
|
||||
getWhereFn.mockReturnValueOnce([])
|
||||
|
||||
@@ -109,7 +109,7 @@ describe('discussion.store', () => {
|
||||
|
||||
describe('uploadDiscussion', () => {
|
||||
it('creates a new discussion with sourceId and sourceType provided', async () => {
|
||||
const { store, discussionItem, setFn } = await factory()
|
||||
const { store, discussionItem, setFn } = factory()
|
||||
|
||||
await store.uploadDiscussion(
|
||||
discussionItem.sourceId,
|
||||
@@ -126,7 +126,7 @@ describe('discussion.store', () => {
|
||||
|
||||
describe('addComment', () => {
|
||||
it('adds a new comment for questions', async () => {
|
||||
const { store, discussionItem, setFn, getFn } = await factory()
|
||||
const { store, discussionItem, setFn, getFn } = factory()
|
||||
|
||||
//Act
|
||||
await store.addComment(discussionItem, 'New comment')
|
||||
@@ -151,7 +151,7 @@ describe('discussion.store', () => {
|
||||
})
|
||||
|
||||
it('adds a reply to a comment', async () => {
|
||||
const { store, discussionItem, setFn } = await factory([
|
||||
const { store, discussionItem, setFn } = factory([
|
||||
FactoryDiscussion({
|
||||
comments: [FactoryDiscussionComment({ text: 'New comment' })],
|
||||
}),
|
||||
@@ -186,8 +186,8 @@ describe('discussion.store', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('handles error fetching discussion', async () => {
|
||||
const { store, discussionItem, setFn, getFn } = await factory()
|
||||
it('handles error fetching discussion', () => {
|
||||
const { store, discussionItem, setFn, getFn } = factory()
|
||||
|
||||
getFn.mockReturnValue(null)
|
||||
//Act
|
||||
@@ -202,7 +202,7 @@ describe('discussion.store', () => {
|
||||
|
||||
describe('editComent', () => {
|
||||
it('allows author to make changes comment', async () => {
|
||||
const { store, discussionItem, setFn } = await factory(
|
||||
const { store, discussionItem, setFn } = factory(
|
||||
[
|
||||
FactoryDiscussion({
|
||||
comments: [
|
||||
@@ -238,7 +238,7 @@ describe('discussion.store', () => {
|
||||
})
|
||||
|
||||
it('allows admin to make changes comment', async () => {
|
||||
const { store, discussionItem, setFn } = await factory(
|
||||
const { store, discussionItem, setFn } = factory(
|
||||
[
|
||||
FactoryDiscussion({
|
||||
comments: [
|
||||
@@ -274,8 +274,8 @@ describe('discussion.store', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('throws an error for a different user', async () => {
|
||||
const { store, discussionItem, setFn } = await factory([
|
||||
it('throws an error for a different user', () => {
|
||||
const { store, discussionItem, setFn } = factory([
|
||||
FactoryDiscussion({
|
||||
comments: [
|
||||
FactoryDiscussionComment({
|
||||
@@ -303,7 +303,7 @@ describe('discussion.store', () => {
|
||||
_creatorId: 'fake-user',
|
||||
text: 'New comment',
|
||||
})
|
||||
const { store, setFn, discussionItem } = await factory(
|
||||
const { store, setFn, discussionItem } = factory(
|
||||
[FactoryDiscussion({ comments: [comment] })],
|
||||
FactoryUser({ _id: 'fake-user' }),
|
||||
)
|
||||
@@ -324,7 +324,7 @@ describe('discussion.store', () => {
|
||||
_creatorId: 'not-admin-user',
|
||||
text: 'New comment',
|
||||
})
|
||||
const { store, setFn, discussionItem } = await factory(
|
||||
const { store, setFn, discussionItem } = factory(
|
||||
[FactoryDiscussion({ comments: [comment] })],
|
||||
FactoryUser({
|
||||
_id: 'admin-user',
|
||||
@@ -340,8 +340,8 @@ describe('discussion.store', () => {
|
||||
expect(setFn.mock.calls[0][0].comments[0]._deleted).toEqual(true)
|
||||
})
|
||||
|
||||
it('throws an error for a different user', async () => {
|
||||
const { store, discussionItem, setFn } = await factory([
|
||||
it('throws an error for a different user', () => {
|
||||
const { store, discussionItem, setFn } = factory([
|
||||
FactoryDiscussion({
|
||||
comments: [
|
||||
FactoryDiscussionComment({
|
||||
|
||||
@@ -23,7 +23,7 @@ vi.mock('../common/toggleDocUsefulByUser', () => ({
|
||||
toggleDocUsefulByUser: () => mockToggleDocUsefulByUser(),
|
||||
}))
|
||||
|
||||
const factory = async () => {
|
||||
const factory = () => {
|
||||
const store = new QuestionStore({} as IRootStore)
|
||||
store.isTitleThatReusesSlug = vi.fn().mockResolvedValue(false)
|
||||
|
||||
@@ -64,7 +64,7 @@ const factory = async () => {
|
||||
describe('question.store', () => {
|
||||
describe('upsertQuestion', () => {
|
||||
it('assigns _createdBy', async () => {
|
||||
const { store, setFn } = await factory()
|
||||
const { store, setFn } = factory()
|
||||
const newQuestion = FactoryQuestionItem({
|
||||
title: 'So what is plastic?',
|
||||
_createdBy: undefined,
|
||||
@@ -83,7 +83,7 @@ describe('question.store', () => {
|
||||
|
||||
describe('fetchQuestionBySlug', () => {
|
||||
it('handles empty query response', async () => {
|
||||
const { store } = await factory()
|
||||
const { store } = factory()
|
||||
const newQuestion = FactoryQuestionItem({
|
||||
title: 'How do you survive living in a tent?',
|
||||
})
|
||||
@@ -93,7 +93,7 @@ describe('question.store', () => {
|
||||
})
|
||||
|
||||
it('returns a valid response', async () => {
|
||||
const { store, getWhereFn } = await factory()
|
||||
const { store, getWhereFn } = factory()
|
||||
const newQuestion = FactoryQuestionItem({
|
||||
title: 'Question title',
|
||||
})
|
||||
@@ -108,7 +108,7 @@ describe('question.store', () => {
|
||||
})
|
||||
|
||||
it('returns a valid response when a previous slug', async () => {
|
||||
const { store, getWhereFn } = await factory()
|
||||
const { store, getWhereFn } = factory()
|
||||
const newQuestion = FactoryQuestionItem({
|
||||
title: 'Can I run a shredder at home?',
|
||||
previousSlugs: ['shredder-at-home'],
|
||||
@@ -125,7 +125,7 @@ describe('question.store', () => {
|
||||
|
||||
describe('incrementViews', () => {
|
||||
it('increments views by one', async () => {
|
||||
const { store, updateFn } = await factory()
|
||||
const { store, updateFn } = factory()
|
||||
|
||||
const question = FactoryQuestionItem({
|
||||
title: 'which trees to cut down',
|
||||
@@ -149,7 +149,7 @@ describe('question.store', () => {
|
||||
|
||||
describe('toggleSubscriberStatusByUserName', () => {
|
||||
it('calls the toggle subscriber function', async () => {
|
||||
const { store } = await factory()
|
||||
const { store } = factory()
|
||||
store.activeQuestionItem = FactoryQuestionItem()
|
||||
|
||||
await store.toggleSubscriberStatusByUserName()
|
||||
@@ -160,7 +160,7 @@ describe('question.store', () => {
|
||||
|
||||
describe('toggleUsefulByUser', () => {
|
||||
it('calls the toogle voted for function', async () => {
|
||||
const { store } = await factory()
|
||||
const { store } = factory()
|
||||
store.activeQuestionItem = FactoryQuestionItem()
|
||||
|
||||
await store.toggleUsefulByUser()
|
||||
|
||||
@@ -32,10 +32,10 @@ vi.mock('firebase/firestore', () => ({
|
||||
increment: (value) => mockIncrement(value),
|
||||
}))
|
||||
|
||||
const factoryResearchItem = async (researchItemOverloads: any = {}, ...rest) =>
|
||||
const factoryResearchItem = (researchItemOverloads: any = {}, ...rest) =>
|
||||
factory(FactoryResearchItem, researchItemOverloads, ...rest)
|
||||
|
||||
const factoryResearchItemFormInput = async (
|
||||
const factoryResearchItemFormInput = (
|
||||
researchItemOverloads: any = {},
|
||||
...rest
|
||||
) => factory(FactoryResearchItemFormInput, researchItemOverloads, ...rest)
|
||||
|
||||
@@ -65,7 +65,7 @@ describe('triggerNotification', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('throws error when invalid user passed', async () => {
|
||||
it('throws error when invalid user passed', () => {
|
||||
// Act
|
||||
expect(
|
||||
store.triggerNotification(
|
||||
@@ -93,15 +93,15 @@ describe('notifications.store', () => {
|
||||
]
|
||||
store.userStore.user.notifications = FactoryNotificationSample()
|
||||
})
|
||||
it('loads user with notifications', async () => {
|
||||
it('loads user with notifications', () => {
|
||||
const notifications = store.userStore.user?.notifications
|
||||
expect(notifications).toHaveLength(6)
|
||||
})
|
||||
it('gets unnotified notifications', async () => {
|
||||
it('gets unnotified notifications', () => {
|
||||
const unnotified = store.getUnnotifiedNotifications()
|
||||
expect(unnotified).toHaveLength(2)
|
||||
})
|
||||
it('gets unread notifications', async () => {
|
||||
it('gets unread notifications', () => {
|
||||
const unread = store.getUnreadNotifications()
|
||||
expect(unread).toHaveLength(3)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user