refactor tests
This commit is contained in:
parent
b8c60aa948
commit
f795194dc3
|
|
@ -1,3 +1,16 @@
|
|||
import type { Paginator } from '@/scripts/types'
|
||||
|
||||
export function flushPromises() {
|
||||
return new Promise(resolve => setImmediate(resolve))
|
||||
return new Promise((resolve) => setImmediate(resolve))
|
||||
}
|
||||
|
||||
export function createPaginator<T>(data: T[]): Paginator<T> {
|
||||
return {
|
||||
data,
|
||||
total: data.length,
|
||||
from: 1,
|
||||
to: data.length,
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import React from 'react'
|
||||
import { render, waitFor, fireEvent } from '@testing-library/react'
|
||||
import { createPaginator } from '../../utils'
|
||||
import { t } from '@/scripts/i18n'
|
||||
import * as fetch from '@/scripts/net'
|
||||
import { Player, Paginator } from '@/scripts/types'
|
||||
import { Player } from '@/scripts/types'
|
||||
import PlayersManagement from '@/views/admin/PlayersManagement'
|
||||
|
||||
jest.mock('@/scripts/net')
|
||||
|
|
@ -16,17 +17,6 @@ const fixture: Readonly<Player> = Object.freeze<Player>({
|
|||
last_modified: new Date().toString(),
|
||||
})
|
||||
|
||||
function createPaginator(data: Player[]): Paginator<Player> {
|
||||
return {
|
||||
data,
|
||||
total: data.length,
|
||||
from: 1,
|
||||
to: data.length,
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
}
|
||||
}
|
||||
|
||||
beforeAll(() => {
|
||||
Object.assign(window, { innerWidth: 500 })
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import React from 'react'
|
||||
import { render, waitFor, fireEvent } from '@testing-library/react'
|
||||
import { createPaginator } from '../../utils'
|
||||
import { t } from '@/scripts/i18n'
|
||||
import * as fetch from '@/scripts/net'
|
||||
import type { Paginator } from '@/scripts/types'
|
||||
import Translations from '@/views/admin/Translations'
|
||||
import type { Line } from '@/views/admin/Translations/types'
|
||||
|
||||
|
|
@ -17,17 +17,6 @@ const fixtureLine: Readonly<Line> = Object.freeze<Line>({
|
|||
},
|
||||
})
|
||||
|
||||
function createPaginator(data: Line[]): Paginator<Line> {
|
||||
return {
|
||||
data,
|
||||
total: data.length,
|
||||
from: 1,
|
||||
to: data.length,
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
}
|
||||
}
|
||||
|
||||
test('empty text', async () => {
|
||||
const line = { ...fixtureLine, text: { en: '' } }
|
||||
fetch.get.mockResolvedValue(createPaginator([line]))
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import React from 'react'
|
||||
import { render, fireEvent, waitFor } from '@testing-library/react'
|
||||
import { createPaginator } from '../../utils'
|
||||
import { t } from '@/scripts/i18n'
|
||||
import * as fetch from '@/scripts/net'
|
||||
import { Paginator } from '@/scripts/types'
|
||||
import SkinLibrary from '@/views/skinlib/SkinLibrary'
|
||||
import { LibraryItem } from '@/views/skinlib/SkinLibrary/types'
|
||||
|
||||
|
|
@ -18,17 +18,6 @@ const fixtureItem: Readonly<LibraryItem> = Object.freeze<LibraryItem>({
|
|||
likes: 70,
|
||||
})
|
||||
|
||||
function createPaginator(data: LibraryItem[]): Paginator<LibraryItem> {
|
||||
return {
|
||||
data,
|
||||
total: data.length,
|
||||
from: 1,
|
||||
to: data.length,
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
window.blessing.extra = { currentUid: null }
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import React from 'react'
|
||||
import { render, fireEvent, waitFor } from '@testing-library/react'
|
||||
import { createPaginator } from '../../utils'
|
||||
import $ from 'jquery'
|
||||
import { t } from '@/scripts/i18n'
|
||||
import * as fetch from '@/scripts/net'
|
||||
import { ClosetItem, Player, Paginator } from '@/scripts/types'
|
||||
import { ClosetItem, Player } from '@/scripts/types'
|
||||
import Closet from '@/views/user/Closet'
|
||||
|
||||
jest.mock('@/scripts/net')
|
||||
|
|
@ -51,17 +52,6 @@ const fixturePlayer: Readonly<Player> = Object.freeze<Player>({
|
|||
last_modified: new Date().toString(),
|
||||
})
|
||||
|
||||
function createPaginator(data: ClosetItem[]): Paginator<ClosetItem> {
|
||||
return {
|
||||
data,
|
||||
total: data.length,
|
||||
from: 1,
|
||||
to: data.length,
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
const container = document.createElement('div')
|
||||
container.id = 'previewer'
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user