Skip to content

Commit f60b078

Browse files
committed
test: added snapshot tests for webapp
- Added new snapshot test for DigitalExperienceBundle with web_app base type - Fixed merge conversion bug where files were placed at wrong directory level - Refactored duplicate code in digitalExperienceSourceAdapter - Added getWebAppBundleDir helper function to eliminate duplication
1 parent 673d7d3 commit f60b078

File tree

27 files changed

+698
-3
lines changed

27 files changed

+698
-3
lines changed

src/convert/transformers/defaultMetadataTransformer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ const getContentSourceDestination = (
8585
if (mergeWith?.content) {
8686
if (component.content && component.tree.isDirectory(component.content)) {
8787
// DEs are always inside a dir.
88-
if (component.type.strategies?.adapter === 'digitalExperience') {
88+
// For web_app base type, use standard relative path logic (no ContentType folders)
89+
const isWebApp = source.includes(`${sep}web_app${sep}`);
90+
if (component.type.strategies?.adapter === 'digitalExperience' && !isWebApp) {
8991
const parts = source.split(sep);
9092
const file = parts.pop() ?? '';
9193
const dir = join(mergeWith.content, parts.pop() ?? '');

src/resolve/adapters/digitalExperienceSourceAdapter.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
125125
return path;
126126
}
127127
if (isWebAppBaseType(path)) {
128-
return path;
128+
// For web_app, trim to the bundle directory: digitalExperiences/web_app/WebApp
129+
return getWebAppBundleDir(path);
129130
}
130131
const pathToContent = dirname(path);
131132
const parts = pathToContent.split(sep);
@@ -207,7 +208,7 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
207208
const bundleName = [baseType, spaceApiName].join('/');
208209

209210
// Extract bundle directory: /path/to/digitalExperiences/web_app/WebApp3
210-
const bundleDir = pathParts.slice(0, digitalExperiencesIndex + 3).join(sep);
211+
const bundleDir = getWebAppBundleDir(trigger);
211212

212213
// Get the DigitalExperienceBundle type
213214
const parentType = this.isBundleType() ? this.type : this.registry.getParentType(this.type.id);
@@ -289,3 +290,18 @@ const getDigitalExperiencesIndex = (path: string): number => {
289290
const pathParts = path.split(sep);
290291
return pathParts.indexOf('digitalExperiences');
291292
};
293+
294+
/**
295+
* Gets the web_app bundle directory path.
296+
* For a path like: /path/to/digitalExperiences/web_app/WebApp/src/App.js
297+
* Returns: /path/to/digitalExperiences/web_app/WebApp
298+
*/
299+
const getWebAppBundleDir = (path: string): string => {
300+
const pathParts = path.split(sep);
301+
const digitalExperiencesIndex = pathParts.indexOf('digitalExperiences');
302+
if (digitalExperiencesIndex > -1 && pathParts.length > digitalExperiencesIndex + 3) {
303+
// Return up to digitalExperiences/web_app/spaceApiName
304+
return pathParts.slice(0, digitalExperiencesIndex + 3).join(sep);
305+
}
306+
return path;
307+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# WebApp2
2+
3+
This is a dummy React application created for demonstration purposes.
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm install`
10+
11+
Installs all the dependencies required for the project.
12+
13+
### `npm start`
14+
15+
Runs the app in the development mode.\
16+
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
17+
18+
The page will reload when you make changes.\
19+
You may also see any lint errors in the console.
20+
21+
### `npm test`
22+
23+
Launches the test runner in the interactive watch mode.
24+
25+
### `npm run build`
26+
27+
Builds the app for production to the `build` folder.\
28+
It correctly bundles React in production mode and optimizes the build for the best performance.
29+
30+
## Getting Started
31+
32+
1. Install dependencies: `npm install`
33+
2. Start the development server: `npm start`
34+
3. Open your browser to [http://localhost:3000](http://localhost:3000)
35+
36+
## Project Structure
37+
38+
```
39+
WebApp2/
40+
├── public/
41+
│ └── index.html
42+
├── src/
43+
│ ├── App.js
44+
│ ├── App.css
45+
│ ├── index.js
46+
│ └── index.css
47+
├── package.json
48+
├── .gitignore
49+
└── README.md
50+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "webapp2",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"react": "^18.2.0",
7+
"react-dom": "^18.2.0",
8+
"react-scripts": "5.0.1"
9+
},
10+
"scripts": {
11+
"start": "react-scripts start",
12+
"build": "react-scripts build",
13+
"test": "react-scripts test",
14+
"eject": "react-scripts eject"
15+
},
16+
"browserslist": {
17+
"production": [
18+
">0.2%",
19+
"not dead",
20+
"not op_mini all"
21+
],
22+
"development": [
23+
"last 1 chrome version",
24+
"last 1 firefox version",
25+
"last 1 safari version"
26+
]
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<meta name="theme-color" content="#000000" />
7+
<meta
8+
name="description"
9+
content="Web App 2 - React Application"
10+
/>
11+
<title>WebApp2</title>
12+
</head>
13+
<body>
14+
<noscript>You need to enable JavaScript to run this app.</noscript>
15+
<div id="root"></div>
16+
</body>
17+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-header {
6+
background-color: #282c34;
7+
min-height: 100vh;
8+
display: flex;
9+
flex-direction: column;
10+
align-items: center;
11+
justify-content: center;
12+
font-size: calc(10px + 2vmin);
13+
color: white;
14+
}
15+
16+
.card {
17+
padding: 2rem;
18+
background-color: #1a1d23;
19+
border-radius: 8px;
20+
margin-top: 2rem;
21+
max-width: 600px;
22+
}
23+
24+
.card h2 {
25+
margin-top: 0;
26+
color: #61dafb;
27+
}
28+
29+
code {
30+
background-color: #1a1d23;
31+
padding: 0.2rem 0.4rem;
32+
border-radius: 4px;
33+
font-family: 'Courier New', monospace;
34+
color: #61dafb;
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import './App.css';
3+
4+
function App() {
5+
return (
6+
<div className="App">
7+
<header className="App-header">
8+
<h1>Welcome to WebApp2</h1>
9+
<p>
10+
This is a dummy React application.
11+
</p>
12+
<div className="card">
13+
<h2>Getting Started</h2>
14+
<p>
15+
Edit <code>src/App.js</code> and save to reload.
16+
</p>
17+
</div>
18+
</header>
19+
</div>
20+
);
21+
}
22+
23+
export default App;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
body {
2+
margin: 0;
3+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5+
sans-serif;
6+
-webkit-font-smoothing: antialiased;
7+
-moz-osx-font-smoothing: grayscale;
8+
}
9+
10+
code {
11+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12+
monospace;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import './index.css';
4+
import App from './App';
5+
6+
const root = ReactDOM.createRoot(document.getElementById('root'));
7+
root.render(
8+
<React.StrictMode>
9+
<App />
10+
</React.StrictMode>
11+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<types>
4+
<members>web_app/</members>
5+
<name>DigitalExperienceBundle</name>
6+
</types>
7+
<version>64.0</version>
8+
</Package>

0 commit comments

Comments
 (0)