{{ title }}
- Enforce privacy & security on Windows and macOS
+ Enforce privacy & security on Windows and macOS
diff --git a/src/presentation/TheSearchBar.vue b/src/presentation/TheSearchBar.vue
index e6457517..efc5971e 100644
--- a/src/presentation/TheSearchBar.vue
+++ b/src/presentation/TheSearchBar.vue
@@ -36,9 +36,6 @@ export default class TheSearchBar extends StatefulVue {
}
}
- protected initialize(): void {
- return;
- }
protected handleCollectionState(newState: ICategoryCollectionState, oldState: ICategoryCollectionState | undefined) {
const totalScripts = newState.collection.totalScripts;
this.searchPlaceHolder = `Search in ${totalScripts} scripts`;
diff --git a/tests/unit/application/ApplicationFactory.spec.ts b/tests/unit/application/ApplicationFactory.spec.ts
new file mode 100644
index 00000000..71ed4215
--- /dev/null
+++ b/tests/unit/application/ApplicationFactory.spec.ts
@@ -0,0 +1,60 @@
+import 'mocha';
+import { expect } from 'chai';
+import { ApplicationFactory, ApplicationGetter } from '@/application/ApplicationFactory';
+import { ApplicationStub } from '../stubs/ApplicationStub';
+
+describe('ApplicationFactory', () => {
+ describe('ctor', () => {
+ it('throws if getter is undefined', () => {
+ // arrange
+ const expectedError = 'undefined getter';
+ const getter = undefined;
+ // act
+ const act = () => new SystemUnderTest(getter);
+ // assert
+ expect(act).to.throw(expectedError);
+ });
+ });
+ describe('getAppAsync', () => {
+ it('returns result from the getter', async () => {
+ // arrange
+ const expected = new ApplicationStub();
+ const getter: ApplicationGetter = () => expected;
+ const sut = new SystemUnderTest(getter);
+ // act
+ const actual = await Promise.all( [
+ sut.getAppAsync(),
+ sut.getAppAsync(),
+ sut.getAppAsync(),
+ sut.getAppAsync(),
+ ]);
+ // assert
+ expect(actual.every((value) => value === expected));
+ });
+ it('only executes getter once', async () => {
+ // arrange
+ let totalExecution = 0;
+ const expected = new ApplicationStub();
+ const getter: ApplicationGetter = () => {
+ totalExecution++;
+ return expected;
+ };
+ const sut = new SystemUnderTest(getter);
+ // act
+ await Promise.all( [
+ sut.getAppAsync(),
+ sut.getAppAsync(),
+ sut.getAppAsync(),
+ sut.getAppAsync(),
+ ]);
+ // assert
+ expect(totalExecution).to.equal(1);
+ });
+ });
+});
+
+class SystemUnderTest extends ApplicationFactory {
+ public constructor(costlyGetter: ApplicationGetter) {
+ super(costlyGetter);
+ }
+}
diff --git a/tests/unit/application/Context/ApplicationContextFactory.spec.ts b/tests/unit/application/Context/ApplicationContextFactory.spec.ts
new file mode 100644
index 00000000..0c5cd329
--- /dev/null
+++ b/tests/unit/application/Context/ApplicationContextFactory.spec.ts
@@ -0,0 +1,83 @@
+import 'mocha';
+import { expect } from 'chai';
+import { OperatingSystem } from '@/domain/OperatingSystem';
+import { ICategoryCollection } from '@/domain/ICategoryCollection';
+import { CategoryCollectionStub } from '../../stubs/CategoryCollectionStub';
+import { EnvironmentStub } from '../../stubs/EnvironmentStub';
+import { ApplicationStub } from '../../stubs/ApplicationStub';
+import { buildContextAsync } from '@/application/Context/ApplicationContextFactory';
+import { IApplicationFactory } from '@/application/IApplicationFactory';
+import { IApplication } from '@/domain/IApplication';
+
+describe('ApplicationContextFactory', () => {
+ describe('buildContextAsync', () => {
+ describe('factory', () => {
+ it('sets application from factory', async () => {
+ // arrange
+ const expected = new ApplicationStub().withCollection(
+ new CategoryCollectionStub().withOs(OperatingSystem.macOS));
+ const factoryMock = mockFactoryWithApp(expected);
+ // act
+ const context = await buildContextAsync(factoryMock);
+ // assert
+ expect(expected).to.equal(context.app);
+ });
+ });
+ describe('environment', () => {
+ describe('sets initial OS as expected', () => {
+ it('returns currentOs if it is supported', async () => {
+ // arrange
+ const expected = OperatingSystem.Windows;
+ const environment = new EnvironmentStub().withOs(expected);
+ const collection = new CategoryCollectionStub().withOs(expected);
+ const factoryMock = mockFactoryWithCollection(collection);
+ // act
+ const context = await buildContextAsync(factoryMock, environment);
+ // assert
+ const actual = context.state.os;
+ expect(expected).to.equal(actual);
+ });
+ it('fallbacks to other os if OS in environment is not supported', async () => {
+ // arrange
+ const expected = OperatingSystem.Windows;
+ const currentOs = OperatingSystem.macOS;
+ const environment = new EnvironmentStub().withOs(currentOs);
+ const collection = new CategoryCollectionStub().withOs(expected);
+ const factoryMock = mockFactoryWithCollection(collection);
+ // act
+ const context = await buildContextAsync(factoryMock, environment);
+ // assert
+ const actual = context.state.os;
+ expect(expected).to.equal(actual);
+ });
+ it('fallbacks to most supported os if current os is not supported', async () => {
+ // arrange
+ const expectedOs = OperatingSystem.Android;
+ const allCollections = [
+ new CategoryCollectionStub().withOs(OperatingSystem.Linux).withTotalScripts(3),
+ new CategoryCollectionStub().withOs(expectedOs).withTotalScripts(5),
+ new CategoryCollectionStub().withOs(OperatingSystem.Windows).withTotalScripts(4),
+ ];
+ const environment = new EnvironmentStub().withOs(OperatingSystem.macOS);
+ const app = new ApplicationStub().withCollections(...allCollections);
+ const factoryMock = mockFactoryWithApp(app);
+ // act
+ const context = await buildContextAsync(factoryMock, environment);
+ // assert
+ const actual = context.state.os;
+ expect(expectedOs).to.equal(actual, `Expected: ${OperatingSystem[expectedOs]}, actual: ${OperatingSystem[actual]}`);
+ });
+ });
+ });
+ });
+});
+
+function mockFactoryWithCollection(result: ICategoryCollection): IApplicationFactory {
+ return mockFactoryWithApp(new ApplicationStub().withCollection(result));
+}
+
+function mockFactoryWithApp(app: IApplication): IApplicationFactory {
+ return {
+ getAppAsync: () => Promise.resolve(app),
+ };
+}
diff --git a/tests/unit/application/Context/ApplicationContextProvider.spec.ts b/tests/unit/application/Context/ApplicationContextProvider.spec.ts
deleted file mode 100644
index 1b9fddfa..00000000
--- a/tests/unit/application/Context/ApplicationContextProvider.spec.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-import 'mocha';
-import { expect } from 'chai';
-import { OperatingSystem } from '@/domain/OperatingSystem';
-import { ICategoryCollection } from '@/domain/ICategoryCollection';
-import { ApplicationParserType, buildContext } from '@/application/Context/ApplicationContextProvider';
-import { CategoryCollectionStub } from '../../stubs/CategoryCollectionStub';
-import { EnvironmentStub } from '../../stubs/EnvironmentStub';
-import { ApplicationStub } from '../../stubs/ApplicationStub';
-
-describe('ApplicationContextProvider', () => {
- describe('buildContext', () => {
- it('sets application from parser', () => {
- // arrange
- const expected = new ApplicationStub().withCollection(
- new CategoryCollectionStub().withOs(OperatingSystem.macOS));
- const parserMock: ApplicationParserType = () => expected;
- // act
- const context = buildContext(parserMock);
- // assert
- expect(expected).to.equal(context.app);
- });
- describe('sets initial OS as expected', () => {
- it('returns currentOs if it is supported', () => {
- // arrange
- const expected = OperatingSystem.Windows;
- const environment = new EnvironmentStub().withOs(expected);
- const parser = mockParser(new CategoryCollectionStub().withOs(expected));
- // act
- const context = buildContext(parser, environment);
- // assert
- const actual = context.state.os;
- expect(expected).to.equal(actual);
- });
- it('fallbacks to other os if OS in environment is not supported', () => {
- // arrange
- const expected = OperatingSystem.Windows;
- const currentOs = OperatingSystem.macOS;
- const environment = new EnvironmentStub().withOs(currentOs);
- const parser = mockParser(new CategoryCollectionStub().withOs(expected));
- // act
- const context = buildContext(parser, environment);
- // assert
- const actual = context.state.os;
- expect(expected).to.equal(actual);
- });
- it('fallbacks to most supported os if current os is not supported', () => {
- // arrange
- const expectedOs = OperatingSystem.Android;
- const allCollections = [
- new CategoryCollectionStub().withOs(OperatingSystem.Linux).withTotalScripts(3),
- new CategoryCollectionStub().withOs(expectedOs).withTotalScripts(5),
- new CategoryCollectionStub().withOs(OperatingSystem.Windows).withTotalScripts(4),
- ];
- const environment = new EnvironmentStub().withOs(OperatingSystem.macOS);
- const app = new ApplicationStub().withCollections(...allCollections);
- const parser: ApplicationParserType = () => app;
- // act
- const context = buildContext(parser, environment);
- // assert
- const actual = context.state.os;
- expect(expectedOs).to.equal(actual, `Expected: ${OperatingSystem[expectedOs]}, actual: ${OperatingSystem[actual]}`);
- });
- });
- });
-});
-
-function mockParser(result: ICategoryCollection): ApplicationParserType {
- return () => new ApplicationStub().withCollection(result);
-}