mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-17 21:50:56 +08:00
149b389508
* Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
140 lines
5.2 KiB
TypeScript
140 lines
5.2 KiB
TypeScript
import {
|
|
SearchQueryAST,
|
|
SearchQueryParser,
|
|
} from 'mailspring-exports';
|
|
|
|
const {
|
|
SearchQueryToken,
|
|
OrQueryExpression,
|
|
AndQueryExpression,
|
|
FromQueryExpression,
|
|
ToQueryExpression,
|
|
SubjectQueryExpression,
|
|
GenericQueryExpression,
|
|
TextQueryExpression,
|
|
UnreadStatusQueryExpression,
|
|
StarredStatusQueryExpression,
|
|
InQueryExpression,
|
|
HasAttachmentQueryExpression,
|
|
} = SearchQueryAST;
|
|
|
|
const token = (text) => { return new SearchQueryToken(text); }
|
|
const and = (e1, e2) => { return new AndQueryExpression(e1, e2); }
|
|
const or = (e1, e2) => { return new OrQueryExpression(e1, e2); }
|
|
const from = (text) => { return new FromQueryExpression(text); }
|
|
const to = (text) => { return new ToQueryExpression(text); }
|
|
const subject = (text) => { return new SubjectQueryExpression(text); }
|
|
const generic = (text) => { return new GenericQueryExpression(text); }
|
|
const in_ = (text) => { return new InQueryExpression(text); }
|
|
const text = (tok) => { return new TextQueryExpression(tok); }
|
|
const unread = (status) => { return new UnreadStatusQueryExpression(status); }
|
|
const starred = (status) => { return new StarredStatusQueryExpression(status); }
|
|
const has = () => { return new HasAttachmentQueryExpression(); }
|
|
|
|
|
|
describe('SearchQueryParser.parse', () => {
|
|
it('correctly parses simple queries', () => {
|
|
expect(SearchQueryParser.parse('blah').equals(
|
|
generic(text(token('blah')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('"foo bar"').equals(
|
|
generic(text(token('foo bar')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('to:blah').equals(
|
|
to(text(token('blah')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('from:blah').equals(
|
|
from(text(token('blah')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('subject:blah').equals(
|
|
subject(text(token('blah')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('to:mhahnenb@gmail.com').equals(
|
|
to(text(token('mhahnenb@gmail.com')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('to:"mhahnenb@gmail.com"').equals(
|
|
to(text(token('mhahnenb@gmail.com')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('to:"Mark mhahnenb@gmail.com"').equals(
|
|
to(text(token('Mark mhahnenb@gmail.com')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('is:unread').equals(
|
|
unread(true)
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('is:read').equals(
|
|
unread(false)
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('is:starred').equals(
|
|
starred(true)
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('is:unstarred').equals(
|
|
starred(false)
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('in:foo').equals(
|
|
in_(text(token('foo')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('has:attachment').equals(has())).toBe(true)
|
|
});
|
|
|
|
it('correctly parses reserved words as normal text in certain places', () => {
|
|
expect(SearchQueryParser.parse('to:blah').equals(
|
|
to(text(token('blah')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('to:to').equals(
|
|
to(text(token('to')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('to:subject').equals(
|
|
to(text(token('subject')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('to:from').equals(
|
|
to(text(token('from')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('to:unread').equals(
|
|
to(text(token('unread')))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('to:starred').equals(
|
|
to(text(token('starred')))
|
|
)).toBe(true)
|
|
});
|
|
|
|
it('correctly parses compound queries', () => {
|
|
expect(SearchQueryParser.parse('foo bar').equals(
|
|
and(generic(text(token('foo'))), generic(text(token('bar'))))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('foo AND bar').equals(
|
|
and(generic(text(token('foo'))), generic(text(token('bar'))))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('foo OR bar').equals(
|
|
or(generic(text(token('foo'))), generic(text(token('bar'))))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('to:foo OR bar').equals(
|
|
or(to(text(token('foo'))), generic(text(token('bar'))))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('foo OR to:bar').equals(
|
|
or(generic(text(token('foo'))), to(text(token('bar'))))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('foo bar baz').equals(
|
|
and(generic(text(token('foo'))),
|
|
and(generic(text(token('bar'))), generic(text(token('baz')))))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('foo AND bar AND baz').equals(
|
|
and(generic(text(token('foo'))),
|
|
and(generic(text(token('bar'))), generic(text(token('baz')))))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('foo OR bar AND baz').equals(
|
|
and(
|
|
or(generic(text(token('foo'))), generic(text(token('bar')))),
|
|
generic(text(token('baz'))))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('foo OR bar OR baz').equals(
|
|
or(generic(text(token('foo'))),
|
|
or(generic(text(token('bar'))), generic(text(token('baz')))))
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('foo is:unread').equals(
|
|
and(generic(text(token('foo'))), unread(true)),
|
|
)).toBe(true)
|
|
expect(SearchQueryParser.parse('is:unread foo').equals(
|
|
and(unread(true), generic(text(token('foo'))))
|
|
)).toBe(true)
|
|
});
|
|
});
|