Skip to content

Commit

Permalink
Adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hovancik committed Feb 21, 2022
1 parent f412970 commit cf9342a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const log = require('electron-log')
const path = require('path')
log.transports.file.resolvePath = () => path.join(remote.app.getPath('userData'), 'logs/main.log')


window.onload = (e) => {
ipcRenderer.on('playSound', (event, file, volume) => {
const audio = new Audio(`audio/${file}.wav`)
Expand Down
66 changes: 66 additions & 0 deletions test/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,70 @@ describe('commands', () => {
const cmd = new Command(input, '1.2.3')
cmd.durationToMs(null).should.be.equal(-1)
})

it('parses a number scheduler as the number of minutes to break', () => {
const input = ['long', '-w', '60']
const cmd = new Command(input, '1.2.3')
cmd.waitToMs(null).should.be.equal(60 * 60 * 1000)
})

it('parses a scheduler argument with hours and minutes', () => {
const input = ['long', '-w', '4h39m']
const cmd = new Command(input, '1.2.3')
cmd.waitToMs(null).should.be.equal(4 * 60 * 60 * 1000 + 39 * 60 * 1000)
})

it('parses a scheduler argument with hours and minutes in the upper case', () => {
const input = ['long', '-w', '4H39M']
const cmd = new Command(input, '1.2.3')
cmd.waitToMs(null).should.be.equal(4 * 60 * 60 * 1000 + 39 * 60 * 1000)
})

it('parses a scheduler argument with just the minutes', () => {
const input = ['long', '-w', '60m']
const cmd = new Command(input, '1.2.3')
cmd.waitToMs(null).should.be.equal(60 * 60 * 1000)
})

it('parses a scheduler argument with just the hours', () => {
const input = ['long', '-w', '184h']
const cmd = new Command(input, '1.2.3')
cmd.waitToMs(null).should.be.equal(184 * 60 * 60 * 1000)
})

it('returns -1 if there\'s extra text in the scheduler argument', () => {
new Command(['long', '-w', 'foo4h39mbar'], '1.2.3').waitToMs(null).should.be.equal(-1)
new Command(['long', '-w', 'foo4h39m'], '1.2.3').waitToMs(null).should.be.equal(-1)
new Command(['long', '-w', '4h39mbar'], '1.2.3').waitToMs(null).should.be.equal(-1)
})

it('returns -1 if a number scheduler argument is zero', () => {
const input = ['long', '-w', '0']
const cmd = new Command(input, '1.2.3')
cmd.waitToMs(null).should.be.equal(-1)
})

it('returns -1 if the scheduler argument with the hours and minutes evaluates to zero', () => {
const input = ['long', '-w', '0h0m']
const cmd = new Command(input, '1.2.3')
cmd.waitToMs(null).should.be.equal(-1)
})

it('returns -1 if the scheduler argument with just the minutes evaluates to zero', () => {
const input = ['long', '-w', '0m']
const cmd = new Command(input, '1.2.3')
cmd.waitToMs(null).should.be.equal(-1)
})

it('returns -1 if the scheduler argument with just the hours evaluates to zero', () => {
const input = ['long', '-w', '0h']
const cmd = new Command(input, '1.2.3')
cmd.waitToMs(null).should.be.equal(-1)
})

it('should return -1 if the scheduler argument is not in a known format', () => {
const input = ['long', '-w', '10i20k']
const cmd = new Command(input, '1.2.3')
cmd.waitToMs(null).should.be.equal(-1)
})
})

0 comments on commit cf9342a

Please sign in to comment.