SeasideSt / Seaside

The framework for developing sophisticated web applications in Smalltalk.
MIT License
519 stars 71 forks source link

Add a method to add data-test attributes #1447

Open koendehondt opened 4 weeks ago

koendehondt commented 4 weeks ago

Several frontend frameworks support data-test-* attributes. They are intended to be used in tests, not in production. It allows tests to easily identify elements in the DOM, without relying on long CSS selectors or element IDs, and without impacting the behaviour of the application. In fact, several frameworks render data-test-* attributes only during development, not during production. It would be nice if Seaside would support data-test-* attributes too.

The first step is to have a dedicated method to add a data-test-* attribute. Seaside provides WATagBrush>>#htmlDataAttributeAt:put:, which means that today code like this is required to add a data-test-* attribute:

html htmlDataAttributeAt: 'test-some-element' put: true

I suggest adding:

WATagBrush >> htmlDataTestAttribute: aString

    self attributes at: 'data-test-' , aString put: true
marschall commented 3 weeks ago

How would you switch them off for production? Different canvas class? #ifTrue: in component code? Configuration attribute?

jbrichau commented 3 weeks ago

@marschall I was thinking a separate configuration attribute.