3131 */
3232
3333import {
34- it ,
35- expect ,
36- describe ,
34+ it ,
35+ expect ,
36+ describe ,
3737} from 'vitest'
3838
3939import {
40- Command ,
41- CommandHistory ,
40+ Command ,
41+ CommandHistory ,
4242} from '@/index'
4343
4444class LightReceiver {
45- protected _isOn = false
45+ protected _isOn = false
4646
47- get isOn ( ) : boolean {
48- return this . _isOn
49- }
47+ get isOn ( ) : boolean {
48+ return this . _isOn
49+ }
5050
51- turnOn ( ) : void {
52- this . _isOn = true
53- }
51+ turnOn ( ) : void {
52+ this . _isOn = true
53+ }
5454
55- turnOff ( ) : void {
56- this . _isOn = false
57- }
55+ turnOff ( ) : void {
56+ this . _isOn = false
57+ }
5858}
5959
6060class TurnOnLightCommand implements Command {
61- protected light : LightReceiver
61+ protected light : LightReceiver
6262
63- constructor ( light : LightReceiver ) {
64- this . light = light
65- }
63+ constructor ( light : LightReceiver ) {
64+ this . light = light
65+ }
6666
67- execute ( ) : boolean {
68- this . light . turnOn ( )
69- return true
70- }
67+ execute ( ) : boolean {
68+ this . light . turnOn ( )
69+ return true
70+ }
7171}
7272
7373class TurnOffLightCommand implements Command {
74- protected light : LightReceiver
74+ protected light : LightReceiver
7575
76- constructor ( light : LightReceiver ) {
77- this . light = light
78- }
76+ constructor ( light : LightReceiver ) {
77+ this . light = light
78+ }
7979
80- execute ( ) : boolean {
81- this . light . turnOff ( )
82- return true
83- }
80+ execute ( ) : boolean {
81+ this . light . turnOff ( )
82+ return true
83+ }
8484}
8585
8686describe ( 'Command' , ( ) => {
87- it ( 'Command execution' , ( ) => {
88- const commandHistory = new CommandHistory ( )
89- const light = new LightReceiver ( )
87+ it ( 'Command execution' , ( ) => {
88+ const commandHistory = new CommandHistory ( )
89+ const light = new LightReceiver ( )
9090
91- const cmd1 = new TurnOnLightCommand ( light )
92- expect ( cmd1 . execute ( ) ) . toBeTruthy ( )
93- expect ( light . isOn ) . toBeTruthy ( )
94- commandHistory . push ( cmd1 )
91+ const cmd1 = new TurnOnLightCommand ( light )
92+ expect ( cmd1 . execute ( ) ) . toBeTruthy ( )
93+ expect ( light . isOn ) . toBeTruthy ( )
94+ commandHistory . push ( cmd1 )
9595
9696
97- const cmd2 = new TurnOffLightCommand ( light )
98- expect ( cmd2 . execute ( ) ) . toBeTruthy ( )
99- expect ( light . isOn ) . toBeFalsy ( )
100- commandHistory . push ( cmd2 )
97+ const cmd2 = new TurnOffLightCommand ( light )
98+ expect ( cmd2 . execute ( ) ) . toBeTruthy ( )
99+ expect ( light . isOn ) . toBeFalsy ( )
100+ commandHistory . push ( cmd2 )
101101
102- expect ( commandHistory . pop ( ) ) . instanceof ( TurnOffLightCommand )
103- expect ( commandHistory . pop ( ) ) . instanceof ( TurnOnLightCommand )
104- expect ( commandHistory . pop ( ) ) . toBeUndefined ( )
105- } )
102+ expect ( commandHistory . pop ( ) ) . instanceof ( TurnOffLightCommand )
103+ expect ( commandHistory . pop ( ) ) . instanceof ( TurnOnLightCommand )
104+ expect ( commandHistory . pop ( ) ) . toBeUndefined ( )
105+ } )
106106} )
0 commit comments