Skip to content

Commit

Permalink
feat: Saved cart feature (#11358)
Browse files Browse the repository at this point in the history
Saved Carts is a generic save-a-cart-for-later mechanism. It's similar to the favorites wishlist. It allows us to save an active cart, see all saved carts on the list and make the saved cart active. It's especially important to the Import CSV feature 

Closes #11062
  • Loading branch information
bgambocjaviniar authored Mar 26, 2021
1 parent 25bf118 commit 7c14d9a
Show file tree
Hide file tree
Showing 176 changed files with 9,406 additions and 219 deletions.
41 changes: 41 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
{
"input": "projects/storefrontapp/src/styles/lib-qualtrics.scss",
"bundleName": "qualtrics"
},
{
"input": "projects/storefrontapp/src/styles/lib-cart.scss",
"bundleName": "cart"
}
],
"stylePreprocessorOptions": {
Expand Down Expand Up @@ -764,6 +768,43 @@
}
}
}
},
"cart": {
"projectType": "library",
"root": "feature-libs/cart",
"sourceRoot": "feature-libs/cart",
"prefix": "cx",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "feature-libs/cart/tsconfig.lib.json",
"project": "feature-libs/cart/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "feature-libs/cart/tsconfig.lib.prod.json"
}
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "feature-libs/cart/test.ts",
"tsConfig": "feature-libs/cart/tsconfig.spec.json",
"karmaConfig": "feature-libs/cart/karma.conf.js"
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"feature-libs/cart/**/*.ts",
"feature-libs/cart/**/*.html"
]
}
}
}
}
},
"defaultProject": "storefrontapp"
Expand Down
12 changes: 12 additions & 0 deletions ci-scripts/unit-tests-sonar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ echo "Running schematics unit tests and code coverage for asm library"
exec 5>&1
output=$(yarn --cwd feature-libs/asm run test:schematics --coverage=true | tee /dev/fd/5)

echo "Running unit tests and code coverage for cart library"
exec 5>&1
output=$(ng test cart --sourceMap --watch=false --code-coverage --browsers=ChromeHeadless | tee /dev/fd/5)
coverage=$(echo $output | grep -i "does not meet global threshold" || true)
if [[ -n "$coverage" ]]; then
echo "Error: Tests did not meet coverage expectations"
exit 1
fi
echo "Running schematics unit tests and code coverage for cart library"
exec 5>&1
output=$(yarn --cwd feature-libs/cart run test:schematics --coverage=true | tee /dev/fd/5)

echo "Running unit tests and code coverage for setup"
exec 5>&1
output=$(ng test setup --sourceMap --watch=false --code-coverage --browsers=ChromeHeadless | tee /dev/fd/5)
Expand Down
20 changes: 10 additions & 10 deletions feature-libs/asm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@
"name": "@spartacus/asm",
"version": "3.2.0-next.2",
"description": "ASM feature library for Spartacus",
"homepage": "https://github.com/SAP/spartacus",
"keywords": [
"spartacus",
"framework",
"storefront",
"asm"
],
"homepage": "https://github.com/SAP/spartacus",
"repository": "https://github.com/SAP/spartacus/tree/develop/feature-libs/asm",
"license": "Apache-2.0",
"scripts": {
"clean:schematics": "../../node_modules/.bin/rimraf \"schematics/**/*.js\" \"schematics/**/*.js.map\" \"schematics/**/*.d.ts\"",
"build:schematics": "yarn clean:schematics && ../../node_modules/.bin/tsc -p ./tsconfig.schematics.json",
"test:schematics": "yarn --cwd ../../projects/schematics/ run clean && yarn clean:schematics && ../../node_modules/.bin/jest --config ./jest.schematics.config.js"
},
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
"dependencies": {
"tslib": "^2.0.0"
},
"repository": "https://github.com/SAP/spartacus/tree/develop/feature-libs/asm",
"peerDependencies": {
"@angular-devkit/schematics": "^10.2.1",
"@angular/common": "^10.2.4",
"@angular/core": "^10.2.4",
"@angular/forms": "^10.2.4",
"@angular-devkit/schematics": "^10.2.1",
"rxjs": "^6.6.0",
"@ngrx/effects": "^10.0.0",
"@ngrx/store": "^10.0.0",
"@schematics/angular": "10.2.1",
"@spartacus/core": "3.2.0-next.2",
"@spartacus/schematics": "3.2.0-next.2",
"@spartacus/storefront": "3.2.0-next.2",
"@spartacus/schematics": "3.2.0-next.2"
"rxjs": "^6.6.0"
},
"dependencies": {
"tslib": "^2.0.0"
"publishConfig": {
"access": "public"
}
}
4 changes: 4 additions & 0 deletions feature-libs/cart/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../.eslintrc.json",
"ignorePatterns": ["schematics/**/*.d.ts"]
}
36 changes: 36 additions & 0 deletions feature-libs/cart/.release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"git": {
"requireCleanWorkingDir": true,
"requireUpstream": false,
"tagName": "cart-${version}",
"commitMessage": "Bumping cart version to ${version}",
"tagAnnotation": "Bumping cart version to ${version}"
},
"npm": {
"publishPath": "./../../dist/cart"
},
"hooks": {
"after:version:bump": "cd ../.. && yarn build:cart"
},
"github": {
"release": true,
"assets": ["../../docs.tar.gz", "../../docs.zip"],
"releaseName": "@spartacus/cart@${version}",
"releaseNotes": "ts-node ../../scripts/changelog.ts --verbose --lib cart --to cart-${version}"
},
"plugins": {
"../../scripts/release-it/bumper.js": {
"out": [
{
"file": "package.json",
"path": [
"peerDependencies.@spartacus/core",
"peerDependencies.@spartacus/storefront",
"peerDependencies.@spartacus/schematics",
"peerDependencies.@spartacus/styles"
]
}
]
}
}
}
11 changes: 11 additions & 0 deletions feature-libs/cart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Spartacus Cart

