-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from hemit-s/jat-61
JAT-61 Cucumber Testing
- Loading branch information
Showing
18 changed files
with
27,327 additions
and
16,611 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ jobs: | |
npm run package | ||
npm run lint | ||
npm exec tsc | ||
npm test | ||
npm run test:unit |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/__tests__/cucumber_tests/features/set_band_gain.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Feature: Set gain of a frequency band | ||
Users want to change the gain of a filter applied to a certain frequency | ||
|
||
Scenario: Move slider to bottom | ||
Given Peace is installed | ||
And Peace is running | ||
And Aqua is not running | ||
When Aqua is launched | ||
And I set gain of slider of frequency 100Hz to bottom | ||
Then Peace should show gain of -30dB for frequency 100Hz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { loadFeature, defineFeature } from 'jest-cucumber'; | ||
import getRandomValuesPolyPony from 'get-random-values-polypony'; // Need this to fix jest-cucumber's reliance on uuid's getRandomValues | ||
import { | ||
Driver, | ||
startChromeDriver, | ||
stopChromeDriver, | ||
} from '__tests__/utils/webdriver'; | ||
import { givenAquaIsNotRunning, whenAquaIsLaunched } from './shared_steps/aqua'; | ||
import { whenSetFrequencyGain } from './shared_steps/aquaSlider'; | ||
import { | ||
givenPeaceIsRunning, | ||
givenPeaceIsInstalled, | ||
thenPeaceFrequencyGain, | ||
} from './shared_steps/peace'; | ||
|
||
// shim the getRandomValues function used in uuid which is used by jest-cucumber | ||
// so that it works in electron environment. | ||
getRandomValuesPolyPony.polyfill(); | ||
const chromeDriver = startChromeDriver(); | ||
|
||
const feature = loadFeature( | ||
'./src/__tests__/cucumber_tests/features/set_band_gain.feature' | ||
); | ||
const webdriver: { driver: Driver } = { driver: undefined }; | ||
|
||
defineFeature(feature, (test) => { | ||
test('Move slider to bottom', async ({ given, when, then }) => { | ||
givenPeaceIsInstalled(given); | ||
givenPeaceIsRunning(given); | ||
givenAquaIsNotRunning(given); | ||
|
||
whenAquaIsLaunched(when, webdriver, chromeDriver); | ||
whenSetFrequencyGain(when, webdriver); | ||
|
||
thenPeaceFrequencyGain(then, webdriver); | ||
}, 30000); | ||
}); | ||
|
||
afterAll(() => { | ||
if (webdriver.driver) { | ||
webdriver.driver.deleteSession(); | ||
} | ||
stopChromeDriver(chromeDriver); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ChildProcessWithoutNullStreams } from 'child_process'; | ||
import { DefineStepFunction } from 'jest-cucumber'; | ||
import getWebDriver, { Driver } from '__tests__/utils/webdriver'; | ||
|
||
export const givenAquaIsNotRunning = (given: DefineStepFunction) => { | ||
given('Aqua is not running', () => { | ||
// TODO find out how to check if aqua is not running. find a way to close aqua | ||
}); | ||
}; | ||
|
||
export const whenAquaIsLaunched = ( | ||
when: DefineStepFunction, | ||
webdriver: { driver: Driver | undefined }, | ||
chromeDriverProcess: ChildProcessWithoutNullStreams | ||
) => { | ||
when('Aqua is launched', async () => { | ||
webdriver.driver = await getWebDriver(chromeDriverProcess); | ||
// Wait 10 seconds for the app to launch and load screen | ||
await new Promise((resolve) => setTimeout(resolve, 10000)); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { DefineStepFunction } from 'jest-cucumber'; | ||
import { Driver } from '__tests__/utils/webdriver'; | ||
|
||
export const whenSetFrequencyGain = ( | ||
when: DefineStepFunction, | ||
webdriver: { driver: Driver | undefined } | ||
) => { | ||
when( | ||
/^I set gain of slider of frequency (\d+)Hz to (top|middle|bottom)$/, | ||
async (frequency: number, position: string) => { | ||
const sliderElem = await webdriver.driver.$( | ||
`[name="${frequency}-range"]` | ||
); | ||
const coord = { x: 0, y: 0 }; | ||
if (position === 'top') { | ||
coord.y = -100; | ||
} else if (position === 'bottom') { | ||
coord.y = 100; | ||
} | ||
sliderElem.dragAndDrop(coord); | ||
// wait 1000 ms for the action. | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
} | ||
); | ||
}; | ||
|
||
export const givenSetFrequencyGain = ( | ||
given: DefineStepFunction, | ||
webdriver: { driver: Driver | undefined } | ||
) => { | ||
given( | ||
/^I set gain of slider of frequency (\d+)Hz to (top|middle|bottom)$/, | ||
async (frequency: number, position: string) => { | ||
console.log(`frequency: ${frequency}`); | ||
console.log(`position: ${position}`); | ||
// TODO use webdriver io get slider position | ||
console.log(webdriver.driver); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { peaceGainOutputToDb } from 'common/peaceConversions'; | ||
import { | ||
getPeaceWindowHandle, | ||
isPeaceRunning, | ||
sendPeaceCommand, | ||
} from 'common/peaceIPC'; | ||
import { DefineStepFunction } from 'jest-cucumber'; | ||
import { Driver } from '__tests__/utils/webdriver'; | ||
import registry from '../../../main/registry'; | ||
|
||
export const givenPeaceIsInstalled = (given: DefineStepFunction) => { | ||
given('Peace is installed', async () => { | ||
if (!(await registry.isPeaceInstalled())) { | ||
throw new Error('Peace not installed'); | ||
} | ||
// TODO find a way to install peace | ||
}); | ||
}; | ||
|
||
export const givenPeaceIsRunning = (given: DefineStepFunction) => { | ||
given('Peace is running', async () => { | ||
// Need retries as this check can be flakey. | ||
for (let i = 0; i < 3; i += 1) { | ||
const peaceHWnd = getPeaceWindowHandle(); | ||
const foundPeace = isPeaceRunning(peaceHWnd); | ||
if (foundPeace) { | ||
return; | ||
} | ||
// Wait 1s before trying again | ||
// eslint-disable-next-line no-await-in-loop | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
} | ||
throw new Error('Peace not running'); | ||
// For now, we need to manually start peace before running end-to-end tests | ||
}); | ||
}; | ||
|
||
export const thenPeaceFrequencyGain = ( | ||
then: DefineStepFunction, | ||
webdriver: { driver: Driver | undefined } | ||
) => { | ||
then( | ||
/^Peace should show gain of (-?\d+)dB for frequency (\d+)Hz$/, | ||
async (gain: string, frequency: string) => { | ||
const sliderElems = await webdriver.driver | ||
.$('.mainContent') | ||
.$$('div*=Hz'); | ||
for (let i = 0; i < sliderElems.length; i += 1) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const text = await sliderElems[i].getText(); | ||
if (text === `${frequency} Hz`) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const peaceHWnd = getPeaceWindowHandle(); | ||
if (!isPeaceRunning(peaceHWnd)) { | ||
throw new Error('Peace is not running.'); | ||
} | ||
const peaceGain = sendPeaceCommand(peaceHWnd, 100 + i + 1, 5, 0); | ||
expect(peaceGainOutputToDb(peaceGain)).toBe(parseInt(gain, 10)); | ||
return; | ||
} | ||
} | ||
throw new Error(`${frequency} Hz gain band not found.`); | ||
} | ||
); | ||
}; |
2 changes: 1 addition & 1 deletion
2
src/__tests__/App.test.tsx → src/__tests__/unit_tests/App.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__tests__/Switch.test.tsx → src/__tests__/unit_tests/Switch.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { remote, RemoteOptions } from 'webdriverio'; | ||
import path from 'path'; | ||
|
||
import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; | ||
|
||
const options: RemoteOptions = { | ||
hostname: 'localhost', // Use localhost as chrome driver server | ||
port: 9515, // "9515" is the port opened by chrome driver. | ||
capabilities: { | ||
browserName: 'chrome', | ||
'goog:chromeOptions': { | ||
binary: path.join( | ||
process.env.USERPROFILE ? process.env.USERPROFILE : '', | ||
'AppData/Local/Programs/aqua/AQUA.exe' | ||
), | ||
args: [], | ||
}, | ||
}, | ||
}; | ||
|
||
export const startChromeDriver = () => { | ||
return spawn('chromedriver.exe', ['--port=9515'], { | ||
shell: true, | ||
cwd: path.join( | ||
__dirname, | ||
'../../../node_modules/electron-chromedriver/bin' | ||
), | ||
}); | ||
}; | ||
|
||
export const stopChromeDriver = ( | ||
chromeDriverProcess: ChildProcessWithoutNullStreams | ||
) => { | ||
return chromeDriverProcess.kill(9); | ||
}; | ||
|
||
export default async function getWebDriver( | ||
chromeDriverProcess: ChildProcessWithoutNullStreams | ||
) { | ||
if (chromeDriverProcess === undefined) { | ||
throw new Error('chrome driver not started.'); | ||
} | ||
return remote(options); | ||
} | ||
|
||
export type Driver = Awaited<ReturnType<typeof getWebDriver>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Peace returns numerical values as unsigned integers | ||
// This is the offset for the value -1000, used when fetching gain values | ||
const OVERFLOW_OFFSET = 4294967296; | ||
|
||
export const peaceGainOutputToDb = (result: number) => { | ||
const MAX_GAIN = 30; | ||
const MIN_GAIN = -30; | ||
|
||
// If gain is larger than MAX_GAIN, assume that Peace returned an unsigned negative number | ||
// If after adjusting for the unsigned number gives a positive value, default to -30 | ||
if (result / 1000 > MAX_GAIN && (result - OVERFLOW_OFFSET) / 1000 > 0) { | ||
return MIN_GAIN; | ||
} | ||
|
||
const gain = | ||
result / 1000 > MAX_GAIN | ||
? (result - OVERFLOW_OFFSET) / 1000 // Unsigned negative case | ||
: result / 1000; // Positive value case | ||
|
||
// Round up any lower gain values up to MIN_GAIN | ||
return Math.max(gain, MIN_GAIN); | ||
}; | ||
|
||
export const peaceFrequencyOutputToNormal = (result: number) => { | ||
const MAX_FREQUENCY = 22050; | ||
const MIN_FREQUENCY = 10; | ||
|
||
// If gain is larger than the MAX_FREQUENCY, assume that Peace returned an unsigned negative number | ||
// Since frequency shouldn't be negative, default to the MIN_FREQUENCY | ||
if (result > MAX_FREQUENCY) { | ||
return MIN_FREQUENCY; | ||
} | ||
|
||
// Round up any lower frequency values up to MIN_FREQUENCY | ||
return Math.max(result, MIN_FREQUENCY); | ||
}; |
Oops, something went wrong.