Debian Codegraph @

tests/jest/mediawiki.special.block/stores/block.test.js

raw symbols SCIP
1 'use strict';
2
3 const { setActivePinia, createPinia } = require( 'pinia' );
4 const { mockMwConfigGet } = require( '../SpecialBlock.setup.js' );
5 const useBlockStore = require( '../../../../resources/src/mediawiki.special.block/stores/block.js' );
6
7 describe( 'Block store', () => {
8 beforeEach( () => {
9 // creates a fresh pinia and makes it active
10 // so it's automatically picked up by any useStore() call
11 // without having to pass it to it: `useStore(pinia)`
12 setActivePinia( createPinia() );
13 } );
14
15 it( 'should require confirmation if the target user is the current user', () => {
16 const store = useBlockStore();
17 expect( store.confirmationRequired ).toBe( false );
18 mockMwConfigGet( { wgUserName: 'ExampleUser' } );
19 store.targetUser = 'ExampleUser';
20 expect( store.confirmationRequired ).toBe( true );
21 } );
22
23 it( 'should require confirmation for hide user', () => {
24 const store = useBlockStore();
25 expect( store.confirmationRequired ).toBe( false );
26 store.type = 'sitewide';
27 store.additionalDetails = [ 'wpHideName' ];
28 mw.util.isInfinity = jest.fn().mockReturnValue( true );
29 expect( store.confirmationRequired ).toBe( true );
30 } );
31
32 it( 'should set hideNameDisabled for blocks that aren\'t sitewide with an infinite expiry', () => {
33 const store = useBlockStore();
34 expect( store.hideNameDisabled ).toBe( false );
35 store.type = 'partial';
36 store.expiry = 'infinite';
37 mw.util.isInfinity = jest.fn().mockReturnValue( true );
38 expect( store.hideNameDisabled ).toBe( true );
39 store.type = 'sitewide';
40 store.expiry = '3 hours';
41 mw.util.isInfinity = jest.fn().mockReturnValue( false );
42 expect( store.hideNameDisabled ).toBe( true );
43 store.type = 'sitewide';
44 store.expiry = 'infinite';
45 mw.util.isInfinity = jest.fn().mockReturnValue( true );
46 expect( store.hideNameDisabled ).toBe( false );
47 } );
48 } );