Mailspring/app/spec/models/model-with-metadata-spec.es6
Ben Gotow 1a3cca8d0a
Totally overhauled composer based on Slate (#524)
* Remove the composer contenteditable, replace with basic <textarea>

* Beginning broader cleanup of draft session

* DraftJS composer with color, style support

* Serialization/unserialization of basic styles, toolbar working

* WIP

* Switch to draft-js-plugins approach, need to revisit HTML

* Move HTML conversion functionality into plugins

* Add spellcheck context menu to editor

* Initial work on quoted text

* Further work on quoted text

* BLOCK approach

* Entity approach - better, does not bump out to top level

* Hiding and showing quoted text via CSS

* Get rid of ability to inject another subject line component

* Clean up specs, DraftFactory to ES6

* Remove old initial focus hack

* Fix focusing, initial text selection

* Remove participant “collapsing” support, it can be confusing

* Correctly terminate links on carriage returns

* Initial signature support, allow removal of uneditable blocks

* Sync body string with body editorstate

* Simplify draft editor session, finish signatures

* Templates

* Minor fixes

* Simplify link/open tracking, ensure it works

* Reorg composer, rework template editor

* Omg the slowness is all the stupid emoji button

* Polish and small fixes

* Performance improvements, new templates UI

* Don’t assume nodes are elements

* Fix for sending drafts twice due to back-to-back saves

* Fix order of operations on app quit to save drafts reliably

* Improve DraftJS-Convert whitespace handling

* Use contentID throughout attachment lifecycle

* Try to fix images

* Switch to Slate instead of DraftJS… much better

* Fix newline handling

* Bug fixes

* Cleanup

* Finish templates plugin

* Clean up text editing / support for Gmail email styles

* Support for color + size on the same node, clean trailing whitespace

* Restore emoji typeahead / emoji picker

* Fix scrolling in template editor

* Fix specs

* Fix newlines

* Re-implement spellcheck to be faster

* Make spellcheck decorator changes invisible to the undo/redo stack

* Remove comment

* Polish themplates panel

* Fix #521
2018-01-11 15:55:56 -08:00

58 lines
2.3 KiB
JavaScript

import ModelWithMetadata from '../../src/flux/models/model-with-metadata';
class TestModel extends ModelWithMetadata {}
describe('ModelWithMetadata', function modelWithMetadata() {
it('should initialize pluginMetadata to an empty array', () => {
const model = new TestModel();
expect(model.pluginMetadata).toEqual([]);
});
describe('metadataForPluginId', () => {
beforeEach(() => {
this.model = new TestModel();
this.model.directlyAttachMetadata('plugin-id-a', { a: true });
this.model.directlyAttachMetadata('plugin-id-b', { b: false });
});
it('returns the metadata value for the provided pluginId', () => {
expect(this.model.metadataForPluginId('plugin-id-b')).toEqual({ b: false });
});
it('returns null if no value is found', () => {
expect(this.model.metadataForPluginId('plugin-id-c')).toEqual(null);
});
});
describe('metadataObjectForPluginId', () => {
it('returns the metadata object for the provided pluginId', () => {
const model = new TestModel();
model.directlyAttachMetadata('plugin-id-a', { a: true });
model.directlyAttachMetadata('plugin-id-b', { b: false });
expect(model.metadataObjectForPluginId('plugin-id-a')).toEqual(model.pluginMetadata[0]);
expect(model.metadataObjectForPluginId('plugin-id-b')).toEqual(model.pluginMetadata[1]);
expect(model.metadataObjectForPluginId('plugin-id-c')).toEqual(undefined);
});
});
describe('directlyAttachMetadata', () => {
it('creates or updates the appropriate metadata object', () => {
const model = new TestModel();
expect(model.pluginMetadata.length).toEqual(0);
// create new metadata object with correct value
model.directlyAttachMetadata('plugin-id-a', { a: true });
let obj = model.metadataObjectForPluginId('plugin-id-a');
expect(model.pluginMetadata.length).toEqual(1);
expect(obj.pluginId).toBe('plugin-id-a');
expect(obj.id).toBe('plugin-id-a');
expect(obj.version).toBe(1);
expect(obj.value.a).toBe(true);
// update existing metadata object
model.directlyAttachMetadata('plugin-id-a', { a: false });
obj = model.metadataObjectForPluginId('plugin-id-a');
expect(obj.version).toBe(2);
expect(obj.value.a).toBe(false);
});
});
});