2023-02-22 06:50:24 -05:00
|
|
|
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'
|
2024-06-18 06:01:37 -04:00
|
|
|
import ManagedPublishers from '../../../../../../frontend/js/features/subscription/components/dashboard/managed-publishers'
|
2024-04-30 10:58:34 -04:00
|
|
|
import { SplitTestProvider } from '@/shared/context/split-test-context'
|
2024-06-18 06:01:37 -04:00
|
|
|
import { Publisher } from '../../../../../../types/subscription/dashboard/publisher'
|
2023-02-22 06:50:24 -05:00
|
|
|
|
|
|
|
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.set('ol-managedPublishers', managedPublishers)
|
2024-06-18 06:01:37 -04:00
|
|
|
window.metaAttributesCache.set('ol-user_id', userId)
|
2023-02-22 06:50:24 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
fetchMock.reset()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders all managed publishers', function () {
|
|
|
|
render(
|
2024-04-30 10:58:34 -04:00
|
|
|
<SplitTestProvider>
|
|
|
|
<SubscriptionDashboardProvider>
|
|
|
|
<ManagedPublishers />
|
|
|
|
</SubscriptionDashboardProvider>
|
|
|
|
</SplitTestProvider>
|
2023-02-22 06:50:24 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
2023-06-08 09:19:32 -04:00
|
|
|
const links = screen.getAllByRole('link')
|
|
|
|
expect(links[0].getAttribute('href')).to.equal('/publishers/pub-1/hub')
|
|
|
|
expect(links[1].getAttribute('href')).to.equal(
|
2023-02-22 06:50:24 -05:00
|
|
|
'/manage/publishers/pub-1/managers'
|
|
|
|
)
|
2023-06-08 09:19:32 -04:00
|
|
|
expect(links[2].getAttribute('href')).to.equal('/publishers/pub-2/hub')
|
|
|
|
expect(links[3].getAttribute('href')).to.equal(
|
2023-02-22 06:50:24 -05:00
|
|
|
'/manage/publishers/pub-2/managers'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders nothing when there are no publishers', function () {
|
|
|
|
window.metaAttributesCache.set('ol-managedPublishers', undefined)
|
|
|
|
|
|
|
|
render(
|
2024-04-30 10:58:34 -04:00
|
|
|
<SplitTestProvider>
|
|
|
|
<SubscriptionDashboardProvider>
|
|
|
|
<ManagedPublishers />
|
|
|
|
</SubscriptionDashboardProvider>
|
|
|
|
</SplitTestProvider>
|
2023-02-22 06:50:24 -05:00
|
|
|
)
|
|
|
|
const elements = screen.queryAllByText('You are a', {
|
|
|
|
exact: false,
|
|
|
|
})
|
|
|
|
expect(elements.length).to.equal(0)
|
|
|
|
})
|
|
|
|
})
|