|
| 1 | +/* eslint no-unused-expressions: 0 */ |
| 2 | + |
| 3 | +const expect = require('chai').expect; |
| 4 | + |
| 5 | +// const debug = require('debug')('mongodb-compass:test:query-changed-store'); |
| 6 | + |
| 7 | +let OpenInsertDocumentDialogStore = require('../../src/internal-packages/crud/lib/store/open-insert-document-dialog-store'); |
| 8 | + |
| 9 | +describe('OpenInsertDocumentDialogStore', () => { |
| 10 | + let unsubscribe = () => {}; |
| 11 | + |
| 12 | + afterEach(() => { |
| 13 | + unsubscribe(); |
| 14 | + unsubscribe = () => {}; |
| 15 | + }); |
| 16 | + |
| 17 | + context('when inserting a new document', () => { |
| 18 | + it('keeps the document as is without modifications', (done) => { |
| 19 | + const doc = { |
| 20 | + _id: 'foo', |
| 21 | + field: 'bar' |
| 22 | + }; |
| 23 | + unsubscribe = OpenInsertDocumentDialogStore.listen((hadronDoc) => { |
| 24 | + expect(hadronDoc.generateObject()).to.be.deep.equal(doc); |
| 25 | + done(); |
| 26 | + }); |
| 27 | + OpenInsertDocumentDialogStore.openInsertDocumentDialog(doc, false); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + context('when cloning a document', () => { |
| 32 | + it('removes the _id element when it is at the first position', (done) => { |
| 33 | + const doc = { |
| 34 | + _id: 'foo', |
| 35 | + field: 'bar' |
| 36 | + }; |
| 37 | + unsubscribe = OpenInsertDocumentDialogStore.listen((hadronDoc) => { |
| 38 | + expect(hadronDoc.generateObject()).to.be.deep.equal({field: 'bar'}); |
| 39 | + done(); |
| 40 | + }); |
| 41 | + OpenInsertDocumentDialogStore.openInsertDocumentDialog(doc, true); |
| 42 | + }); |
| 43 | + it('removes the _id element when it is not at the first position', (done) => { |
| 44 | + const doc = { |
| 45 | + _a_surprise_: 'indeed', |
| 46 | + _id: 'foo', |
| 47 | + field: 'bar' |
| 48 | + }; |
| 49 | + unsubscribe = OpenInsertDocumentDialogStore.listen((hadronDoc) => { |
| 50 | + expect(hadronDoc.generateObject()).to.be.deep.equal({ |
| 51 | + _a_surprise_: 'indeed', |
| 52 | + field: 'bar' |
| 53 | + }); |
| 54 | + done(); |
| 55 | + }); |
| 56 | + OpenInsertDocumentDialogStore.openInsertDocumentDialog(doc, true); |
| 57 | + }); |
| 58 | + }); |
| 59 | +}); |
0 commit comments