Skip to content

Commit

Permalink
Merge branch 'develop' into feature/GH-12358
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophHi committed May 27, 2021
2 parents 3e344d3 + f9faf0e commit e8ffbb8
Show file tree
Hide file tree
Showing 166 changed files with 5,529 additions and 4,107 deletions.
5 changes: 0 additions & 5 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

------------------------------------------------------------------------------
APIs

This project may include APIs to SAP or third party products or services. The use of these APIs, products and services may be subject to additional agreements. In no event shall the application of the Apache Software License, v.2 to this project grant any rights in or to these APIs, products or services that would alter, expand, be inconsistent with, or supersede any terms of these additional agreements. ìAPIî means application programming interfaces, as well as their respective specifications and implementing code that allows other software products to communicate with or call on SAP or third party products or services (for example, SAP Enterprise Services, BAPIs, Idocs, RFCs and ABAP calls or other user exits) and may be made available through SAP or third party products, SDKs, documentation or other media.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ Many improvements are coming! All tasks will be posted to our GitHub issue track

Copyright (c) 2018 SAP SE or an SAP affiliate company. All rights reserved.
This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the [LICENSE](LICENSE) file.

7 changes: 7 additions & 0 deletions docs/migration/css-changes-in-version-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Changes to Styles in 4.0
---

## Changes in Checkout Components

* `cx-product-variants` selector has been moved to corresponding feature-lib `@spartacus/product`.
2 changes: 1 addition & 1 deletion feature-libs/asm/root/services/asm-auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MockUserIdService {
}

