45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
import RulesPage from '@/views/bell/rules/index.vue'
|
|
import { listRules } from '@/api/bell/rule'
|
|
|
|
jest.mock('@/api/bell/rule', () => ({
|
|
createRule: jest.fn(),
|
|
listRules: jest.fn(),
|
|
setRuleEnabled: jest.fn(),
|
|
updateRule: jest.fn()
|
|
}))
|
|
|
|
function pageContext() {
|
|
return {
|
|
loading: false,
|
|
error: '',
|
|
items: [],
|
|
total: 0,
|
|
query: { pageIndex: 1, pageSize: 10, name: '', enabled: null }
|
|
}
|
|
}
|
|
|
|
describe('Bell ordinary warning rule page', () => {
|
|
beforeEach(() => jest.clearAllMocks())
|
|
|
|
it('only enables rule changes for the GoAdmin edit permission', () => {
|
|
expect(RulesPage.computed.canEdit.call({ $store: { getters: { permisaction: ['bell:rule:list'] }}})).toBe(false)
|
|
expect(RulesPage.computed.canEdit.call({ $store: { getters: { permisaction: ['bell:rule:edit'] }}})).toBe(true)
|
|
expect(RulesPage.computed.canEdit.call({ $store: { getters: { permisaction: ['*:*:*'] }}})).toBe(true)
|
|
})
|
|
|
|
it('keeps an empty list as an intentional page state', async() => {
|
|
listRules.mockResolvedValue({ data: { list: [], count: 0 }})
|
|
const context = pageContext()
|
|
await RulesPage.methods.load.call(context)
|
|
expect(context).toMatchObject({ loading: false, error: '', items: [], total: 0 })
|
|
})
|
|
|
|
it('surfaces a failed list request instead of leaving a blank page', async() => {
|
|
listRules.mockRejectedValue(new Error('网络不可用'))
|
|
const context = pageContext()
|
|
await RulesPage.methods.load.call(context)
|
|
expect(context.loading).toBe(false)
|
|
expect(context.error).toBe('网络不可用')
|
|
})
|
|
})
|