Verified Commit 92f60fe3 authored by Exbrayat Cédric's avatar Exbrayat Cédric Committed by Raphaël Flores
Browse files

feat: add a configuration to disable the basket

parent 95ec457e
......@@ -131,17 +131,17 @@ or
```sh
./gradlew assemble -Papp=wheatis
```
which is a shortcut for
or
```sh
./gradlew assemble -Papp=wheatis && java -jar path/to/wheatis.jar
./gradlew assemble -Papp=rare-no-basket
```
This will build a standalone jar at `backend/build/libs/`, that you can run with either:
```sh
java -jar backend/build/libs/rare.jar
java -jar backend/build/libs/rare-no-basket.jar
java -jar backend/build/libs/wheatis.jar
java -jar backend/build/libs/data-discovery.jar
```
......
import org.gradle.api.*
import org.gradle.kotlin.dsl.*
private val acceptableValues = setOf("rare", "wheatis", "data-discovery")
private val acceptableValues = setOf("rare", "rare-no-basket", "wheatis", "data-discovery")
val Project.app: String
get() = findProperty("app")
......
......@@ -116,6 +116,57 @@
}
]
},
"rare-no-basket": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.rare.ts"
},
{
"replace": "src/environments/rare-basket.ts",
"with": "src/environments/no-basket.ts"
}
],
"baseHref": "/rare-dev/"
},
"rare-no-basket-production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.rare.prod.ts"
},
{
"replace": "src/environments/rare-basket.ts",
"with": "src/environments/no-basket.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "900kb",
"maximumError": "1.2mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
}
]
},
"wheatis": {
"budgets": [
{
......@@ -264,6 +315,12 @@
"rare-production": {
"browserTarget": "data-discovery-frontend:build:rare-production"
},
"rare-no-basket": {
"browserTarget": "data-discovery-frontend:build:rare-no-basket"
},
"rare-no-basket-production": {
"browserTarget": "data-discovery-frontend:build:rare-no-basket-production"
},
"wheatis": {
"browserTarget": "data-discovery-frontend:build:wheatis"
},
......
......@@ -5,11 +5,13 @@
"ng": "ng",
"start": "ng serve --configuration=rare --port=4000",
"start:rare": "ng serve --configuration=rare --port=4000",
"start:rare-no-basket": "ng serve --configuration=rare-no-basket --port=4000",
"start:wheatis": "ng serve --configuration=wheatis --port=4100",
"start:wheatis-production": "ng serve --configuration=wheatis-production --port=4101",
"start:data-discovery": "ng serve --configuration=data-discovery --port=4200",
"build": "ng build --configuration=rare-production --no-progress",
"build:rare": "ng build --configuration=rare-production --no-progress",
"build:rare-no-basket": "ng build --configuration=rare-no-basket-production --no-progress",
"build:wheatis": "ng build --configuration=wheatis-production --no-progress",
"build:data-discovery": "ng build --configuration=data-discovery-production --no-progress",
"test": "ng test --code-coverage --no-progress --no-watch",
......
......@@ -10,7 +10,7 @@
<span translate="documents.results-limited" [translateParams]="{ total: documents.maxResults | number }"></span>
</ng-container>
</div>
<div class="select-all-rare-basket">
<div class="select-all-rare-basket" *ngIf="isBasketEnabled">
<!-- the following component will not be the same depending on the environment.resourceModule value -->
<!-- for example, if the module is `RareModule` it will be a `RareSelectAllResultsComponent` -->
<!-- For others it will be an empty component -->
......
......@@ -37,7 +37,8 @@ describe('DocumentsComponent', () => {
}
}
const basketService = jasmine.createSpyObj<BasketService>('BasketService', ['isAccessionInBasket']);
const basketService = jasmine.createSpyObj<BasketService>('BasketService', ['isEnabled', 'isAccessionInBasket']);
basketService.isEnabled.and.returnValue(true);
basketService.isAccessionInBasket.and.returnValue(of(false));
beforeEach(() => {
......
......@@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Page } from '../models/page';
import { DocumentModel } from '../models/document.model';
import { BasketService } from '../rare/basket.service';
@Component({
selector: 'dd-documents',
......@@ -12,6 +13,11 @@ import { DocumentModel } from '../models/document.model';
export class DocumentsComponent {
@Input() documents: Page<DocumentModel>;
isBasketEnabled: boolean;
constructor(basketService: BasketService) {
this.isBasketEnabled = basketService.isEnabled();
}
get firstResultIndex() {
return (this.documents.number * this.documents.size) + 1;
......
......@@ -48,6 +48,10 @@ export class BasketService {
this.restoreBasketFromLocalStorage();
}
isEnabled() {
return rareBasket.isBasketEnabled;
}
restoreBasketFromLocalStorage() {
const rareBasketStringified = window.localStorage.getItem('rare-basket');
if (rareBasketStringified) {
......
<div class="basket-counter navbar-text" *ngIf="itemCounter === 0; else navbarButton">
<div class="basket-counter navbar-text" *ngIf="isEnabled && itemCounter === 0">
<span class="fa fa-fw fa-shopping-basket"></span>&ngsp;
<span class="badge badge-pill badge-light">0</span>
</div>
<ng-template #navbarButton>
<button class="basket-counter btn" [ngbTooltip]="buttonTooltip" (click)="viewItems(basketModal)">
<span class="fa fa-fw fa-shopping-basket"></span>&ngsp;
<span class="badge badge-pill badge-light">{{ itemCounter | number }}</span>
</button>
</ng-template>
<button class="basket-counter btn" *ngIf="isEnabled && itemCounter" [ngbTooltip]="buttonTooltip" (click)="viewItems(basketModal)">
<span class="fa fa-fw fa-shopping-basket"></span>&ngsp;
<span class="badge badge-pill badge-light">{{ itemCounter | number }}</span>
</button>
<ng-template #buttonTooltip>
<ng-container [ngPlural]="itemCounter">
......
......@@ -74,7 +74,8 @@ describe('RareBasketComponent', () => {
const basketEvents = new Subject<Basket>();
beforeEach(() => {
service = jasmine.createSpyObj<BasketService>('BasketService', ['getBasket', 'removeFromBasket', 'sendBasket', 'clearBasket']);
service = jasmine.createSpyObj<BasketService>('BasketService', ['isEnabled', 'getBasket', 'removeFromBasket', 'sendBasket', 'clearBasket']);
service.isEnabled.and.returnValue(true);
service.getBasket.and.returnValue(basketEvents);
location = jasmine.createSpyObj<Location>('Location', ['assign']);
TestBed.configureTestingModule({
......@@ -87,7 +88,6 @@ describe('RareBasketComponent', () => {
});
jasmine.addMatchers(speculoosMatchers);
tester = new RareBasketComponentTester();
tester.detectChanges();
});
afterEach(() => {
......@@ -100,6 +100,7 @@ describe('RareBasketComponent', () => {
});
it('should display the number of items', () => {
tester.detectChanges();
// no item
expect(tester.basketCounterAsText).toContainText('0');
......@@ -139,6 +140,7 @@ describe('RareBasketComponent', () => {
});
it('should open a summary modal on click', () => {
tester.detectChanges();
basketEvents.next({ items: [{ accession: { identifier: 'rosa', name: 'Rosa' } } as BasketItem] });
tester.detectChanges();
tester.basketCounter.click();
......@@ -159,6 +161,7 @@ describe('RareBasketComponent', () => {
});
it('should send the basket', fakeAsync(() => {
tester.detectChanges();
const reference = 'ABCDEFGH';
service.sendBasket.and.returnValue(
of({
......@@ -187,6 +190,7 @@ describe('RareBasketComponent', () => {
}));
it('should clear the basket', () => {
tester.detectChanges();
basketEvents.next({ items: [{ accession: { identifier: 'rosa', name: 'Rosa' } } as BasketItem] });
tester.detectChanges();
tester.basketCounter.click();
......@@ -194,4 +198,11 @@ describe('RareBasketComponent', () => {
tester.clearBasket.click();
expect(service.clearBasket).toHaveBeenCalled();
});
it('should not display if the basket feature is disabled', () => {
service.isEnabled.and.returnValue(false);
tester.detectChanges();
expect(tester.basketCounter).toBeNull();
expect(tester.basketCounterAsText).toBeNull();
});
});
......@@ -21,6 +21,7 @@ export class RareBasketComponent implements OnInit {
eulaAgreementControl: FormControl;
submitted = false;
confirmForbidden = false;
isEnabled: boolean;
constructor(
private basketService: BasketService,
......@@ -30,11 +31,14 @@ export class RareBasketComponent implements OnInit {
) {}
ngOnInit(): void {
this.basketService.getBasket().subscribe((basket: Basket) => {
this.itemCounter = basket.items.length;
this.basket = basket;
});
this.eulaAgreementControl = this.fb.control(false, Validators.requiredTrue);
this.isEnabled = this.basketService.isEnabled();
if (this.isEnabled) {
this.basketService.getBasket().subscribe((basket: Basket) => {
this.itemCounter = basket.items.length;
this.basket = basket;
});
this.eulaAgreementControl = this.fb.control(false, Validators.requiredTrue);
}
}
viewItems(basket: any) {
......
......@@ -6,7 +6,7 @@
</a>
<small> - {{ document.pillarName }}</small>&ngsp;
</div>
<div *ngIf="document.accessionHolder">
<div *ngIf="isBasketEnabled && document.accessionHolder">
<button
*ngIf="!selectedForOrdering"
type="button"
......
......@@ -64,16 +64,19 @@ describe('RareDocumentComponent', () => {
}
}
const basketService = jasmine.createSpyObj<BasketService>('BasketService', ['isAccessionInBasket', 'addToBasket', 'removeFromBasket']);
let basketService: jasmine.SpyObj<BasketService>;
const basketEvents = new Subject<boolean>();
basketService.isAccessionInBasket.and.returnValue(basketEvents);
beforeEach(() =>
beforeEach(() => {
basketService = jasmine.createSpyObj<BasketService>('BasketService', ['isEnabled', 'isAccessionInBasket', 'addToBasket', 'removeFromBasket']);
basketService.isEnabled.and.returnValue(true);
basketService.isAccessionInBasket.and.returnValue(basketEvents);
TestBed.configureTestingModule({
imports: [NgbTooltipModule, I18nTestingModule],
declarations: [RareDocumentComponent, TruncatableDescriptionComponent],
providers: [{ provide: BasketService, useValue: basketService }]
})
});
}
);
beforeEach(() => jasmine.addMatchers(speculoosMatchers));
......@@ -134,6 +137,18 @@ describe('RareDocumentComponent', () => {
expect(tester.type).toContainText('type1, type2');
});
it('should not have the basket button if the feature is disabled', () => {
basketService.isEnabled.and.returnValue(false);
const tester = new RareDocumentComponentTester();
const component = tester.componentInstance;
// given a resource with several types
component.document = toRareDocument('Bacteria');
tester.detectChanges();
// then the button should not be displayed
expect(tester.addToBasketButton).toBeNull();
});
it('should add/remove to/from basket', () => {
const tester = new RareDocumentComponentTester();
const component = tester.componentInstance;
......
......@@ -11,14 +11,18 @@ import { BasketService } from '../basket.service';
export class RareDocumentComponent implements OnInit {
selectedForOrdering = false;
@Input() document: RareDocumentModel;
isBasketEnabled: boolean;
constructor(private changeDetectorRef: ChangeDetectorRef, private basketService: BasketService) {}
ngOnInit(): void {
this.basketService.isAccessionInBasket(this.document).subscribe(isInBasket => {
this.selectedForOrdering = isInBasket;
this.changeDetectorRef.markForCheck();
});
this.isBasketEnabled = this.basketService.isEnabled();
if (this.isBasketEnabled) {
this.basketService.isAccessionInBasket(this.document).subscribe(isInBasket => {
this.selectedForOrdering = isInBasket;
this.changeDetectorRef.markForCheck();
});
}
}
addToBasket() {
......
......@@ -55,7 +55,8 @@ class SearchComponentTester extends ComponentTester<SearchComponent> {
}
describe('SearchComponent', () => {
const basketService = jasmine.createSpyObj<BasketService>('BasketService', ['isAccessionInBasket']);
const basketService = jasmine.createSpyObj<BasketService>('BasketService', ['isEnabled', 'isAccessionInBasket']);
basketService.isEnabled.and.returnValue(true);
basketService.isAccessionInBasket.and.returnValue(of(false));
beforeEach(() => TestBed.configureTestingModule({
imports: [
......
/**
* Configuration variables to disable RARe Basket.
* This file is only used by the RARe-no-basket version of the application.
* You NEVER have to import this version of the file:
* the build takes care of replacing it when needed.
*/
export const rareBasket = {
isBasketEnabled: false,
url: 'http://localhost:4201/rare-basket'
};
......@@ -6,5 +6,6 @@
* See angular.json for more details.
*/
export const rareBasket = {
isBasketEnabled: true,
url: 'http://localhost:4201/rare-basket' // TODO update to proper URL
};
......@@ -7,5 +7,6 @@
* the build takes care of replacing it by the production one.
*/
export const rareBasket = {
isBasketEnabled: true,
url: 'http://localhost:4201/rare-basket'
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment