mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 13:44:41 +08:00
d1c587a01c
More spec fixes replace process.nextTick with setTimeout(fn, 0) for specs Also added an unspy in the afterEach Temporarily disable specs fix(spec): start fixing specs Summary: This is the WIP fix to our spec runner. Several tests have been completely commented out that will require substantially more work to fix. These have been added to our sprint backlog. Other tests have been fixed to update to new APIs or to deal with genuine bugs that were introduced without our knowing! The most common non-trivial change relates to observing the `NylasAPI` and `NylasAPIRequest`. We used to observe the arguments to `makeRequest`. Unfortunately `NylasAPIRequest.run` is argumentless. Instead you can do: `NylasAPIRequest.prototype.run.mostRecentCall.object.options` to get the `options` passed into the object. the `.object` property grabs the context of the spy when it was last called. Fixing these tests uncovered several concerning issues with our test runner. I spent a while tracking down why our participant-text-field-spec was failling every so often. I chose that spec because it was the first spec to likely fail, thereby requiring looking at the least number of preceding files. I tried binary searching, turning on and off, several files beforehand only to realize that the failure rate was not determined by a particular preceding test, but rather the existing and quantity of preceding tests, AND the number of console.log statements I had. There is some processor-dependent race condition going on that needs further investigation. I also discovered an issue with the file-download-spec. We were getting errors about it accessing a file, which was very suspicious given the code stubs out all fs access. This was caused due to a spec that called an async function outside ot a `waitsForPromise` block or a `waitsFor` block. The test completed, the spies were cleaned up, but the downstream async chain was still running. By the time the async chain finished the runner was already working on the next spec and the spies had been restored (causing the real fs access to run). Juan had an idea to kill the specs once one fails to prevent cascading failures. I'll implement this in the next diff update Test Plan: npm test Reviewers: juan, halla, jackie Differential Revision: https://phab.nylas.com/D3501 Disable other specs Disable more broken specs All specs turned off till passing state Use async-safe versions of spec functions Add async test spec Remove unused package code Remove canary spec
124 lines
4 KiB
JavaScript
124 lines
4 KiB
JavaScript
import {
|
|
Actions,
|
|
Message,
|
|
DraftHelpers,
|
|
DatabaseStore,
|
|
} from 'nylas-exports';
|
|
|
|
import InlineStyleTransformer from '../../src/services/inline-style-transformer'
|
|
import SanitizeTransformer from '../../src/services/sanitize-transformer';
|
|
|
|
|
|
xdescribe('DraftHelpers', function describeBlock() {
|
|
describe('prepareDraftForSyncback', () => {
|
|
beforeEach(() => {
|
|
spyOn(Actions, 'queueTask')
|
|
});
|
|
|
|
it('calls the proper functions', () => {
|
|
const draft = new Message({
|
|
clientId: "local-123",
|
|
threadId: "thread-123",
|
|
uploads: [{inline: true, id: 1}],
|
|
body: "",
|
|
});
|
|
const session = {
|
|
ensureCorrectAccount() { return Promise.resolve() },
|
|
draft() { return draft },
|
|
}
|
|
spyOn(session, 'ensureCorrectAccount')
|
|
spyOn(DraftHelpers, 'applyExtensionTransforms').andCallFake(async (d) => d)
|
|
spyOn(DatabaseStore, 'inTransaction').andCallFake((f) => {
|
|
f({persistModel: m => m})
|
|
});
|
|
spyOn(DraftHelpers, 'removeStaleUploads');
|
|
|
|
waitsForPromise(async () => {
|
|
await DraftHelpers.prepareDraftForSyncback(session);
|
|
expect(session.ensureCorrectAccount).toHaveBeenCalled();
|
|
expect(DraftHelpers.applyExtensionTransforms).toHaveBeenCalled();
|
|
expect(DraftHelpers.removeStaleUploads).toHaveBeenCalled();
|
|
})
|
|
})
|
|
});
|
|
|
|
describe("prepareBodyForQuoting", () => {
|
|
it("should transform inline styles and sanitize unsafe html", () => {
|
|
const input = "test 123";
|
|
spyOn(InlineStyleTransformer, 'run').andCallThrough();
|
|
spyOn(SanitizeTransformer, 'run').andCallThrough();
|
|
DraftHelpers.prepareBodyForQuoting(input);
|
|
expect(InlineStyleTransformer.run).toHaveBeenCalledWith(input);
|
|
advanceClock();
|
|
expect(SanitizeTransformer.run).toHaveBeenCalledWith(input, SanitizeTransformer.Preset.UnsafeOnly);
|
|
});
|
|
});
|
|
|
|
|
|
describe('shouldAppendQuotedText', () => {
|
|
it('returns true if message is reply and has no marker', () => {
|
|
const draft = {
|
|
replyToMessageId: 1,
|
|
body: `<div>hello!</div>`,
|
|
}
|
|
expect(DraftHelpers.shouldAppendQuotedText(draft)).toBe(true)
|
|
})
|
|
|
|
it('returns false if message is reply and has marker', () => {
|
|
const draft = {
|
|
replyToMessageId: 1,
|
|
body: `<div>hello!</div><div id="n1-quoted-text-marker"></div>Quoted Text`,
|
|
}
|
|
expect(DraftHelpers.shouldAppendQuotedText(draft)).toBe(false)
|
|
})
|
|
|
|
it('returns false if message is not reply', () => {
|
|
const draft = {
|
|
body: `<div>hello!</div>`,
|
|
}
|
|
expect(DraftHelpers.shouldAppendQuotedText(draft)).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('removeStaleUploads', () => {
|
|
describe('returns immediately when', () => {
|
|
beforeEach(() => {
|
|
spyOn(DatabaseStore, 'inTransaction').andReturn(Promise.resolve(null));
|
|
})
|
|
|
|
it('has 0 uploads', () => {
|
|
const draft = new Message({uploads: []});
|
|
waitsForPromise(async () => {
|
|
await DraftHelpers.removeStaleUploads(draft)
|
|
expect(DatabaseStore.inTransaction).not.toHaveBeenCalled();
|
|
})
|
|
})
|
|
|
|
it('has an invalid uploads field', () => {
|
|
const draft = new Message({uploads: "uploads"});
|
|
waitsForPromise(async () => {
|
|
await DraftHelpers.removeStaleUploads(draft)
|
|
expect(DatabaseStore.inTransaction).not.toHaveBeenCalled();
|
|
})
|
|
})
|
|
})
|
|
|
|
it('removes the proper uploads', () => {
|
|
const draft = new Message({
|
|
uploads: [
|
|
{inline: true, id: 1},
|
|
{inline: true, id: 2},
|
|
{inline: false, id: 3},
|
|
],
|
|
body: 'aldkfjoe cid:2 adlfkobieejlkd',
|
|
})
|
|
waitsForPromise(async () => {
|
|
const {uploads} = await DraftHelpers.removeStaleUploads(draft)
|
|
expect(uploads.length).toEqual(2);
|
|
expect(uploads.find(u => u.id === 1)).not.toBeDefined();
|
|
expect(uploads.find(u => u.id === 2)).toBeDefined();
|
|
expect(uploads.find(u => u.id === 3)).toBeDefined();
|
|
})
|
|
})
|
|
})
|
|
});
|