|
| 1 | +// Copyright 2020 Las Venturas Playground. All rights reserved. |
| 2 | +// Use of this source code is governed by the MIT license, a copy of which can |
| 3 | +// be found in the LICENSE file. |
| 4 | + |
| 5 | +describe('ColorCommand', (it, beforeEach) => { |
| 6 | + let gunther = null; |
| 7 | + let russell = null; |
| 8 | + |
| 9 | + beforeEach(async () => { |
| 10 | + const feature = server.featureManager.loadFeature('player_commands'); |
| 11 | + |
| 12 | + gunther = server.playerManager.getById(/* Gunther= */ 0); |
| 13 | + russell = server.playerManager.getById(/* Russell= */ 1); |
| 14 | + russell.level = Player.LEVEL_ADMINISTRATOR; |
| 15 | + |
| 16 | + await feature.registry_.initialize(); |
| 17 | + await russell.identify(); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should enable players to change their colors', async (assert) => { |
| 21 | + // (1) Non-VIP players get an error message when changing their colour. |
| 22 | + assert.isTrue(await gunther.issueCommand('/my color')); |
| 23 | + |
| 24 | + assert.equal(gunther.messages.length, 1); |
| 25 | + assert.equal(gunther.messages[0], Message.PLAYER_COMMANDS_REQUIRES_VIP); |
| 26 | + |
| 27 | + assert.isTrue(await russell.issueCommand('/p Russell color')); |
| 28 | + |
| 29 | + assert.equal(russell.messages.length, 1); |
| 30 | + assert.equal(russell.messages[0], Message.PLAYER_COMMANDS_REQUIRES_VIP); |
| 31 | + |
| 32 | + gunther.setVip(true); |
| 33 | + russell.setVip(true); |
| 34 | + |
| 35 | + // (2) It's possible for players to change their own colour. |
| 36 | + { |
| 37 | + const currentColor = russell.color; |
| 38 | + |
| 39 | + assert.isTrue(await russell.issueCommand('/my color')); |
| 40 | + assert.notDeepEqual(russell.color, currentColor); |
| 41 | + |
| 42 | + assert.equal(russell.messages.length, 2); |
| 43 | + assert.equal(russell.messages[1], Message.PLAYER_COMMANDS_COLOR_UPDATED_SELF); |
| 44 | + } |
| 45 | + |
| 46 | + // (3) It's possible for administrators to change other player's colours. |
| 47 | + { |
| 48 | + const currentColor = gunther.color; |
| 49 | + |
| 50 | + assert.isTrue(await russell.issueCommand('/p gunth color')); |
| 51 | + assert.notDeepEqual(gunther.color, currentColor); |
| 52 | + |
| 53 | + assert.equal(russell.messages.length, 4); |
| 54 | + assert.includes( |
| 55 | + russell.messages[2], |
| 56 | + Message.format(Message.PLAYER_COMMANDS_COLOR_UPDATED_FYI_ADMIN, russell.name, |
| 57 | + russell.id, gunther.name, gunther.id, 'FFFF00')); |
| 58 | + |
| 59 | + assert.equal( |
| 60 | + russell.messages[3], |
| 61 | + Message.format(Message.PLAYER_COMMANDS_COLOR_UPDATED_OTHER, gunther.name, |
| 62 | + gunther.id)); |
| 63 | + |
| 64 | + assert.equal(gunther.messages.length, 2); |
| 65 | + assert.equal( |
| 66 | + gunther.messages[1], |
| 67 | + Message.format(Message.PLAYER_COMMANDS_COLOR_UPDATED_FYI, russell.name, |
| 68 | + russell.id)); |
| 69 | + } |
| 70 | + |
| 71 | + // (4) A warning message is shown when trying to update to an invalid color. |
| 72 | + assert.isTrue(await russell.issueCommand('/my color bananarama')); |
| 73 | + |
| 74 | + assert.equal(russell.messages.length, 5); |
| 75 | + assert.equal(russell.messages[4], Message.PLAYER_COMMANDS_COLOR_INVALID_FORMAT); |
| 76 | + |
| 77 | + // (5) Administrators can update colours to specific RGB values. |
| 78 | + { |
| 79 | + const color = 'FFFF00'; |
| 80 | + |
| 81 | + assert.isTrue(await russell.issueCommand('/my color #' + color)); |
| 82 | + assert.equal(russell.color.toHexRGB(), color); |
| 83 | + } |
| 84 | + }); |
| 85 | +}); |
0 commit comments