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

@@ -24,9 +24,12 @@ export class Environment implements IEnvironment {
throw new Error('variables is null or empty');
}
this.isDesktop = isDesktop(variables);
this.os = this.isDesktop ?
getDesktopOsType(getProcessPlatform(variables))
: browserOsDetector.detect(getUserAgent(variables));
if (this.isDesktop) {
this.os = getDesktopOsType(getProcessPlatform(variables));
} else {
const userAgent = getUserAgent(variables);
this.os = !userAgent ? undefined : browserOsDetector.detect(userAgent);
}
}
}