Skip to content

Commit

Permalink
chore(NativeMocks): Deprecate static instance method
Browse files Browse the repository at this point in the history
  • Loading branch information
stonelasley committed Jul 7, 2018
1 parent bf67932 commit e8e9a87
Show file tree
Hide file tree
Showing 20 changed files with 1,058 additions and 169 deletions.
2 changes: 1 addition & 1 deletion src/native/file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('FileMock', () => {
let file;

beforeEach(() => {
file = FileMock.instance();
file = new FileMock();
});

it('should initialise', () => {
Expand Down
91 changes: 50 additions & 41 deletions src/native/file.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
export class FileMock {
public applicationDirectory: string = 'a-directory';
public applicationStorageDirectory: string = 'a-directory';
public dataDirectory: string = 'a-directory';
public cacheDirectory: string = 'a-directory';
public externalApplicationStorageDirectory: string = 'a-directory';
public externalDataDirectory: string = 'a-directory';
public externalCacheDirectory: string = 'a-directory';
public externalRootDirectory: string = 'a-directory';
public tempDirectory: string = 'a-directory';
public syncedDataDirectory: string = 'a-directory';
public documentsDirectory: string = 'a-directory';
public sharedDirectory: string = 'a-directory';
public cordovaFileError: any;
import { BaseMock } from '../base.mock';

public static instance(): any {
let instance = jasmine.createSpyObj('File', [

const METHODS = [
'getFreeDiskSpace',
'checkDir',
'createDir',
Expand All @@ -38,32 +25,54 @@ export class FileMock {
'resolveDirectoryUrl',
'getDirectory',
'getFile'
]);
];
export class FileMock extends BaseMock {
applicationDirectory = 'a-directory';
applicationStorageDirectory = 'a-directory';
dataDirectory = 'a-directory';
cacheDirectory = 'a-directory';
externalApplicationStorageDirectory = 'a-directory';
externalDataDirectory = 'a-directory';
externalCacheDirectory = 'a-directory';
externalRootDirectory = 'a-directory';
tempDirectory = 'a-directory';
syncedDataDirectory = 'a-directory';
documentsDirectory = 'a-directory';
sharedDirectory = 'a-directory';
cordovaFileError: any;

constructor() {
super('File', METHODS);

this.spyObj.getFreeDiskSpace.and.returnValue(Promise.resolve(64));
this.spyObj.checkDir.and.returnValue(Promise.resolve(true));
this.spyObj.createDir.and.returnValue(Promise.resolve());
this.spyObj.removeDir.and.returnValue(Promise.resolve());
this.spyObj.moveDir.and.returnValue(Promise.resolve());
this.spyObj.copyDir.and.returnValue(Promise.resolve());
this.spyObj.listDir.and.returnValue(Promise.resolve());
this.spyObj.removeRecursively.and.returnValue(Promise.resolve());
this.spyObj.checkFile.and.returnValue(Promise.resolve(true));
this.spyObj.createFile.and.returnValue(Promise.resolve());
this.spyObj.removeFile.and.returnValue(Promise.resolve());
this.spyObj.writeFile.and.returnValue(Promise.resolve());
this.spyObj.writeExistingFile.and.returnValue(Promise.resolve());
this.spyObj.readAsText.and.returnValue(Promise.resolve('a string'));
this.spyObj.readAsDataURL.and.returnValue(Promise.resolve('data:,some%20data'));
this.spyObj.readAsBinaryString.and.returnValue(Promise.resolve('101010'));
this.spyObj.readAsArrayBuffer.and.returnValue(Promise.resolve(new ArrayBuffer(1)));
this.spyObj.moveFile.and.returnValue(Promise.resolve());
this.spyObj.copyFile.and.returnValue(Promise.resolve());
this.spyObj.resolveLocalFilesystemUrl.and.returnValue(Promise.resolve());
this.spyObj.resolveDirectoryUrl.and.returnValue(Promise.resolve());
this.spyObj.getDirectory.and.returnValue(Promise.resolve());
this.spyObj.getFile.and.returnValue(Promise.resolve());

}

instance.getFreeDiskSpace.and.returnValue(Promise.resolve(64));
instance.checkDir.and.returnValue(Promise.resolve(true));
instance.createDir.and.returnValue(Promise.resolve());
instance.removeDir.and.returnValue(Promise.resolve());
instance.moveDir.and.returnValue(Promise.resolve());
instance.copyDir.and.returnValue(Promise.resolve());
instance.listDir.and.returnValue(Promise.resolve());
instance.removeRecursively.and.returnValue(Promise.resolve());
instance.checkFile.and.returnValue(Promise.resolve(true));
instance.createFile.and.returnValue(Promise.resolve());
instance.removeFile.and.returnValue(Promise.resolve());
instance.writeFile.and.returnValue(Promise.resolve());
instance.writeExistingFile.and.returnValue(Promise.resolve());
instance.readAsText.and.returnValue(Promise.resolve('a string'));
instance.readAsDataURL.and.returnValue(Promise.resolve('data:,some%20data'));
instance.readAsBinaryString.and.returnValue(Promise.resolve('101010'));
instance.readAsArrayBuffer.and.returnValue(Promise.resolve(new ArrayBuffer(1)));
instance.moveFile.and.returnValue(Promise.resolve());
instance.copyFile.and.returnValue(Promise.resolve());
instance.resolveLocalFilesystemUrl.and.returnValue(Promise.resolve());
instance.resolveDirectoryUrl.and.returnValue(Promise.resolve());
instance.getDirectory.and.returnValue(Promise.resolve());
instance.getFile.and.returnValue(Promise.resolve());

return instance;

public static instance(): any {
return new FileMock();
}
}
195 changes: 195 additions & 0 deletions src/native/google-analytics.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import { GoogleAnalyticsMock } from './google-analytics';

describe('GoogleAnalytics', () => {
let classUnderTest: any;

beforeEach(() => {
classUnderTest = new GoogleAnalyticsMock();
});

it('should be defined', () => {
expect(classUnderTest).toBeDefined();
});

describe('startTrackerWithId', () => {
it('should be defined', () => {
expect(classUnderTest.startTrackerWithId).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.startTrackerWithId().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('setAllowIDFACollection', () => {
it('should be defined', () => {
expect(classUnderTest.setAllowIDFACollection).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.setAllowIDFACollection().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('setUserId', () => {
it('should be defined', () => {
expect(classUnderTest.setUserId).toBeDefined();
});

it('should should return empty Promise', done => {
classUnderTest.setUserId().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('setAnonymizeIp', () => {
it('should be defined', () => {
expect(classUnderTest.setAnonymizeIp).toBeDefined();
});

it('should should return empty Promise', done => {
classUnderTest.setAnonymizeIp().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('setAppVersion', () => {
it('should be defined', () => {
expect(classUnderTest.setAppVersion).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.setAppVersion().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('setOptOut', () => {
it('should be defined', () => {
expect(classUnderTest.setOptOut).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.setOptOut().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('debugMode', () => {
it('should be defined', () => {
expect(classUnderTest.debugMode).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.debugMode().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('trackMetric', () => {
it('should be defined', () => {
expect(classUnderTest.trackMetric).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.trackMetric().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('trackView', () => {
it('should be defined', () => {
expect(classUnderTest.trackView).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.trackView().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('trackException', () => {
it('should be defined', () => {
expect(classUnderTest.trackException).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.trackException().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('trackTiming', () => {
it('should be defined', () => {
expect(classUnderTest.trackTiming).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.trackTiming().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('addTransaction', () => {
it('should be defined', () => {
expect(classUnderTest.addTransaction).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.addTransaction().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('addTransactionItem', () => {
it('should be defined', () => {
expect(classUnderTest.addTransactionItem).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.addTransactionItem().then(result => {
expect(result).toBeUndefined();
done();
});
});
});

describe('enableUncaughtExceptionReporting', () => {
it('should be defined', () => {
expect(classUnderTest.enableUncaughtExceptionReporting).toBeDefined();
});

it('should return empty Promise', done => {
classUnderTest.enableUncaughtExceptionReporting().then(result => {
expect(result).toBeUndefined();
done();
});
});
});
});
81 changes: 44 additions & 37 deletions src/native/google-analytics.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
export class GoogleAnalyticsMock {
import deprecated from 'deprecated-decorator';
import { BaseMock } from '../base.mock';

public static instance(): any {
let instance = jasmine.createSpyObj('GoogleAnalytics', [
'startTrackerWithId',
'setAllowIDFACollection',
'setUserId',
'setAnonymizeIp',
'setAppVersion',
'setOptOut',
'debugMode',
'trackMetric',
'trackView',
'addCustomDimension',
'trackEvent',
'trackException',
'trackTiming',
'addTransaction',
'addTransactionItem',
'enableUncaughtExceptionReporting'
]);
instance.startTrackerWithId.and.returnValue(Promise.resolve());
instance.setAllowIDFACollection.and.returnValue(Promise.resolve());
instance.setUserId.and.returnValue(Promise.resolve());
instance.setAnonymizeIp.and.returnValue(Promise.resolve());
instance.setAppVersion.and.returnValue(Promise.resolve());
instance.setOptOut.and.returnValue(Promise.resolve());
instance.debugMode.and.returnValue(Promise.resolve());
instance.trackMetric.and.returnValue(Promise.resolve());
instance.trackView.and.returnValue(Promise.resolve());
instance.addCustomDimension.and.returnValue(Promise.resolve());
instance.trackEvent.and.returnValue(Promise.resolve());
instance.trackException.and.returnValue(Promise.resolve());
instance.trackTiming.and.returnValue(Promise.resolve());
instance.addTransaction.and.returnValue(Promise.resolve());
instance.addTransactionItem.and.returnValue(Promise.resolve());
instance.enableUncaughtExceptionReporting.and.returnValue(Promise.resolve());
const METHODS = [
'startTrackerWithId',
'setAllowIDFACollection',
'setUserId',
'setAnonymizeIp',
'setAppVersion',
'setOptOut',
'debugMode',
'trackMetric',
'trackView',
'addCustomDimension',
'trackEvent',
'trackException',
'trackTiming',
'addTransaction',
'addTransactionItem',
'enableUncaughtExceptionReporting'
];

return instance;
export class GoogleAnalyticsMock extends BaseMock {
constructor() {
super('GoogleAnalytics', METHODS);
this.spyObj.startTrackerWithId.and.returnValue(Promise.resolve());
this.spyObj.setAllowIDFACollection.and.returnValue(Promise.resolve());
this.spyObj.setUserId.and.returnValue(Promise.resolve());
this.spyObj.setAnonymizeIp.and.returnValue(Promise.resolve());
this.spyObj.setAppVersion.and.returnValue(Promise.resolve());
this.spyObj.setOptOut.and.returnValue(Promise.resolve());
this.spyObj.debugMode.and.returnValue(Promise.resolve());
this.spyObj.trackMetric.and.returnValue(Promise.resolve());
this.spyObj.trackView.and.returnValue(Promise.resolve());
this.spyObj.addCustomDimension.and.returnValue(Promise.resolve());
this.spyObj.trackEvent.and.returnValue(Promise.resolve());
this.spyObj.trackException.and.returnValue(Promise.resolve());
this.spyObj.trackTiming.and.returnValue(Promise.resolve());
this.spyObj.addTransaction.and.returnValue(Promise.resolve());
this.spyObj.addTransactionItem.and.returnValue(Promise.resolve());
this.spyObj.enableUncaughtExceptionReporting.and.returnValue(Promise.resolve());
}

@deprecated('new GoogleAnalyticsMock()')
static instance(): any {
new GoogleAnalyticsMock();
}
}
Loading

0 comments on commit e8e9a87

Please sign in to comment.