Skip to content

[Fix] tariffs undefined values #3645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
import { Location } from '@angular/common';
import { UbsAdminTariffsPricingPageComponent } from './ubs-admin-tariffs-pricing-page.component';
import { MatDialog, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
Expand Down Expand Up @@ -118,12 +118,16 @@ describe('UbsAdminPricingPageComponent', () => {
descriptionEng: 'fake1'
};

const fakeBag: Bag = {
capacity: 111,
price: 478,
commission: 15,
const fakeBag = {
id: 1,
limitIncluded: false,
id: 1
capacity: 20,
price: 100,
commission: 10,
name: 'Назва',
nameEng: 'Name',
description: 'Опис',
descriptionEng: 'Description'
};
const fakeDescription = {
limitDescription: 'fake'
Expand Down Expand Up @@ -536,12 +540,30 @@ describe('UbsAdminPricingPageComponent', () => {
});
});

it('should get all tariffs for service', () => {
it('should get all tariffs for service', fakeAsync(() => {
component.bags = [];
const fakeResponse = [
{
id: 1,
limitIncluded: false,
capacity: 20,
price: 100,
commission: 10,
name: 'Назва',
nameEng: 'Name',
description: 'Опис',
descriptionEng: 'Description'
}
];
component.selectedCardId = 1;
tariffsServiceMock.getAllTariffsForService.and.returnValue(of(fakeResponse));

component.getAllTariffsForService();
tick();

expect(component.isLoadBar).toEqual(false);
expect(component.bags).toEqual([fakeBag]);
});
}));

it('should get all services', () => {
component.getService();
Expand All @@ -556,12 +578,21 @@ describe('UbsAdminPricingPageComponent', () => {
expect(component.couriers).toEqual([fakeCouriers]);
});

it('onCheck should set limitIncluded to true of checked is true', () => {
it('onCheck should set limitIncluded to true if checked is true', () => {
const fakeBag: Bag = {
id: 1,
limitIncluded: false,
capacity: 20,
price: 100,
commission: 10
};
component.bags = [fakeBag];

const fakeEvent = {
checked: true
};
component.onChecked(fakeBag.id, fakeEvent);
expect(fakeBag.limitIncluded).toEqual(true);
expect(component.bags[0].limitIncluded).toEqual(true);
});

it('onCheck should set limitIncluded to false of checked is false', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,14 @@ export class UbsAdminTariffsPricingPageComponent implements OnInit, OnDestroy {
this.areAllCheckBoxEmpty = !filteredCheckBoxes.length;
}

onChecked(id, event): void {
onChecked(id: number, event: any): void {
this.limitsForm.markAsDirty();

const currentBag = this.bags.find((bag) => bag.id === id);
if (!currentBag) {
return;
}

currentBag.limitIncluded = event.checked;
this.unClickSaveBTN(event);
this.limitsForm.markAsDirty();
Expand Down Expand Up @@ -350,14 +355,24 @@ export class UbsAdminTariffsPricingPageComponent implements OnInit, OnDestroy {
});
}

transformBag(bag: any): Bag {
return {
...bag,
name: bag.nameUk || bag.name,
nameEng: bag.nameEn || bag.nameEng,
description: bag.descriptionUk || bag.description,
descriptionEng: bag.descriptionEn || bag.descriptionEng
};
}

getAllTariffsForService(): void {
const tariffId = this.selectedCardId;
this.isLoadBar = true;
this.tariffsService
.getAllTariffsForService(tariffId)
.pipe(takeUntil(this.destroy))
.subscribe((res: Bag[]) => {
this.bags = res;
this.bags = res.map((bag) => this.transformBag(bag));
this.filterBags();
this.isLoadBar = false;
});
Expand Down
Loading