Skip to content

Commit

Permalink
updated packages
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-jonathan committed Jan 18, 2025
1 parent fe220d8 commit 065c9c3
Show file tree
Hide file tree
Showing 16 changed files with 3,430 additions and 2,450 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

132 changes: 0 additions & 132 deletions .eslintrc.yml

This file was deleted.

92 changes: 46 additions & 46 deletions __tests__/behavioral/Command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,76 +31,76 @@
*/

import {
it,
expect,
describe,
it,
expect,
describe,
} from 'vitest'

import {
Command,
CommandHistory,
Command,
CommandHistory,
} from '@/index'

class LightReceiver {
protected _isOn = false
protected _isOn = false

get isOn(): boolean {
return this._isOn
}
get isOn(): boolean {
return this._isOn
}

turnOn(): void {
this._isOn = true
}
turnOn(): void {
this._isOn = true
}

turnOff(): void {
this._isOn = false
}
turnOff(): void {
this._isOn = false
}
}

class TurnOnLightCommand implements Command {
protected light: LightReceiver
protected light: LightReceiver

constructor(light: LightReceiver) {
this.light = light
}
constructor(light: LightReceiver) {
this.light = light
}

execute(): boolean {
this.light.turnOn()
return true
}
execute(): boolean {
this.light.turnOn()
return true
}
}

class TurnOffLightCommand implements Command {
protected light: LightReceiver
protected light: LightReceiver

constructor(light: LightReceiver) {
this.light = light
}
constructor(light: LightReceiver) {
this.light = light
}

execute(): boolean {
this.light.turnOff()
return true
}
execute(): boolean {
this.light.turnOff()
return true
}
}

describe('Command', () => {
it('Command execution', () => {
const commandHistory = new CommandHistory()
const light = new LightReceiver()
it('Command execution', () => {
const commandHistory = new CommandHistory()
const light = new LightReceiver()

const cmd1 = new TurnOnLightCommand(light)
expect(cmd1.execute()).toBeTruthy()
expect(light.isOn).toBeTruthy()
commandHistory.push(cmd1)
const cmd1 = new TurnOnLightCommand(light)
expect(cmd1.execute()).toBeTruthy()
expect(light.isOn).toBeTruthy()
commandHistory.push(cmd1)


const cmd2 = new TurnOffLightCommand(light)
expect(cmd2.execute()).toBeTruthy()
expect(light.isOn).toBeFalsy()
commandHistory.push(cmd2)
const cmd2 = new TurnOffLightCommand(light)
expect(cmd2.execute()).toBeTruthy()
expect(light.isOn).toBeFalsy()
commandHistory.push(cmd2)

expect(commandHistory.pop()).instanceof(TurnOffLightCommand)
expect(commandHistory.pop()).instanceof(TurnOnLightCommand)
expect(commandHistory.pop()).toBeUndefined()
})
expect(commandHistory.pop()).instanceof(TurnOffLightCommand)
expect(commandHistory.pop()).instanceof(TurnOnLightCommand)
expect(commandHistory.pop()).toBeUndefined()
})
})
Loading

0 comments on commit 065c9c3

Please sign in to comment.