-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix an issue with customized preview for Javascript modules for content with virtual nodes. The virtual nodes are correctly created (temporarily) in the session of the aliased user, however the rendering was performed with the current user, causing a ItemNotFoundException. The rendering now uses the aliased user if any, and fallback to the current user otherwise.
- Loading branch information
1 parent
4b1a2f9
commit 9c734a8
Showing
7 changed files
with
127 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
javascript-modules-engine/tests/cypress/e2e/ui/virtualNodeTest.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {addNode, createUser, deleteUser} from '@jahia/cypress'; | ||
import {addSimplePage} from '../../utils/Utils'; | ||
|
||
describe('Test virtual nodes', () => { | ||
const pageName = 'testVirtualNode'; | ||
|
||
before('Create test page and contents', () => { | ||
addSimplePage('/sites/npmTestSite/home', pageName, pageName, 'en', 'simple', [ | ||
{ | ||
name: 'pagecontent', | ||
primaryNodeType: 'jnt:contentList' | ||
} | ||
]).then(() => { | ||
addNode({ | ||
parentPathOrId: `/sites/npmTestSite/home/${pageName}/pagecontent`, | ||
name: 'test', | ||
primaryNodeType: 'npmExample:testVirtualNode', | ||
properties: [ | ||
{name: 'jcr:title', value: 'Test Virtual Node'} | ||
] | ||
}); | ||
}); | ||
}); | ||
|
||
it(`${pageName}: Check virtual nodes are correctly rendered in preview mode`, function () { | ||
cy.login(); | ||
cy.visit(`/cms/render/default/en/sites/npmTestSite/home/${pageName}.html`); | ||
cy.get('div[data-testid="testVirtualNodeSample_myProperty"]').contains('this is a virtual node property'); | ||
cy.get('div[data-testid="virtualNode_aliasedUser"]').should('be.empty'); // logged as root, no alias | ||
cy.logout(); | ||
}); | ||
it(`${pageName}: Check virtual nodes are correctly rendered in customized preview mode`, function () { | ||
cy.login(); | ||
let users = ['fooUser', 'barUser']; | ||
users.forEach(user => { | ||
createUser(user, 'testPassword'); | ||
cy.visit(`/cms/render/default/en/sites/npmTestSite/home/${pageName}.html?alias=${user}`); | ||
cy.get('div[data-testid="testVirtualNodeSample_myProperty"]').should('have.text', 'this is a virtual node property'); | ||
cy.get('div[data-testid="virtualNode_aliasedUser"]').should('have.text', user); | ||
deleteUser('testUser'); | ||
}); | ||
cy.logout(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 20 additions & 18 deletions
38
javascript-modules-engine/tests/jahia-module/src/react/server/views/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
export * from './contentList/ContentListParameters'; | ||
export * from './hydratedNavMenu/HydratedNavMenu'; | ||
export * from './navMenu/NavMenu'; | ||
export * from './testCurrentContent/TestCurrentContent'; | ||
export * from './testAbsoluteAreas/TestAbsoluteAreas'; | ||
export * from './testAreaColumns/TestAreaColumns'; | ||
export * from './testAreas/TestAreas'; | ||
export * from './testAbsoluteAreas/TestAbsoluteAreas'; | ||
export * from './testBoundComponent/TestBoundComponent'; | ||
export * from './testConfig/TestConfig'; | ||
export * from './testFindDisplayableContent/TestFindDisplayableContent'; | ||
export * from './testGQL/TestGQL'; | ||
export * from './testRender'; | ||
export * from './testUrl/TestUrl'; | ||
export * from './testGetNodeProps/TestGetNodeProps'; | ||
export * from './testGetChildNodes/TestGetChildNodes'; | ||
export * from './testContentTemplate/TestContentTemplate'; | ||
export * from './testContentTemplate/TestContentTemplateView'; | ||
export * from './testContentTemplate/TestContentTemplateOtherView'; | ||
export * from './testReactViewRegistration/TestReactViewRegistration'; | ||
export * from './testJCRQuery/TestJCRQuery'; | ||
export * from './testReactClientSide/TestReactClientSide'; | ||
export * from './contentList/ContentListParameters'; | ||
export * from './testContentTemplate/TestContentTemplateView'; | ||
export * from './testCrashingView/TestCrashingView'; | ||
export * from './testCurrentContent/TestCurrentContent'; | ||
export * from './testCurrentUser/TestCurrentUser'; | ||
export * from './testIsNodeType/TestIsNodeType'; | ||
export * from './testFindDisplayableContent/TestFindDisplayableContent'; | ||
export * from './testGQL/TestGQL'; | ||
export * from './testGetChildNodes/TestGetChildNodes'; | ||
export * from './testGetNodeProps/TestGetNodeProps'; | ||
export * from './testHasPermission/TestHasPermission'; | ||
export * from './testUrlParameters/TestUrlParameters'; | ||
export * from './testLocale/TestLocale'; | ||
export * from './testCrashingView/TestCrashingView'; | ||
export * from './testBoundComponent/TestBoundComponent'; | ||
export * from './testI18n/TestI18n'; | ||
export * from './testIsNodeType/TestIsNodeType'; | ||
export * from './testJCRQuery/TestJCRQuery'; | ||
export * from './testLocale/TestLocale'; | ||
export * from './testReactClientSide/TestReactClientSide'; | ||
export * from './testReactViewRegistration/TestReactViewRegistration'; | ||
export * from './testRender'; | ||
export * from './testRule/TestRule'; | ||
export * from './testUrl/TestUrl'; | ||
export * from './testUrlParameters/TestUrlParameters'; | ||
export * from './testVirtualNode'; | ||
|
33 changes: 33 additions & 0 deletions
33
...ules-engine/tests/jahia-module/src/react/server/views/testVirtualNode/TestVirtualNode.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import {defineJahiaComponent, Render, useServerContext} from '@jahia/javascript-modules-library'; | ||
|
||
|
||
export const TestVirtualNode = () => { | ||
const {currentNode, renderContext} = useServerContext(); | ||
const aliasedUser = renderContext.getMainResource().getNode().getSession().getAliasedUser(); | ||
// create a virtual node (TestVirtualNodeSample) | ||
const testVirtualNodeSample = { | ||
name: 'testVirtualNodeSample', | ||
nodeType: 'npmExample:testVirtualNodeSample', | ||
properties: { | ||
'myProperty': 'this is a virtual node property' | ||
} | ||
}; | ||
return ( | ||
<> | ||
<h3>test virtual node</h3> | ||
<div data-testid="virtualNode"> | ||
<div data-testid="virtualNode_aliasedUser">{aliasedUser == null ? "" : aliasedUser.getName()}</div> | ||
<Render content={testVirtualNodeSample}/> | ||
</div> | ||
<hr/> | ||
</> | ||
) | ||
} | ||
|
||
TestVirtualNode.jahiaComponent = defineJahiaComponent({ | ||
nodeType: 'npmExample:testVirtualNode', | ||
name: 'default', | ||
displayName: 'test virtual node', | ||
componentType: 'view' | ||
}); |
16 changes: 16 additions & 0 deletions
16
...ngine/tests/jahia-module/src/react/server/views/testVirtualNode/TestVirtualNodeSample.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import {defineJahiaComponent, getNodeProps, useServerContext} from '@jahia/javascript-modules-library'; | ||
|
||
export const TestVirtualNodeSample = () => { | ||
const {currentNode} = useServerContext(); | ||
const props = getNodeProps(currentNode, ['myProperty']); | ||
|
||
return ( | ||
<div data-testid="testVirtualNodeSample_myProperty">{props['myProperty']}</div> | ||
); | ||
}; | ||
|
||
TestVirtualNodeSample.jahiaComponent = defineJahiaComponent({ | ||
nodeType: 'npmExample:testVirtualNodeSample', | ||
componentType: 'view', | ||
}); |
2 changes: 2 additions & 0 deletions
2
javascript-modules-engine/tests/jahia-module/src/react/server/views/testVirtualNode/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './TestVirtualNode'; | ||
export * from './TestVirtualNodeSample'; |