class MockOAuthLibWrapperService {
revokeAndLogout = jasmine.createSpy();
revokeAndLogout = jasmine.createSpy().and.returnValue(Promise.resolve());
initLoginFlow = jasmine.createSpy();

authorizeWithPasswordFlow = () => new Promise(() => {});
Expand Down
125 changes: 45 additions & 80 deletions feature-libs/asm/schematics/add-asm/__snapshots__/index_spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,91 +1,56 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Spartacus Asm schematics: ng-add When no features are provided should not add the feature to the feature module 1`] = `
exports[`Spartacus Asm schematics: ng-add Asm feature eager loading should import appropriate modules 1`] = `
"import { NgModule } from '@angular/core';
import { AnonymousConsentsModule, AuthModule, CartModule, CartOccModule, CheckoutModule, CheckoutOccModule, CostCenterOccModule, ProductModule, ProductOccModule, UserOccTransitionalModule, UserTransitionalModule } from \\"@spartacus/core\\";
import { AddressBookModule, AnonymousConsentManagementBannerModule, AnonymousConsentsDialogModule, BannerCarouselModule, BannerModule, BreadcrumbModule, CartComponentModule, CartPageEventModule, CategoryNavigationModule, CheckoutComponentModule, CheckoutLoginModule, CmsParagraphModule, ConsentManagementModule, FooterNavigationModule, HamburgerMenuModule, HomePageEventModule, LinkModule, LoginRouteModule, LogoutModule, MyCouponsModule, MyInterestsModule, NavigationEventModule, NavigationModule, NotificationPreferenceModule, OrderCancellationModule, OrderConfirmationModule, OrderDetailsModule, OrderHistoryModule, OrderReturnModule, PaymentMethodsModule, ProductCarouselModule, ProductDetailsPageModule, ProductFacetNavigationModule, ProductImagesModule, ProductIntroModule, ProductListingPageModule, ProductListModule, ProductPageEventModule, ProductReferencesModule, ProductSummaryModule, ProductTabsModule, ReplenishmentOrderConfirmationModule, ReplenishmentOrderDetailsModule, ReplenishmentOrderHistoryModule, ReturnRequestDetailModule, ReturnRequestListModule, SearchBoxModule, SiteContextSelectorModule, StockNotificationModule, TabParagraphContainerModule, WishListModule } from \\"@spartacus/storefront\\";
import { AsmModule } from \\"@spartacus/asm\\";
import { asmTranslationChunksConfig, asmTranslations } from \\"@spartacus/asm/assets\\";
import { AsmRootModule } from \\"@spartacus/asm/root\\";
import { I18nConfig, provideConfig } from \\"@spartacus/core\\";
@NgModule({
declarations: [],
imports: [
// Auth Core
AuthModule.forRoot(),
LogoutModule,
LoginRouteModule,
// Basic Cms Components
HamburgerMenuModule,
SiteContextSelectorModule,
LinkModule,
BannerModule,
CmsParagraphModule,
TabParagraphContainerModule,
BannerCarouselModule,
CategoryNavigationModule,
NavigationModule,
FooterNavigationModule,
BreadcrumbModule,
// User Core,
UserTransitionalModule,
UserOccTransitionalModule,
// User UI,
AddressBookModule,
PaymentMethodsModule,
NotificationPreferenceModule,
MyInterestsModule,
StockNotificationModule,
ConsentManagementModule,
MyCouponsModule,
// Anonymous Consents Core,
AnonymousConsentsModule.forRoot(),
// Anonymous Consents UI,
AnonymousConsentsDialogModule,
AnonymousConsentManagementBannerModule,
// Product Core,
ProductModule.forRoot(),
ProductOccModule,
// Product UI,
ProductDetailsPageModule,
ProductListingPageModule,
ProductListModule,
SearchBoxModule,
ProductFacetNavigationModule,
ProductTabsModule,
ProductCarouselModule,
ProductReferencesModule,
ProductImagesModule,
ProductSummaryModule,
ProductIntroModule,
// Cart Core,
CartModule.forRoot(),
CartOccModule,
// Cart UI,
CartComponentModule,
WishListModule,
// Checkout Core,
CheckoutModule.forRoot(),
CheckoutOccModule,
CostCenterOccModule,
// Checkout UI,
CheckoutLoginModule,
CheckoutComponentModule,
OrderConfirmationModule,
// Order,
OrderHistoryModule,
OrderDetailsModule,
OrderCancellationModule,
OrderReturnModule,
ReturnRequestListModule,
ReturnRequestDetailModule,
ReplenishmentOrderHistoryModule,
ReplenishmentOrderDetailsModule,
ReplenishmentOrderConfirmationModule,
// Page Events,
NavigationEventModule,
HomePageEventModule,
CartPageEventModule,
ProductPageEventModule,
AsmRootModule,
AsmModule
],
providers: [provideConfig(<I18nConfig>{
i18n: {
resources: asmTranslations,
chunks: asmTranslationChunksConfig,
},
})]
})
export class AsmFeatureModule { }
"
`;
exports[`Spartacus Asm schematics: ng-add Asm feature general setup should add the feature using the lazy loading syntax 1`] = `
"import { NgModule } from '@angular/core';
import { asmTranslationChunksConfig, asmTranslations } from \\"@spartacus/asm/assets\\";
import { AsmRootModule, ASM_FEATURE } from \\"@spartacus/asm/root\\";
import { CmsConfig, I18nConfig, provideConfig } from \\"@spartacus/core\\";
@NgModule({
declarations: [],
imports: [
AsmRootModule
],
providers: [provideConfig(<CmsConfig>{
featureModules: {
[ASM_FEATURE]: {
module: () =>
import('@spartacus/asm').then((m) => m.AsmModule),
},
}
}),
provideConfig(<I18nConfig>{
i18n: {
resources: asmTranslations,
chunks: asmTranslationChunksConfig,
},
})
]
})
export class SpartacusFeaturesModule { }
export class AsmFeatureModule { }
"
`;
11 changes: 3 additions & 8 deletions feature-libs/asm/schematics/add-asm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,16 @@ import {
} from '../constants';

export function addAsmFeatures(options: SpartacusAsmOptions): Rule {
return (tree: Tree, context: SchematicContext) => {
return (tree: Tree, _context: SchematicContext): Rule => {
const packageJson = readPackageJson(tree);
validateSpartacusInstallation(packageJson);

return chain([
addPackageJsonDependenciesForLibrary(peerDependencies, options),

shouldAddFeature(CLI_ASM_FEATURE, options.features)
? addAsmFeature(options)
: noop(),

addPackageJsonDependenciesForLibrary({
packageJson,
context,
dependencies: peerDependencies,
options,
}),
]);
};
}
Expand Down
127 changes: 52 additions & 75 deletions feature-libs/asm/schematics/add-asm/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {
CLI_ASM_FEATURE,
LibraryOptions as SpartacusAsmOptions,
SpartacusOptions,
SPARTACUS_SCHEMATICS,
} from '@spartacus/schematics';
import * as path from 'path';
import { peerDependencies } from '../../package.json';

const collectionPath = path.join(__dirname, '../collection.json');
const asmFeatureModulePath =
const featureModulePath =
'src/app/spartacus/features/asm/asm-feature.module.ts';

describe('Spartacus Asm schematics: ng-add', () => {
Expand Down Expand Up @@ -47,15 +49,20 @@ describe('Spartacus Asm schematics: ng-add', () => {
features: [],
};

const defaultFeatureOptions: SpartacusAsmOptions = {
const libraryNoFeaturesOptions: SpartacusAsmOptions = {
project: 'schematics-test',
lazy: true,
features: [],
};

const asmFeatureOptions: SpartacusAsmOptions = {
...libraryNoFeaturesOptions,
features: [CLI_ASM_FEATURE],
};

beforeEach(async () => {
schematicRunner.registerCollection(
'@spartacus/schematics',
SPARTACUS_SCHEMATICS,
'../../projects/schematics/src/collection.json'
);

Expand All @@ -76,112 +83,82 @@ describe('Spartacus Asm schematics: ng-add', () => {
.toPromise();
appTree = await schematicRunner
.runExternalSchematicAsync(
'@spartacus/schematics',
SPARTACUS_SCHEMATICS,
'ng-add',
{ ...spartacusDefaultOptions, name: 'schematics-test' },
appTree
)
.toPromise();
});

describe('When no features are provided', () => {
describe('Without features', () => {
beforeEach(async () => {
appTree = await schematicRunner
.runSchematicAsync(
'ng-add',
{ ...defaultFeatureOptions, features: [] },
appTree
)
.runSchematicAsync('ng-add', libraryNoFeaturesOptions, appTree)
.toPromise();
});

it('should not create the feature module', () => {
const featureModule = appTree.readContent(asmFeatureModulePath);
expect(featureModule).toBeFalsy();
it('should not create any of the feature modules', () => {
expect(appTree.exists(featureModulePath)).toBeFalsy();
});
it('should not add the feature to the feature module', () => {
const spartacusFeaturesModule = appTree.readContent(
'src/app/spartacus/spartacus-features.module.ts'
);
expect(spartacusFeaturesModule).toMatchSnapshot();

it('should install necessary Spartacus libraries', () => {
const packageJson = JSON.parse(appTree.readContent('package.json'));
let dependencies: Record<string, string> = {};
dependencies = { ...packageJson.dependencies };
dependencies = { ...dependencies, ...packageJson.devDependencies };

for (const toAdd in peerDependencies) {
// skip the SPARTACUS_SCHEMATICS, as those are added only when running by the Angular CLI, and not in the testing environment
if (
!peerDependencies.hasOwnProperty(toAdd) ||
toAdd === SPARTACUS_SCHEMATICS
) {
continue;
}
// TODO: after 4.0: use this test, as we'll have synced versions between lib's and root package.json
// const expectedVersion = (peerDependencies as Record<
// string,
// string
// >)[toAdd];
const expectedDependency = dependencies[toAdd];
expect(expectedDependency).toBeTruthy();
// expect(expectedDependency).toEqual(expectedVersion);
}
});
});

describe('Asm feature', () => {
describe('styling', () => {
describe('general setup', () => {
beforeEach(async () => {
appTree = await schematicRunner
.runSchematicAsync('ng-add', defaultFeatureOptions, appTree)
.runSchematicAsync('ng-add', asmFeatureOptions, appTree)
.toPromise();
});

it('should add the feature using the lazy loading syntax', async () => {
const module = appTree.readContent(featureModulePath);
expect(module).toMatchSnapshot();
});
});

describe('eager loading', () => {
beforeEach(async () => {
appTree = await schematicRunner
.runSchematicAsync(
'ng-add',
{ ...defaultFeatureOptions, lazy: false },
{
...asmFeatureOptions,
lazy: false,
},
appTree
)
.toPromise();
});

it('should import appropriate modules', async () => {
const asmModule = appTree.readContent(asmFeatureModulePath);
expect(asmModule).toContain(
`import { AsmRootModule } from "@spartacus/asm/root";`
);
expect(asmModule).toContain(
`import { AsmModule } from "@spartacus/asm";`
);
});

it('should not contain lazy loading syntax', async () => {
const asmModule = appTree.readContent(asmFeatureModulePath);
expect(asmModule).not.toContain(`import('@spartacus/asm').then(`);
});
});

describe('lazy loading', () => {
beforeEach(async () => {
appTree = await schematicRunner
.runSchematicAsync('ng-add', defaultFeatureOptions, appTree)
.toPromise();
});

it('should import AsmRootModule and contain the lazy loading syntax', async () => {
const asmModule = appTree.readContent(asmFeatureModulePath);
expect(asmModule).toContain(
`import { AsmRootModule, ASM_FEATURE } from "@spartacus/asm/root";`
);
expect(asmModule).toContain(`import('@spartacus/asm').then(`);
});

it('should not contain the AsmModule import', () => {
const asmModule = appTree.readContent(asmFeatureModulePath);
expect(asmModule).not.toContain(
`import { AsmModule } from "@spartacus/asm";`
);
});
});
describe('i18n', () => {
beforeEach(async () => {
appTree = await schematicRunner
.runSchematicAsync('ng-add', defaultFeatureOptions, appTree)
.toPromise();
});

it('should import the i18n resource and chunk from assets', async () => {
const asmModule = appTree.readContent(asmFeatureModulePath);
expect(asmModule).toContain(
`import { asmTranslationChunksConfig, asmTranslations } from "@spartacus/asm/assets";`
);
});
it('should provideConfig', async () => {
const asmModule = appTree.readContent(asmFeatureModulePath);
expect(asmModule).toContain(`resources: asmTranslations,`);
expect(asmModule).toContain(`chunks: asmTranslationChunksConfig,`);
const module = appTree.readContent(featureModulePath);
expect(module).toMatchSnapshot();
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/asm/schematics/add-asm/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"features": {
"type": "array",
"uniqueItems": true,
"default": ["Assisted Services Module"]
"default": ["ASM"]
}
},
"required": []
Expand Down
Loading

0 comments on commit e8ffbb8

Please sign in to comment.