mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-03 09:23:50 -05:00
6a6f155029
* Fix split-tests loading in React component: use `useSplitTestContext` instead of `getSplitTestVariant` * Replace use of `isSplitTestEnabled` by `useSplitTestContext` * Add SplitTestProvider to roots, and fix tests * Create `useFeatureFlag` hook * Use `useFeatureFlag` where applicable GitOrigin-RevId: 9ff7bb3975d50bc4d07d74d93c482d56dc96f615
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { expect } from 'chai'
|
|
import { render, screen } from '@testing-library/react'
|
|
import { SubscriptionDashboardProvider } from '../../../../../../frontend/js/features/subscription/context/subscription-dashboard-context'
|
|
import fetchMock from 'fetch-mock'
|
|
import ManagedPublishers, {
|
|
Publisher,
|
|
} from '../../../../../../frontend/js/features/subscription/components/dashboard/managed-publishers'
|
|
import { SplitTestProvider } from '@/shared/context/split-test-context'
|
|
|
|
const userId = 'fff999fff999'
|
|
const publisher1 = {
|
|
slug: 'pub-1',
|
|
managerIds: [],
|
|
name: 'Pub 1',
|
|
partner: 'p1',
|
|
}
|
|
const publisher2 = {
|
|
slug: 'pub-2',
|
|
managerIds: [],
|
|
name: 'Pub 2',
|
|
partner: 'p2',
|
|
}
|
|
const managedPublishers: Publisher[] = [publisher1, publisher2]
|
|
|
|
describe('<ManagedPublishers />', function () {
|
|
beforeEach(function () {
|
|
window.metaAttributesCache = new Map()
|
|
window.metaAttributesCache.set('ol-managedPublishers', managedPublishers)
|
|
window.user_id = userId
|
|
})
|
|
|
|
afterEach(function () {
|
|
window.metaAttributesCache = new Map()
|
|
delete window.user_id
|
|
fetchMock.reset()
|
|
})
|
|
|
|
it('renders all managed publishers', function () {
|
|
render(
|
|
<SplitTestProvider>
|
|
<SubscriptionDashboardProvider>
|
|
<ManagedPublishers />
|
|
</SubscriptionDashboardProvider>
|
|
</SplitTestProvider>
|
|
)
|
|
|
|
const elements = screen.getAllByText('You are a', {
|
|
exact: false,
|
|
})
|
|
expect(elements.length).to.equal(2)
|
|
expect(elements[0].textContent).to.equal('You are a manager of Pub 1')
|
|
expect(elements[1].textContent).to.equal('You are a manager of Pub 2')
|
|
|
|
const links = screen.getAllByRole('link')
|
|
expect(links[0].getAttribute('href')).to.equal('/publishers/pub-1/hub')
|
|
expect(links[1].getAttribute('href')).to.equal(
|
|
'/manage/publishers/pub-1/managers'
|
|
)
|
|
expect(links[2].getAttribute('href')).to.equal('/publishers/pub-2/hub')
|
|
expect(links[3].getAttribute('href')).to.equal(
|
|
'/manage/publishers/pub-2/managers'
|
|
)
|
|
})
|
|
|
|
it('renders nothing when there are no publishers', function () {
|
|
window.metaAttributesCache.set('ol-managedPublishers', undefined)
|
|
|
|
render(
|
|
<SplitTestProvider>
|
|
<SubscriptionDashboardProvider>
|
|
<ManagedPublishers />
|
|
</SubscriptionDashboardProvider>
|
|
</SplitTestProvider>
|
|
)
|
|
const elements = screen.queryAllByText('You are a', {
|
|
exact: false,
|
|
})
|
|
expect(elements.length).to.equal(0)
|
|
})
|
|
})
|