Replies: 6 comments 25 replies
-
I've never used angular-testing-library but in SlickGrid if you want to call a rerender, you can do that via On the other hand, I use Cypress for all my SlickGrid projects but I gave a try to Playwright in my other lib Maybe a potential problem with unit testing tools is that Angular-Slickgrid is not a pure Angular library, it's a SlickGrid wrapper which uses native HTML, so that could potentially add challenges with some testing libraries but Cypress/Playwright should work just fine. All my Examples are tested with Cypress and it helps quite a lot to make sure I'm not breaking anything, especially with major version (which I'm working on and expect a major release in coming month). not sure if that helped or not... feel free to ask some more |
Beta Was this translation helpful? Give feedback.
-
ok I see. Well in that case your change won't really help as the issue is here https://github.com/6pac/SlickGrid/blob/version4/slick.grid.js#L2119 and JSDOM simply doesn't attach an ownerNode as is done so by browsers. As for defineProperty overrides ... so the container we're talking about is <div class="slickgrid-container slickgrid_501049 ui-widget" style="width: 100%; overflow: hidden; outline: 0px;" id="grid1">...</div> which gets created during rendering of my component, which on the other hand though is already too late to be monkey patched via defineProp. So I'd have to come up with an alternative approach for that |
Beta Was this translation helpful? Give feedback.
-
So what I'd need within slick.grid.js (from npm slickgrid) would be the following two workarounds. --- a/node_modules/slickgrid/slick.grid.js
+++ b/node_modules/slickgrid/slick.grid.js
@@ -2085,6 +2085,8 @@ if (typeof Slick === "undefined") {
var i;
if (!stylesheet) {
var sheets = document.styleSheets;
+ sheets[0].ownerNode = _style;
+
for (i = 0; i < sheets.length; i++) {
if ((sheets[i].ownerNode || sheets[i].owningElement) == _style) {
stylesheet = sheets[i];
@@ -3718,7 +3720,7 @@ if (typeof Slick === "undefined") {
}
function getViewportWidth() {
- viewportW = parseFloat(utils.innerSize(_container, 'width'));
+ viewportW = parseFloat(utils.innerSize(_container, 'width')) || 1000;
}
function resizeCanvas() { The first to overcome the lack of ownerNode support, the second to accomodate the non-existing clientWidth calculation in jsDom. The second one could be formalized by leveraging the defaults property as for the missing ownerNode ... dunno how to approach that tbh |
Beta Was this translation helpful? Give feedback.
-
aight there it is 6pac/SlickGrid#944 The final test now for angular-testing-library based tests looks like the following: const { rerender } = await render(GridDemoComponent, {
imports: [AppModule, AngularSlickgridModule.forRoot({
autoResize: {
container: 'whatever_it_is_as_long_as_its_a_valid_css_selector',
},
devMode: {
containerClientWidth: 1000, // <--------- set the fake width
ownerNodeIndex: 0 // <--------- indicate which stylesheet is supposed to resemble the injected _style
}
} as any)],
providers: [
{
provide: SupabaseRepository,
useValue: {
async loadAll() {
return fakeData;
},
async lookupData() {
return fakeLookupData;
}
},
},
],
});
await rerender();
const rows = document.querySelectorAll('.slick-row')!;
expect(Array.from(rows).length).toBeGreaterThan(0);
expect(document.querySelector("div.slick-cell.l8.r8")).toBeInTheDocument(); |
Beta Was this translation helpful? Give feedback.
-
@zewa666 hey so out of subject, but looking at Aurelia-Slickgrid code and I just remember that you've added an optional Header/Footer using slots, I've never managed (or spend time) trying to replicate this in Angular-Slickgrid, if you know how to do the same in here, that'd be great and I would be happy to receive another PR from you 😉 BTW, new major is published |
Beta Was this translation helpful? Give feedback.
-
yeah passing the ng-templates as children shouldnt be too troublesome. I'll take a look at it and create a new issue to keep the discussion separated |
Beta Was this translation helpful? Give feedback.
-
Hey there. So today I was experimenting with rendering the actual grid in jest dom tests so that I can use angular-testing-library for behavior validations.
there were some ugly parts from slickgrid like looking for document.styleSheets but I managed to work around those. Now the grid successfully rendered (confirmed via screen.debug print). sadly though even though my dataset gets applied the provided rows do not render. So I guess the issue has to do something with timing issues or having to force manual rerenders.
I thought before diving deeper into this I'd ask here whether anyone tried to do something similar.
if it turns out not to work its no biggy either since I could switch to using playwright and real browser rendering, but its an interesting challenge ;)
Beta Was this translation helpful? Give feedback.
All reactions