Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adobe/aem-spa-page-model-manager
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.4.3
Choose a base ref
...
head repository: adobe/aem-spa-page-model-manager
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.4.4
Choose a head ref
  • 2 commits
  • 9 files changed
  • 2 contributors

Commits on Jun 21, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    316aeb6 View commit details
  2. chore(release): 1.4.4 [skip ci]

    ## [1.4.4](v1.4.3...v1.4.4) (2022-06-21)
    
    ### Bug Fixes
    
    * check the existence of the window object in places where is not yet verified ([#86](#86)) ([316aeb6](316aeb6))
    semantic-release-bot committed Jun 21, 2022
    Copy the full SHA
    6484b37 View commit details
Showing with 41 additions and 16 deletions.
  1. +7 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +8 −4 src/ModelRouter.ts
  4. +1 −1 src/PathUtils.ts
  5. +5 −6 test/AuthoringUtils.test.ts
  6. +7 −2 test/ModelManager.test.ts
  7. +7 −1 test/ModelRouter.test.ts
  8. +5 −0 test/ModelStore.test.ts
  9. +0 −1 test/data/MainPageData.ts
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.4.4](https://github.com/adobe/aem-spa-page-model-manager/compare/v1.4.3...v1.4.4) (2022-06-21)


### Bug Fixes

* check the existence of the window object in places where is not yet verified ([#86](https://github.com/adobe/aem-spa-page-model-manager/issues/86)) ([316aeb6](https://github.com/adobe/aem-spa-page-model-manager/commit/316aeb667d0ab704b77ebe5840c11f70cab33fb8))

## [1.4.3](https://github.com/adobe/aem-spa-page-model-manager/compare/v1.4.2...v1.4.3) (2022-06-02)


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/aem-spa-page-model-manager",
"version": "1.4.3",
"version": "1.4.4",
"description": "An interpreter between AEM Editor and the AEM SPA Editor.",
"keywords": [
"spa",
12 changes: 8 additions & 4 deletions src/ModelRouter.ts
Original file line number Diff line number Diff line change
@@ -76,9 +76,13 @@ export class RouterModes {
* @return
*/
export function getModelPath(url?: string | null | URL): string | null {
const localUrl = (url || window.location.pathname) as string;
const localUrl = (url || (PathUtils.isBrowser() && window.location.pathname)) as string;

return PathUtils.sanitize(localUrl);
if (localUrl) {
return PathUtils.sanitize(localUrl);
}

return null;
}

/**
@@ -179,7 +183,7 @@ export function routeModel(url?: string | undefined | null | URL): void {

export function initModelRouter(): void {
// Activate the model router
if (isModelRouterEnabled() && typeof window !== 'undefined') {
if (isModelRouterEnabled() && PathUtils.isBrowser()) {
// Encapsulate the history.pushState and history.replaceState functions to prefetch the page model for the current route
const pushState = window.history.pushState;
const replaceState = window.history.replaceState;
@@ -202,4 +206,4 @@ export function initModelRouter(): void {
return replaceState.apply(history, [ state, title, url ]);
};
}
}
}
2 changes: 1 addition & 1 deletion src/PathUtils.ts
Original file line number Diff line number Diff line change
@@ -558,7 +558,7 @@ export class PathUtils {
* @returns Updated path to match against
*/
public static toAEMPath(path: string, aemHost: string, rootPath: string): string {
const isLoadedInAEM = window.location.origin === aemHost;
const isLoadedInAEM = this.isBrowser() && window.location.origin === aemHost;

if (isLoadedInAEM) {
// Remove leading and trailing slashes, if any
11 changes: 5 additions & 6 deletions test/AuthoringUtils.test.ts
Original file line number Diff line number Diff line change
@@ -11,10 +11,10 @@
*/

import * as assert from 'assert';
import {AuthoringUtils} from '../src/AuthoringUtils';
import {PathUtils} from '../src/PathUtils';
import {AEM_MODE} from '../src/Constants';
import MetaProperty from "../src/MetaProperty";
import { AuthoringUtils } from '../src/AuthoringUtils';
import { PathUtils } from '../src/PathUtils';
import { AEM_MODE } from '../src/Constants';
import MetaProperty from '../src/MetaProperty';

describe('AuthoringUtils ->', () => {
let authoringUtils: AuthoringUtils;
@@ -94,7 +94,7 @@ describe('AuthoringUtils ->', () => {

// then
Object.entries(AuthoringUtils.AUTHORING_LIBRARIES.META).forEach((entry) => {
const [key, val] = entry;
const [ key, val ] = entry;

assert.ok(libs.querySelectorAll('meta[property="' + key + '"][content="' + val + '"]'));
});
@@ -231,7 +231,6 @@ describe('AuthoringUtils ->', () => {
});
});


describe('isPreviewMode', () => {
it('should be false if both indicators are falsy', () => {
jest.spyOn(PathUtils, 'getMetaPropertyValue').mockReturnValue(AEM_MODE.EDIT);
9 changes: 7 additions & 2 deletions test/ModelManager.test.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ import EventType from '../src/EventType';
import InternalConstants from '../src/InternalConstants';
import MetaProperty from '../src/MetaProperty';
import { ModelClient } from '../src/ModelClient';
import ModelManager, {ModelManagerConfiguration} from '../src/ModelManager';
import ModelManager, { ModelManagerConfiguration } from '../src/ModelManager';
import { isRouteExcluded } from '../src/ModelRouter';
import { PathUtils } from '../src/PathUtils';
import { content_test_page_root_child0000_child0010, PAGE_MODEL, ERROR_PAGE_MODEL_404, ERROR_PAGE_MODEL_500 } from './data/MainPageData';
@@ -44,7 +44,7 @@ jest.mock('../src/ModelRouter');

const REQUEST_MAP:{[key:string]:any} = {};

fetchMock.mockResponse( (req) => {
fetchMock.mockResponse((req) => {
if (REQUEST_MAP[req.url]) {
return Promise.resolve({
body: JSON.stringify(REQUEST_MAP[req.url])
@@ -231,6 +231,7 @@ describe('ModelManager ->', () => {

it('should fetch data once on initialization when sub page route path is excluded', () => {
isRouteExcludedSpy.mockReturnValue(true);

return ModelManager.initialize({ path: PAGE_PATH, modelClient: modelClient }).then((data) => {
expectPageModelLoadedEventFired();
verify(ModelClientMock.fetch(anyString())).times(1);
@@ -345,10 +346,12 @@ describe('ModelManager ->', () => {
errorPageRoot: ERROR_PAGE_ROOT
};
const data:Model = await ModelManager.initialize(configuration);

verify(modelClient.fetch(anyString()));
assert.deepEqual(data, PAGE_MODEL, 'data should be correct');

const nonExistingData = await ModelManager._fetchData(NON_EXISTING_PATH);

assert.deepEqual(nonExistingData, ERROR_PAGE_MODEL_404, 'data should be correct');

});
@@ -361,10 +364,12 @@ describe('ModelManager ->', () => {
errorPageRoot: ERROR_PAGE_ROOT
};
const data:Model = await ModelManager.initialize(configuration);

verify(modelClient.fetch(anyString()));
assert.deepEqual(data, PAGE_MODEL, 'data should be correct');

const nonExistingData = await ModelManager._fetchData(PAGE_WITH_ERROR_PATH);

assert.deepEqual(nonExistingData, ERROR_PAGE_MODEL_500, 'data should be correct');

});
8 changes: 7 additions & 1 deletion test/ModelRouter.test.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import MetaProperty from '../src/MetaProperty';
import { Model } from '../src/Model';
import ModelManager from '../src/ModelManager';
import {
dispatchRouteChanged, getModelPath, getRouteFilters, initModelRouter, isModelRouterEnabled, isRouteExcluded, routeModel, RouterModes,
dispatchRouteChanged, getModelPath, getRouteFilters, initModelRouter, isModelRouterEnabled, isRouteExcluded, routeModel, RouterModes
} from '../src/ModelRouter';
import { PathUtils } from '../src/PathUtils';

@@ -49,6 +49,12 @@ describe('ModelRouter ->', () => {
it('should get the current window URL', () => {
expect(getModelPath('/zyx/abc?date=03.10.2021')).toEqual('/zyx/abc');
});
it('should return null', () => {
const isBrowserSpy = jest.spyOn(PathUtils, 'isBrowser').mockImplementation(() => false);

expect(getModelPath()).toBeNull();
isBrowserSpy.mockRestore();
});
});

describe('dispatchRouteChanged ->', () => {
5 changes: 5 additions & 0 deletions test/ModelStore.test.ts
Original file line number Diff line number Diff line change
@@ -190,7 +190,9 @@ describe('ModelStore ->', () => {
describe('setData', () => {
it('should set data', () => {
let item: any = modelStore.getData('/content/test/child_page_1/jcr:content/root/child1000');

item[TEST_FIELD] = TEST_FIELD_DATA;

const val = {
key: 'child1000',
value: item
@@ -204,11 +206,14 @@ describe('ModelStore ->', () => {

it('should set empty string on removed data', () => {
let item: any = modelStore.getData('/content/test/child_page_1/jcr:content/root/child1000');

item[TEST_FIELD] = TEST_FIELD_DATA;

const val = {
key: 'child1000',
value: item
};

modelStore.setData('/content/test/child_page_1/jcr:content/root/child1000', val);

delete item[TEST_FIELD];
1 change: 0 additions & 1 deletion test/data/MainPageData.ts
Original file line number Diff line number Diff line change
@@ -152,7 +152,6 @@ export const ERROR_PAGE_MODEL_404: PageModel = {
':type': 'we-retail-react/components/structure/page'
};


export const ERROR_PAGE_MODEL_500: PageModel = {
'designPath': '/libs/settings/wcm/designs/default',
'title': 'Example Error Page 500',