| 1 |
'use strict'; |
| 2 |
|
| 3 |
const { mount, flushPromises } = require( '@vue/test-utils' ); |
| 4 |
const { mockMwApiGet } = require( './SpecialBlock.setup.js' ); |
| 5 |
const TargetBlockLog = require( '../../../resources/src/mediawiki.special.block/components/TargetBlockLog.vue' ); |
| 6 |
|
| 7 |
beforeAll( () => mockMwApiGet() ); |
| 8 |
|
| 9 |
describe( 'TargetBlockLog', () => { |
| 10 |
it( 'should show a table with one row when given a user with one block', async () => { |
| 11 |
const wrapper = mount( TargetBlockLog, { |
| 12 |
propsData: { targetUser: 'ExampleUser' } |
| 13 |
} ); |
| 14 |
await flushPromises(); |
| 15 |
|
| 16 |
expect( wrapper.find( '.cdx-table__table' ).exists() ).toBeTruthy(); |
| 17 |
const rows = wrapper.findAll( '.cdx-table__table tbody tr' ); |
| 18 |
|
| 19 |
expect( rows ).toHaveLength( 1 ); |
| 20 |
} ); |
| 21 |
it( 'should show a table with the no-previous-blocks message when given a user with no blocks', async () => { |
| 22 |
const wrapper = mount( TargetBlockLog, { |
| 23 |
propsData: { targetUser: 'NeverBlocked' } |
| 24 |
} ); |
| 25 |
await flushPromises(); |
| 26 |
|
| 27 |
expect( wrapper.find( '.cdx-table__table' ).exists() ).toBeTruthy(); |
| 28 |
const rows = wrapper.findAll( '.cdx-table__table tbody tr' ); |
| 29 |
|
| 30 |
expect( rows ).toHaveLength( 1 ); |
| 31 |
|
| 32 |
expect( rows[ 0 ].text() ).toContain( 'block-user-no-previous-blocks' ); |
| 33 |
} ); |
| 34 |
it( 'should show a table with ten rows, and a show more link, when given a user with more than ten blocks', async () => { |
| 35 |
const wrapper = mount( TargetBlockLog, { |
| 36 |
propsData: { targetUser: 'BlockedALot' } |
| 37 |
} ); |
| 38 |
await flushPromises(); |
| 39 |
|
| 40 |
expect( wrapper.find( '.cdx-table__table' ).exists() ).toBeTruthy(); |
| 41 |
const rows = wrapper.findAll( '.cdx-table__table tbody tr' ); |
| 42 |
|
| 43 |
expect( rows ).toHaveLength( 10 ); |
| 44 |
|
| 45 |
expect( wrapper.find( '.mw-block-fulllog' ).exists() ).toBeTruthy(); |
| 46 |
} ); |
| 47 |
} ); |