mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 07:46:06 +08:00
Fix feature usage specs
This commit is contained in:
parent
7d59c67234
commit
1013578f60
|
@ -4,9 +4,9 @@ import IdentityStore from '../../src/flux/stores/identity-store';
|
||||||
|
|
||||||
describe('FeatureUsageStore', function featureUsageStoreSpec() {
|
describe('FeatureUsageStore', function featureUsageStoreSpec() {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
this.oldIdent = IdentityStore._identity;
|
this.fakeIdentity = {
|
||||||
IdentityStore._identity = { id: 'foo' };
|
id: 'foo',
|
||||||
IdentityStore._identity.featureUsage = {
|
featureUsage: {
|
||||||
'is-usable': {
|
'is-usable': {
|
||||||
quota: 10,
|
quota: 10,
|
||||||
period: 'monthly',
|
period: 'monthly',
|
||||||
|
@ -19,11 +19,12 @@ describe('FeatureUsageStore', function featureUsageStoreSpec() {
|
||||||
usedInPeriod: 10,
|
usedInPeriod: 10,
|
||||||
featureLimitName: 'Unusable Group A',
|
featureLimitName: 'Unusable Group A',
|
||||||
},
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
spyOn(IdentityStore, 'identity').andReturn(this.fakeIdentity);
|
||||||
|
spyOn(IdentityStore, 'saveIdentity').andCallFake(async ident => {
|
||||||
|
this.fakeIdentity = ident;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
IdentityStore._identity = this.oldIdent;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('isUsable', () => {
|
describe('isUsable', () => {
|
||||||
|
@ -42,12 +43,9 @@ describe('FeatureUsageStore', function featureUsageStoreSpec() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('_markFeatureUsed', () => {
|
describe('markUsed', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(Actions, 'queueTask');
|
spyOn(Actions, 'queueTask');
|
||||||
spyOn(IdentityStore, 'saveIdentity').andCallFake(ident => {
|
|
||||||
IdentityStore._identity = ident;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -55,28 +53,28 @@ describe('FeatureUsageStore', function featureUsageStoreSpec() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('immediately increments the identity counter', () => {
|
it('immediately increments the identity counter', () => {
|
||||||
const before = IdentityStore._identity.featureUsage['is-usable'].usedInPeriod;
|
const before = this.fakeIdentity.featureUsage['is-usable'].usedInPeriod;
|
||||||
FeatureUsageStore._markFeatureUsed('is-usable');
|
FeatureUsageStore.markUsed('is-usable');
|
||||||
const after = IdentityStore._identity.featureUsage['is-usable'].usedInPeriod;
|
const after = this.fakeIdentity.featureUsage['is-usable'].usedInPeriod;
|
||||||
expect(after).toEqual(before + 1);
|
expect(after).toEqual(before + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('queues a task to sync the optimistic changes to the server', () => {
|
it('queues a task to sync the optimistic changes to the server', () => {
|
||||||
FeatureUsageStore._markFeatureUsed('is-usable');
|
FeatureUsageStore.markUsed('is-usable');
|
||||||
expect(Actions.queueTask).toHaveBeenCalled();
|
expect(Actions.queueTask).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('use feature', () => {
|
describe('markUsedOrUpgrade', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(FeatureUsageStore, '_markFeatureUsed').andReturn(Promise.resolve());
|
spyOn(FeatureUsageStore, 'markUsed').andReturn(Promise.resolve());
|
||||||
spyOn(Actions, 'openModal');
|
spyOn(Actions, 'openModal');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("marks the feature used if it's usable", async () => {
|
it("marks the feature used if it's usable", async () => {
|
||||||
await FeatureUsageStore.markUsedOrUpgrade('is-usable');
|
await FeatureUsageStore.markUsedOrUpgrade('is-usable');
|
||||||
expect(FeatureUsageStore._markFeatureUsed).toHaveBeenCalled();
|
expect(FeatureUsageStore.markUsed).toHaveBeenCalled();
|
||||||
expect(FeatureUsageStore._markFeatureUsed.callCount).toBe(1);
|
expect(FeatureUsageStore.markUsed.callCount).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('showing modal', () => {
|
describe('showing modal', () => {
|
||||||
|
@ -90,7 +88,7 @@ describe('FeatureUsageStore', function featureUsageStoreSpec() {
|
||||||
|
|
||||||
it('resolves the modal if you upgrade', async () => {
|
it('resolves the modal if you upgrade', async () => {
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
IdentityStore._identity.featureUsage['not-usable'].quota = 10000;
|
this.fakeIdentity.featureUsage['not-usable'].quota = 10000;
|
||||||
FeatureUsageStore._onModalClose();
|
FeatureUsageStore._onModalClose();
|
||||||
});
|
});
|
||||||
await FeatureUsageStore.markUsedOrUpgrade('not-usable', this.lexicon);
|
await FeatureUsageStore.markUsedOrUpgrade('not-usable', this.lexicon);
|
||||||
|
@ -100,7 +98,7 @@ describe('FeatureUsageStore', function featureUsageStoreSpec() {
|
||||||
|
|
||||||
it('pops open a modal with the correct text', async () => {
|
it('pops open a modal with the correct text', async () => {
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
IdentityStore._identity.featureUsage['not-usable'].quota = 10000;
|
this.fakeIdentity.featureUsage['not-usable'].quota = 10000;
|
||||||
FeatureUsageStore._onModalClose();
|
FeatureUsageStore._onModalClose();
|
||||||
});
|
});
|
||||||
await FeatureUsageStore.markUsedOrUpgrade('not-usable', this.lexicon);
|
await FeatureUsageStore.markUsedOrUpgrade('not-usable', this.lexicon);
|
||||||
|
|
|
@ -107,8 +107,6 @@ class FeatureUsageStore extends MailspringStore {
|
||||||
|
|
||||||
markUsed(feature) {
|
markUsed(feature) {
|
||||||
const next = JSON.parse(JSON.stringify(IdentityStore.identity()));
|
const next = JSON.parse(JSON.stringify(IdentityStore.identity()));
|
||||||
console.log('Next:');
|
|
||||||
console.log(JSON.stringify(next));
|
|
||||||
|
|
||||||
if (next.featureUsage[feature]) {
|
if (next.featureUsage[feature]) {
|
||||||
next.featureUsage[feature].usedInPeriod += 1;
|
next.featureUsage[feature].usedInPeriod += 1;
|
||||||
|
|
Loading…
Reference in a new issue