From 35b8c1e3b9c59ef38c8717fe34b0e90975dfab75 Mon Sep 17 00:00:00 2001 From: Jesse Jurman Date: Fri, 6 Oct 2023 22:14:22 -0400 Subject: [PATCH] working import-component output --- cypress/import.cy.js | 18 +++ cypress/inline.cy.js | 65 ++++++++++ cypress/spec.cy.js | 65 ---------- examples/import/example-container.html | 14 +++ examples/import/im-progressbar.html | 17 +++ examples/import/im-temperature.html | 46 +++++++ examples/import/index.html | 31 +++++ examples/{ => inline}/index.html | 162 ++++++++++++------------- package.json | 10 +- result.js | 88 -------------- src/TramLite.js | 10 +- src/build-component.js | 36 ------ src/import-component.js | 36 ++++++ src/processors/ComponentDefinition.js | 16 +++ test.html | 3 - x-button.html | 3 - 16 files changed, 336 insertions(+), 284 deletions(-) create mode 100644 cypress/import.cy.js create mode 100644 cypress/inline.cy.js delete mode 100644 cypress/spec.cy.js create mode 100644 examples/import/example-container.html create mode 100644 examples/import/im-progressbar.html create mode 100644 examples/import/im-temperature.html create mode 100644 examples/import/index.html rename examples/{ => inline}/index.html (53%) delete mode 100644 result.js delete mode 100644 src/build-component.js create mode 100644 src/import-component.js delete mode 100644 test.html delete mode 100644 x-button.html diff --git a/cypress/import.cy.js b/cypress/import.cy.js new file mode 100644 index 0000000..3b4e390 --- /dev/null +++ b/cypress/import.cy.js @@ -0,0 +1,18 @@ +describe('Tram-Lite Example Components (via import)', () => { + it('should validate Tram-Lite APIs and Use Cases when importing components', () => { + // visit index.html (this works because the test page doesn't need to be hosted to work!) + cy.visit('../examples/import/index.html'); + + /* verify that component effects trigger on dependency updates */ + cy.get('im-temperature').get('input#f').type('19'); + cy.get('im-temperature').get('input#c').should('have.value', '-7'); + cy.get('im-temperature').get('input#f').should('have.value', '19'); + + /* verify that an element with multiple dependencies triggers on either dependency */ + cy.get('im-progressbar').should('not.have.attr', 'warning'); + cy.get('im-progressbar').get('input#value').clear().type('12'); + cy.get('im-progressbar').should('have.attr', 'warning'); + cy.get('im-progressbar').get('input#max').clear().type('15'); + cy.get('im-progressbar').should('not.have.attr', 'warning'); + }); +}); diff --git a/cypress/inline.cy.js b/cypress/inline.cy.js new file mode 100644 index 0000000..2f232df --- /dev/null +++ b/cypress/inline.cy.js @@ -0,0 +1,65 @@ +describe('Tram-Lite Example Components', () => { + // per Cypress best practices (https://docs.cypress.io/guides/references/best-practices#Creating-Tiny-Tests-With-A-Single-Assertion) + // it is often better to run all tests together, rather than having unit-like tests... so we'll comment the intent of each test, + // rather than doing a reset between each test. The results should still be just as obvious in the cypress runner! + it('should validate all Tram-Lite APIs and Use Cases', () => { + // visit index.html (this works because the test page doesn't need to be hosted to work!) + cy.visit('../examples/inline/index.html'); + + /* validate that slot elements are rendered as expected in Tram-Lite */ + cy.get('in-title').contains('Title'); + cy.get('in-title').contains('Tram-Lite Components!'); + + /* validate that the counter elements work as expected */ + cy.get('in-counter#default').contains(/Green: 0/); // default values should populate + cy.get('in-counter#red').contains(/Red: 0/); // passed in values should populate + cy.get('in-counter#red').click(); // clicking a counter should increment + cy.get('in-counter#red').contains(/Red: 1/); + + /* verify that updating inputs updates attributes as expected (tl-controlled) */ + cy.get('in-mirror').get('input#source').type('Hello, World'); + cy.get('in-mirror').get('input#reflection').should('have.value', 'Hello, World'); + cy.get('in-mirror').should('have.attr', 'value', 'Hello, World'); + cy.get('in-mirror').should('have.attr', 'is-mirrored', ''); + + /* verify that updating an attribute copies to multiple elements and attributes */ + cy.get('in-colorpicker').invoke('attr', 'hue', '120'); + cy.get('in-colorpicker').get('input#hue-range-input').should('have.value', '120'); + cy.get('in-colorpicker').get('input#hue-text-input').should('have.value', '120'); + cy.get('in-colorpicker') + .get('rect') + .then(($element) => { + const rawColor = window.getComputedStyle($element[0])['fill']; + expect(rawColor).to.equal('oklch(0.7 0.1 120)'); + }); + + /* verify that startup scripts in component definitions trigger as expected */ + cy.get('in-todoitem').contains('Example Initial Item'); + cy.get('in-todoitem').contains('Learning Tram-Lite'); + + /* verify that creating elements works as expected */ + cy.get('in-todolist').get('form input').type('Cypress Test'); // create new todo item + cy.get('in-todolist').get('form').submit(); + + cy.get('in-todoitem').contains('Cypress Test'); // verify it exists + + cy.get('in-todoitem').contains('Cypress Test').click(); // click it, and verify that the top label updates + cy.get('in-todolist').get('span').contains('(1/3)'); + + /* verify that updating an input with a false value unsets the attribute value */ + cy.get('in-todoitem').contains('Cypress Test').click(); + cy.get('in-todolist').get('span').contains('(0/3)'); + + /* verify that component effects trigger on dependency updates */ + cy.get('in-temperature').get('input#f').type('19'); + cy.get('in-temperature').get('input#c').should('have.value', '-7'); + cy.get('in-temperature').get('input#f').should('have.value', '19'); + + /* verify that an element with multiple dependencies triggers on either dependency */ + cy.get('in-progressbar').should('not.have.attr', 'warning'); + cy.get('in-progressbar').get('input#value').clear().type('12'); + cy.get('in-progressbar').should('have.attr', 'warning'); + cy.get('in-progressbar').get('input#max').clear().type('15'); + cy.get('in-progressbar').should('not.have.attr', 'warning'); + }); +}); diff --git a/cypress/spec.cy.js b/cypress/spec.cy.js deleted file mode 100644 index f8a1f48..0000000 --- a/cypress/spec.cy.js +++ /dev/null @@ -1,65 +0,0 @@ -describe('Tram-Lite Example Components', () => { - // per Cypress best practices (https://docs.cypress.io/guides/references/best-practices#Creating-Tiny-Tests-With-A-Single-Assertion) - // it is often better to run all tests together, rather than having unit-like tests... so we'll comment the intent of each test, - // rather than doing a reset between each test. The results should still be just as obvious in the cypress runner! - it('should validate all Tram-Lite APIs and Use Cases', () => { - // visit index.html (this works because the test page doesn't need to be hosted to work!) - cy.visit('../examples/index.html'); - - /* validate that slot elements are rendered as expected in Tram-Lite */ - cy.get('ex-title').contains('Title'); - cy.get('ex-title').contains('Tram-Lite Components!'); - - /* validate that the counter elements work as expected */ - cy.get('ex-counter#default').contains(/Green: 0/); // default values should populate - cy.get('ex-counter#red').contains(/Red: 0/); // passed in values should populate - cy.get('ex-counter#red').click(); // clicking a counter should increment - cy.get('ex-counter#red').contains(/Red: 1/); - - /* verify that updating inputs updates attributes as expected (tl-controlled) */ - cy.get('ex-mirror').get('input#source').type('Hello, World'); - cy.get('ex-mirror').get('input#reflection').should('have.value', 'Hello, World'); - cy.get('ex-mirror').should('have.attr', 'value', 'Hello, World'); - cy.get('ex-mirror').should('have.attr', 'is-mirrored', ''); - - /* verify that updating an attribute copies to multiple elements and attributes */ - cy.get('ex-colorpicker').invoke('attr', 'hue', '120'); - cy.get('ex-colorpicker').get('input#hue-range-input').should('have.value', '120'); - cy.get('ex-colorpicker').get('input#hue-text-input').should('have.value', '120'); - cy.get('ex-colorpicker') - .get('rect') - .then(($element) => { - const rawColor = window.getComputedStyle($element[0])['fill']; - expect(rawColor).to.equal('oklch(0.7 0.1 120)'); - }); - - /* verify that startup scripts in component definitions trigger as expected */ - cy.get('ex-todoitem').contains('Example Initial Item'); - cy.get('ex-todoitem').contains('Learning Tram-Lite'); - - /* verify that creating elements works as expected */ - cy.get('ex-todolist').get('form input').type('Cypress Test'); // create new todo item - cy.get('ex-todolist').get('form').submit(); - - cy.get('ex-todoitem').contains('Cypress Test'); // verify it exists - - cy.get('ex-todoitem').contains('Cypress Test').click(); // click it, and verify that the top label updates - cy.get('ex-todolist').get('span').contains('(1/3)'); - - /* verify that updating an input with a false value unsets the attribute value */ - cy.get('ex-todoitem').contains('Cypress Test').click(); - cy.get('ex-todolist').get('span').contains('(0/3)'); - - /* verify that component effects trigger on dependency updates */ - cy.get('ex-temperature').get('input#f').type('19'); - cy.get('ex-temperature').get('input#c').should('have.value', '-7'); - cy.get('ex-temperature').get('input#f').should('have.value', '19'); - - /* verify that an element with multiple dependencies triggers on either dependency */ - cy.get('ex-progressbar').should('not.have.attr', 'warning'); - cy.get('ex-progressbar').get('input#value').clear().type('12'); - cy.get('ex-progressbar').should('have.attr', 'warning'); - cy.get('ex-progressbar').get('input#max').clear().type('15'); - cy.get('ex-progressbar').should('not.have.attr', 'warning'); - }); -}); diff --git a/examples/import/example-container.html b/examples/import/example-container.html new file mode 100644 index 0000000..566f319 --- /dev/null +++ b/examples/import/example-container.html @@ -0,0 +1,14 @@ + + +
+ ${'name'} + +
+
diff --git a/examples/import/im-progressbar.html b/examples/import/im-progressbar.html new file mode 100644 index 0000000..5a71ade --- /dev/null +++ b/examples/import/im-progressbar.html @@ -0,0 +1,17 @@ + +
+ + +
+ +
${'warning'}
+ +
diff --git a/examples/import/im-temperature.html b/examples/import/im-temperature.html new file mode 100644 index 0000000..54bf837 --- /dev/null +++ b/examples/import/im-temperature.html @@ -0,0 +1,46 @@ + + + = + + + + + + diff --git a/examples/import/index.html b/examples/import/index.html new file mode 100644 index 0000000..d5cbece --- /dev/null +++ b/examples/import/index.html @@ -0,0 +1,31 @@ + + + + Tram-Lite Example Components + + + + + + + + + + + + + + + + diff --git a/examples/index.html b/examples/inline/index.html similarity index 53% rename from examples/index.html rename to examples/inline/index.html index 7f40718..c2e239e 100644 --- a/examples/index.html +++ b/examples/inline/index.html @@ -15,7 +15,7 @@ } - +