Seaside icon indicating copy to clipboard operation
Seaside copied to clipboard

Add a method to add data-test attributes

Open koendehondt opened this issue 1 year ago • 2 comments

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

koendehondt avatar Oct 25 '24 09:10 koendehondt

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

marschall avatar Oct 27 '24 19:10 marschall

@marschall I was thinking a separate configuration attribute.

jbrichau avatar Oct 28 '24 15:10 jbrichau