From e25c0a0eaf116ef6ff7380cb63e0875dfbc3cfef Mon Sep 17 00:00:00 2001 From: "Alexey Mulyukin (alexprey)" Date: Mon, 25 Jan 2021 18:27:51 +0300 Subject: [PATCH] Add additional unit test around events in Svelte V3 --- .../event.dispatcher.arrayIdentifier.svelte | 12 ++++ .../events/event.dispatcher.identifier.svelte | 5 ++ ...event.dispatcher.importedIdentifier.svelte | 10 +++ .../svelte3/integration/events/events.spec.js | 62 ++++++++++++++++++- .../integration/events/sharedEvents.js | 7 +++ 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 test/svelte3/integration/events/event.dispatcher.arrayIdentifier.svelte create mode 100644 test/svelte3/integration/events/event.dispatcher.importedIdentifier.svelte create mode 100644 test/svelte3/integration/events/sharedEvents.js diff --git a/test/svelte3/integration/events/event.dispatcher.arrayIdentifier.svelte b/test/svelte3/integration/events/event.dispatcher.arrayIdentifier.svelte new file mode 100644 index 0000000..2cac054 --- /dev/null +++ b/test/svelte3/integration/events/event.dispatcher.arrayIdentifier.svelte @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/test/svelte3/integration/events/event.dispatcher.identifier.svelte b/test/svelte3/integration/events/event.dispatcher.identifier.svelte index 73db692..23f2f8c 100644 --- a/test/svelte3/integration/events/event.dispatcher.identifier.svelte +++ b/test/svelte3/integration/events/event.dispatcher.identifier.svelte @@ -7,5 +7,10 @@ NOTIFY: 'notify' } }; + + const SIMPLE_EVENT = 'plain-notify'; + dispatch(EVENT.SIGNAL.NOTIFY); + + dispatch(SIMPLE_EVENT); \ No newline at end of file diff --git a/test/svelte3/integration/events/event.dispatcher.importedIdentifier.svelte b/test/svelte3/integration/events/event.dispatcher.importedIdentifier.svelte new file mode 100644 index 0000000..605e13c --- /dev/null +++ b/test/svelte3/integration/events/event.dispatcher.importedIdentifier.svelte @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/test/svelte3/integration/events/events.spec.js b/test/svelte3/integration/events/events.spec.js index f144290..b6f744f 100644 --- a/test/svelte3/integration/events/events.spec.js +++ b/test/svelte3/integration/events/events.spec.js @@ -324,7 +324,7 @@ describe('SvelteDoc v3 - Events', () => { }); }); - it('Dispatch event from code should be found when using an identifier', (done) => { + it('Dispatch event from code should be found when using an identifier from object', (done) => { parser.parse({ version: 3, filename: path.resolve(__dirname, 'event.dispatcher.identifier.svelte'), @@ -333,7 +333,36 @@ describe('SvelteDoc v3 - Events', () => { }).then((doc) => { expect(doc, 'Document should be provided').to.exist; expect(doc.events, 'Document events should be parsed').to.exist; - expect(doc.events.length).to.equal(1); + expect(doc.events.length).to.equal(2); + + let event = doc.events[0]; + + expect(event, 'Event should be a valid entity').to.exist; + expect(event.name).to.equal('notify'); + expect(event.visibility).to.equal('public'); + + event = doc.events[1]; + + expect(event, 'Event should be a valid entity').to.exist; + expect(event.name).to.equal('plain-notify'); + expect(event.visibility).to.equal('public'); + + done(); + }).catch(e => { + done(e); + }); + }); + + xit('Dispatch event from code should be found when using an identifier from array', (done) => { + parser.parse({ + version: 3, + filename: path.resolve(__dirname, 'event.dispatcher.arrayIdentifier.svelte'), + features: ['events'], + ignoredVisibilities: [] + }).then((doc) => { + expect(doc, 'Document should be provided').to.exist; + expect(doc.events, 'Document events should be parsed').to.exist; + expect(doc.events.length).to.equal(2); const event = doc.events[0]; @@ -346,4 +375,33 @@ describe('SvelteDoc v3 - Events', () => { done(e); }); }); + + xit('Dispatch event from code should be found when using an identifier from imported object', (done) => { + parser.parse({ + version: 3, + filename: path.resolve(__dirname, 'event.dispatcher.importedIdentifier.svelte'), + features: ['events'], + ignoredVisibilities: [] + }).then((doc) => { + expect(doc, 'Document should be provided').to.exist; + expect(doc.events, 'Document events should be parsed').to.exist; + expect(doc.events.length).to.equal(2); + + let event = doc.events[0]; + + expect(event, 'Event should be a valid entity').to.exist; + expect(event.name).to.equal('notify'); + expect(event.visibility).to.equal('public'); + + event = doc.events[1]; + + expect(event, 'Event should be a valid entity').to.exist; + expect(event.name).to.equal('plain-notify'); + expect(event.visibility).to.equal('public'); + + done(); + }).catch(e => { + done(e); + }); + }); }); diff --git a/test/svelte3/integration/events/sharedEvents.js b/test/svelte3/integration/events/sharedEvents.js new file mode 100644 index 0000000..9ab7ccf --- /dev/null +++ b/test/svelte3/integration/events/sharedEvents.js @@ -0,0 +1,7 @@ +export const EVENT = { + SIGNAL: { + NOTIFY: 'notify', + }, +}; + +export const SIMPLE_EVENT = 'plain-notify';