Fix OS desktop detection tests and edge cases

- Fix test cases not running for desktop OS detection.
- Fixes application throwing error when user agent is undefined.
- Refactor by making os property optional in Environment to explicit
describe its potential undefined state.
This commit is contained in:
undergroundwires
2021-12-11 11:55:43 +01:00
parent 5f091bb6ab
commit a8358b8e7a
2 changed files with 34 additions and 15 deletions

View File

@@ -59,7 +59,21 @@ describe('Environment', () => {
});
});
describe('os', () => {
describe('browser os from BrowserOsDetector', () => {
it('returns undefined without user agent', () => {
// arrange
const expected = undefined;
const mock: IBrowserOsDetector = {
detect: (agent) => {
throw new Error('should not reach here');
},
};
const sut = new SystemUnderTest({ }, mock);
// act
const actual = sut.os;
// assert
expect(actual).to.equal(expected);
});
it('browser os from BrowserOsDetector', () => {
// arrange
const givenUserAgent = 'testUserAgent';
const expected = OperatingSystem.macOS;
@@ -87,17 +101,19 @@ describe('Environment', () => {
userAgent: 'Electron',
};
for (const testCase of DesktopOsTestCases) {
// arrange
const process = {
platform: testCase.processPlatform,
};
// act
const sut = new SystemUnderTest({ navigator, process });
// assert
expect(sut.os).to.equal(testCase.expectedOs,
`Expected: "${OperatingSystem[testCase.expectedOs]}"\n` +
`Actual: "${OperatingSystem[sut.os]}"\n` +
`Platform: "${testCase.processPlatform}"`);
it(testCase.processPlatform, () => {
// arrange
const process = {
platform: testCase.processPlatform,
};
// act
const sut = new SystemUnderTest({ navigator, process });
// assert
expect(sut.os).to.equal(testCase.expectedOs,
`Expected: "${OperatingSystem[testCase.expectedOs]}"\n` +
`Actual: "${OperatingSystem[sut.os]}"\n` +
`Platform: "${testCase.processPlatform}"`);
});
}
});
});