Delete assets/js/dashboard/stats/modals/google-keywords.test.tsx with huggingface_hub
Browse files
assets/js/dashboard/stats/modals/google-keywords.test.tsx
DELETED
|
@@ -1,71 +0,0 @@
|
|
| 1 |
-
import React, { useState, Dispatch, SetStateAction } from 'react'
|
| 2 |
-
import { act, render, screen } from '@testing-library/react'
|
| 3 |
-
import { TestContextProviders } from '../../../../test-utils/app-context-providers'
|
| 4 |
-
import GoogleKeywordsModal from './google-keywords'
|
| 5 |
-
import { MockAPI } from '../../../../test-utils/mock-api'
|
| 6 |
-
|
| 7 |
-
const domain = 'dummy.site'
|
| 8 |
-
|
| 9 |
-
let mockAPI: MockAPI
|
| 10 |
-
|
| 11 |
-
beforeAll(() => {
|
| 12 |
-
mockAPI = new MockAPI().start()
|
| 13 |
-
})
|
| 14 |
-
|
| 15 |
-
afterAll(() => {
|
| 16 |
-
mockAPI.stop()
|
| 17 |
-
})
|
| 18 |
-
|
| 19 |
-
beforeEach(() => {
|
| 20 |
-
mockAPI.clear()
|
| 21 |
-
})
|
| 22 |
-
|
| 23 |
-
beforeEach(() => {
|
| 24 |
-
const modalRoot = document.createElement('div')
|
| 25 |
-
modalRoot.setAttribute('id', 'modal_root')
|
| 26 |
-
document.body.appendChild(modalRoot)
|
| 27 |
-
})
|
| 28 |
-
|
| 29 |
-
afterEach(() => {
|
| 30 |
-
document.getElementById('modal_root')?.remove()
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
describe('GoogleKeywordsModal', () => {
|
| 34 |
-
test('opening the modal for a second time with the same dashboardState gets response from cache', async () => {
|
| 35 |
-
const googleKeywordsHandler = mockAPI.get(
|
| 36 |
-
`/api/stats/${domain}/google-search-terms/`,
|
| 37 |
-
{ results: [] }
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
let setOpen: Dispatch<SetStateAction<boolean>>
|
| 41 |
-
|
| 42 |
-
function ToggleableModal() {
|
| 43 |
-
const [open, s] = useState(false)
|
| 44 |
-
setOpen = s
|
| 45 |
-
return open ? <GoogleKeywordsModal /> : null
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
render(
|
| 49 |
-
<TestContextProviders siteOptions={{ domain }}>
|
| 50 |
-
<ToggleableModal />
|
| 51 |
-
</TestContextProviders>
|
| 52 |
-
)
|
| 53 |
-
|
| 54 |
-
expect(googleKeywordsHandler).toHaveBeenCalledTimes(0)
|
| 55 |
-
act(() => setOpen(true))
|
| 56 |
-
expect(screen.getByText('Google search terms')).toBeVisible()
|
| 57 |
-
expect(googleKeywordsHandler).toHaveBeenCalledTimes(1)
|
| 58 |
-
expect(googleKeywordsHandler).toHaveBeenNthCalledWith(
|
| 59 |
-
1,
|
| 60 |
-
expect.stringContaining('limit=100'),
|
| 61 |
-
expect.anything()
|
| 62 |
-
)
|
| 63 |
-
|
| 64 |
-
act(() => setOpen(false))
|
| 65 |
-
expect(screen.queryByText('Google search terms')).not.toBeInTheDocument()
|
| 66 |
-
act(() => setOpen(true))
|
| 67 |
-
expect(screen.getByText('Google search terms')).toBeVisible()
|
| 68 |
-
|
| 69 |
-
expect(googleKeywordsHandler).toHaveBeenCalledTimes(1)
|
| 70 |
-
})
|
| 71 |
-
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|