`@spartacus/cart` is a package that you can include in your application, which allows you to use various cart features.

Cart can be added to the existing Spartacus application by running `ng add @spartacus/cart`. For more information about Spartacus schematics, visit the [official Spartacus schematics documentation page](https://sap.github.io/spartacus-docs/schematics/).

The Spartacus Cart library contains the following packages:

- `@spartacus/cart/saved-cart` is a package that adds the saved cart feature.

For more information about Spartacus, see [Spartacus](https://github.com/SAP/spartacus).
7 changes: 7 additions & 0 deletions feature-libs/cart/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import '~@spartacus/styles';

@import '~bootstrap/scss/functions';
@import '~bootstrap/scss/variables';
@import '~bootstrap/scss/_mixins';

@import './saved-cart/index';
29 changes: 29 additions & 0 deletions feature-libs/cart/jest.schematics.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig.schematics');

module.exports = {
setupFilesAfterEnv: ['<rootDir>/jest.ts'],
transform: {
'^.+\\.ts?$': 'ts-jest',
},

collectCoverage: false,
coverageReporters: ['json', 'lcov', 'text', 'clover'],
coverageDirectory: '<rootDir>/../../coverage/cart/schematics',
coverageThreshold: {
global: {
branches: 70,
functions: 80,
lines: 80,
statements: 80,
},
},

roots: ['<rootDir>/schematics'],
modulePaths: ['<rootDir>/../../projects/schematics'],
testMatch: ['**/+(*_)+(spec).+(ts)'],
moduleFileExtensions: ['js', 'ts', 'json'],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths || {}, {
prefix: '<rootDir>/',
}),
};
24 changes: 24 additions & 0 deletions feature-libs/cart/jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// uncomment when we switch the whole lib to jest
/*
Object.defineProperty(window, 'CSS', { value: null });
Object.defineProperty(window, 'getComputedStyle', {
value: () => {
return {
display: 'none',
appearance: ['-webkit-appearance'],
};
},
});
Object.defineProperty(document, 'doctype', {
value: '<!DOCTYPE html>',
});
Object.defineProperty(document.body.style, 'transform', {
value: () => {
return {
enumerable: true,
configurable: true,
};
},
});
*/
40 changes: 40 additions & 0 deletions feature-libs/cart/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-coverage'),
require('karma-junit-reporter'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
reporters: ['progress', 'kjhtml', 'coverage-istanbul', 'dots'],
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage/cart'),
reports: ['lcov', 'cobertura', 'text-summary'],
fixWebpackSourcePaths: true,
thresholds: {
statements: 80,
lines: 80,
branches: 70,
functions: 80,
},
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};
13 changes: 13 additions & 0 deletions feature-libs/cart/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/cart",
"lib": {
"entryFile": "./public_api.ts",
"umdModuleIds": {
"@spartacus/core": "core",
"@spartacus/storefront": "storefront",
"rxjs": "rxjs"
}
},
"assets": ["**/*.scss", "schematics/**/*.json", "schematics/**/*.js"]
}
46 changes: 46 additions & 0 deletions feature-libs/cart/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@spartacus/cart",
"version": "3.2.0-next.2",
"description": "",
"keywords": [
"spartacus",
"framework",
"storefront",
"cart",
"shopping",
"shop",
"saved cart"
],
"homepage": "https://github.com/SAP/spartacus",
"repository": "https://github.com/SAP/spartacus/tree/develop/feature-libs/cart",
"license": "Apache-2.0",
"scripts": {
"build:schematics": "yarn clean:schematics && ../../node_modules/.bin/tsc -p ./tsconfig.schematics.json",
"clean:schematics": "../../node_modules/.bin/rimraf \"schematics/**/*.js\" \"schematics/**/*.js.map\" \"schematics/**/*.d.ts\"",
"test:schematics": "yarn --cwd ../../projects/schematics/ run clean && yarn clean:schematics && ../../node_modules/.bin/jest --config ./jest.schematics.config.js"
},
"dependencies": {
"tslib": "^2.0.0"
},
"peerDependencies": {
"@angular-devkit/schematics": "^10.1.0",
"@angular/common": "^10.1.0",
"@angular/core": "^10.1.0",
"@angular/forms": "^10.1.0",
"@angular/router": "^10.1.0",
"@ngrx/effects": "^10.0.0",
"@ngrx/store": "^10.0.0",
"@schematics/angular": "^10.1.0",
"@spartacus/core": "3.2.0-next.2",
"@spartacus/schematics": "3.2.0-next.2",
"@spartacus/storefront": "3.2.0-next.2",
"@spartacus/styles": "3.2.0-next.2",
"bootstrap": "^4.0",
"rxjs": "^6.6.0",
"typescript": "~4.0.2"
},
"publishConfig": {
"access": "public"
},
"schematics": "./schematics/collection.json"
}
5 changes: 5 additions & 0 deletions feature-libs/cart/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
* Public API Surface of cart
*/

export {};
1 change: 1 addition & 0 deletions feature-libs/cart/saved-cart/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './styles/index';
6 changes: 6 additions & 0 deletions feature-libs/cart/saved-cart/assets/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "./public_api.ts"
}
}
1 change: 1 addition & 0 deletions feature-libs/cart/saved-cart/assets/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './translations/translations';
5 changes: 5 additions & 0 deletions feature-libs/cart/saved-cart/assets/translations/en/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { savedCart } from './saved-cart.i18n';

export const en = {
savedCart,
};
Loading

0 comments on commit 7c14d9a

Please sign in to comment.