Skip to content

Commit

Permalink
Merge pull request #3437 from ita-social-projects/refactor/rename-habits
Browse files Browse the repository at this point in the history
[Refactor] Rename in habit components
  • Loading branch information
Tadei-Mykola authored Nov 8, 2024
2 parents 5a715cb + 09da20c commit 5d076f8
Show file tree
Hide file tree
Showing 55 changed files with 603 additions and 605 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('AddCommentComponent', () => {
rating: null,
showEcoPlace: true,
showLocation: true,
showShoppingList: true,
showToDoList: true,
socialNetworks: [{ id: 1, url: defaultImagePath }]
} as EditProfileModel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ <h3 class="label">{{ 'user.habit.add-new-habit.textarea-title' | translate }}</h
<app-habit-progress [habit]="habit" class="progress-container"></app-habit-progress>
</div>
<div class="habit-second-block">
<div class="duration-shoping">
<div class="duration-to-do">
<div class="duration">
<app-habit-duration
[habitDurationInitial]="initialDuration"
(changeDuration)="durationControl.setValue($event)"
></app-habit-duration>
</div>
<div class="shopping">
<app-habit-edit-shopping-list (newList)="getShopList($event)" [shopList]="shopList"></app-habit-edit-shopping-list>
<div class="to-do">
<app-habit-edit-to-do-list (newList)="getToDoList($event)" [toDoList]="toDoList"></app-habit-edit-to-do-list>
</div>
</div>
<div class="invite-friends">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@
}
}

.duration-shoping {
.duration-to-do {
display: flex;
width: 100%;
justify-content: space-between;
gap: 32px;

.duration,
.shopping {
.to-do {
width: calc(50% - 16px);
background: var(--secondary-light-grey);
border-radius: 8px;
Expand Down Expand Up @@ -352,13 +352,13 @@ input[type='radio'] + img {
padding: 0;
gap: 24px;

.duration-shoping {
.duration-to-do {
flex-direction: column;
height: auto;
gap: 24px;

.duration,
.shopping {
.to-do {
width: 100%;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { HabitAssignService } from '@global-service/habit-assign/habit-assign.se
import { HabitService } from '@global-service/habit/habit.service';
import { LocalStorageService } from '@global-service/localstorage/local-storage.service';
import { HabitDurationComponent } from '@global-user/components/habit/add-new-habit/habit-duration/habit-duration.component';
import { HabitEditShoppingListComponent } from '@global-user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component';
import { HabitEditToDoListComponent } from '@global-user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component';
import { HabitInviteFriendsComponent } from '@global-user/components/habit/add-new-habit/habit-invite-friends/habit-invite-friends.component';
import { HabitProgressComponent } from '@global-user/components/habit/add-new-habit/habit-progress/habit-progress.component';
import { CalendarWeekComponent } from '@global-user/components/profile/calendar/calendar-week/calendar-week.component';
import { ShoppingList } from '@global-user/models/shoppinglist.interface';
import { ToDoList } from '@global-user/models/to-do-list.interface';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { provideMockStore } from '@ngrx/store/testing';
import { TranslateModule } from '@ngx-translate/core';
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('AddEditCustomHabitComponent', () => {
HabitDurationComponent,
CalendarWeekComponent,
CalendarComponent,
HabitEditShoppingListComponent,
HabitEditToDoListComponent,
HabitInviteFriendsComponent,
HabitProgressComponent,
SelectImagesComponent,
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('AddEditCustomHabitComponent', () => {
});

it('should call changeCustomHabit() and goToAllHabits() on success', () => {
const habitFormValue = { title: 'Title', description: 'Description', complexity: 1, duration: 7, tagIds: [1], image: '', shopList: [] };
const habitFormValue = { title: 'Title', description: 'Description', complexity: 1, duration: 7, tagIds: [1], image: '', toDoList: [] };
component.habitForm.setValue(habitFormValue);
habitServiceMock.changeCustomHabit = jasmine.createSpy('changeCustomHabit').and.returnValue(of(null));
spyOn(component, 'goToAllHabits');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ImageResize from 'quill-image-resize-module';
import { HabitService } from '@global-service/habit/habit.service';
import { TagInterface } from '@shared/components/tag-filter/tag-filter.model';
import { quillConfig } from '../../../../events/components/event-editor/quillEditorFunc';
import { ShoppingList } from '@global-user/models/shoppinglist.interface';
import { ToDoList } from '@global-user/models/to-do-list.interface';
import { FileHandle } from '@eco-news-models/create-news-interface';
import { UserFriendsService } from '@global-user/services/user-friends.service';
import { TodoStatus } from '../models/todo-status.enum';
Expand All @@ -35,8 +35,8 @@ export class AddEditCustomHabitComponent extends FormBaseComponent implements On
habitImages = HABIT_IMAGES;
stars = STAR_IMAGES;
initialDuration = HABIT_DEFAULT_DURATION;
shopList: ShoppingList[] = [];
newList: ShoppingList[] = [];
toDoList: ToDoList[] = [];
newList: ToDoList[] = [];
tagsList: TagInterface[];
tagMaxLength = HABIT_TAGS_MAXLENGTH;
selectedTagsList: number[];
Expand Down Expand Up @@ -151,13 +151,13 @@ export class AddEditCustomHabitComponent extends FormBaseComponent implements On
return value <= complexity ? this.stars.GREEN : this.stars.WHITE;
}

getShopList(list: ShoppingList[]): void {
getToDoList(list: ToDoList[]): void {
this.newList = list.map((item) => ({
id: item.id,
status: item.status,
text: item.text
}));
this.habitForm.get('shopList').setValue(this.newList);
this.habitForm.get('toDoList').setValue(this.newList);
}

getTagsList(list: TagInterface[]): void {
Expand Down Expand Up @@ -217,7 +217,7 @@ export class AddEditCustomHabitComponent extends FormBaseComponent implements On
duration: new FormControl(this.initialDuration, [Validators.required, Validators.min(7), Validators.max(56)]),
tagIds: new FormControl([], Validators.required),
image: new FormControl(''),
shopList: new FormControl([])
toDoList: new FormControl([])
});
}

Expand All @@ -230,13 +230,13 @@ export class AddEditCustomHabitComponent extends FormBaseComponent implements On
duration: this.habit.defaultDuration,
tagIds: this.habit.tags,
image: this.habit.image,
shopList: this.habit.customShoppingListItems
toDoList: this.habit.customToDoListItems
});
this.habitId = this.habit.id;
this.shopList = this.habit.customShoppingListItems?.length
? [...(this.habit.customShoppingListItems || [])]
: [...(this.habit.customShoppingListItems || []), ...this.habit.shoppingListItems];
this.shopList = this.shopList.map((el) => ({ ...el, selected: el.status === TodoStatus.inprogress }));
this.toDoList = this.habit.customToDoListItems?.length
? [...(this.habit.customToDoListItems || [])]
: [...(this.habit.customToDoListItems || []), ...this.habit.ToDoListItems];
this.toDoList = this.toDoList.map((el) => ({ ...el, selected: el.status === TodoStatus.inprogress }));
}

private subscribeToLangChange(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h3>{{ 'user.habit.info' | translate }}</h3>
></app-habit-progress>
</div>
<div class="habit-second-block">
<div class="duration-shoping">
<div class="duration-to-do">
<div class="duration">
<app-habit-duration
*ngIf="initialDuration"
Expand All @@ -58,13 +58,13 @@ <h3>{{ 'user.habit.info' | translate }}</h3>
<input type="checkbox" [checked]="isPrivate" (change)="onChange()" /><span class="slider"></span>
</label>
</div>
<div class="shopping">
<app-habit-edit-shopping-list
*ngIf="initialShoppingList"
<div class="to-do">
<app-habit-edit-to-do-list
*ngIf="initialToDoList"
(newList)="getList($event)"
[shopList]="initialShoppingList"
[toDoList]="initialToDoList"
[isAcquired]="isAcquired"
></app-habit-edit-shopping-list>
></app-habit-edit-to-do-list>
</div>
</div>
<div class="invite-friends">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@
}
}

.duration-shoping {
.duration-to-do {
display: flex;
width: 100%;
justify-content: space-between;
gap: 32px;

.duration,
.shopping {
.to-do {
width: calc(50% - 16px);
background: var(--secondary-light-grey);
border-radius: 8px;
Expand Down Expand Up @@ -402,13 +402,13 @@
padding: 0;
gap: 24px;

.duration-shoping {
.duration-to-do {
flex-direction: column;
height: auto;
gap: 24px;

.duration,
.shopping {
.to-do {
width: 100%;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AddNewHabitComponent } from './add-new-habit.component';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { LocalStorageService } from '@global-service/localstorage/local-storage.service';
import { ShoppingListService } from './habit-edit-shopping-list/shopping-list.service';
import { ToDoListService } from './habit-edit-to-do-list/to-do-list.service';
import { HabitService } from '@global-service/habit/habit.service';
import { HabitAssignService } from '@global-service/habit-assign/habit-assign.service';
import { of, Subject } from 'rxjs';
Expand Down Expand Up @@ -80,14 +80,14 @@ describe('AddNewHabitComponent', () => {

const matSnackBarMock: MatSnackBarComponent = jasmine.createSpyObj('MatSnackBarComponent', ['openSnackBar']);

const fakeShoppingListService: ShoppingListService = jasmine.createSpyObj('fakeShoppingListService', [
'getHabitAllShopLists',
'getHabitShopList',
'updateHabitShopList'
const fakeToDoListService: ToDoListService = jasmine.createSpyObj('fakeToDoListService', [
'getHabitAllToDoLists',
'getHabitToDoList',
'updateHabitToDoList'
]);
fakeShoppingListService.getHabitAllShopLists = () => of();
fakeShoppingListService.getHabitShopList = () => of();
fakeShoppingListService.updateHabitShopList = () => of();
fakeToDoListService.getHabitAllToDoLists = () => of();
fakeToDoListService.getHabitToDoList = () => of();
fakeToDoListService.updateHabitToDoList = () => of();

matSnackBarMock.openSnackBar = (type: string) => type;

Expand Down Expand Up @@ -115,7 +115,7 @@ describe('AddNewHabitComponent', () => {
{ provide: HabitService, useValue: fakeHabitService },
{ provide: HabitAssignService, useValue: fakeHabitAssignService },
{ provide: EcoNewsService, useValue: ecoNewsServiceMock },
{ provide: ShoppingListService, useValue: fakeShoppingListService },
{ provide: ToDoListService, useValue: fakeToDoListService },
{ provide: LocalStorageService, useValue: fakeLocalStorageService },
{ provide: ActivatedRoute, useValue: mockActivatedRoute },
{ provide: Location, useValue: locationMock },
Expand Down Expand Up @@ -144,8 +144,8 @@ describe('AddNewHabitComponent', () => {
it('should navigate back on onGoBack without call dialog', () => {
component.initialDuration = 1;
component.newDuration = 1;
component.standardShopList = null;
component.customShopList = null;
component.standardToDoList = null;
component.customToDoList = null;
const spy = spyOn(locationMock, 'back');
component.onGoBack();
expect(spy).toHaveBeenCalled();
Expand All @@ -169,22 +169,22 @@ describe('AddNewHabitComponent', () => {
expect(component.canAcquire).toBeTruthy();
});

it('should set standardShopList', () => {
component.getList(DEFAULTFULLINFOHABIT.shoppingListItems);
expect(component.standardShopList).toEqual([{ id: 6, status: TodoStatus.active, text: 'TEST' }]);
expect(component.customShopList).toEqual([]);
it('should set standardToDoList', () => {
component.getList(DEFAULTFULLINFOHABIT.toDoListItems);
expect(component.standardToDoList).toEqual([{ id: 6, status: TodoStatus.active, text: 'TEST' }]);
expect(component.customToDoList).toEqual([]);
});

it('should set and customShopList', () => {
component.getList(CUSTOMFULLINFOHABIT.shoppingListItems);
expect(component.customShopList).toEqual([{ id: 6, status: TodoStatus.active, text: 'TEST', custom: true }]);
expect(component.standardShopList).toEqual([]);
it('should set and customToDoList', () => {
component.getList(CUSTOMFULLINFOHABIT.toDoListItems);
expect(component.customToDoList).toEqual([{ id: 6, status: TodoStatus.active, text: 'TEST', custom: true }]);
expect(component.standardToDoList).toEqual([]);
});

it('should set standardShopList and customShopList', () => {
const shoppingListItems = DEFAULTFULLINFOHABIT.shoppingListItems.concat(CUSTOMFULLINFOHABIT.shoppingListItems);
component.getList(shoppingListItems);
expect(component.customShopList).toEqual(shoppingListItems.filter((item) => item.custom));
expect(component.standardShopList).toEqual(shoppingListItems.filter((item) => !item.custom));
it('should set standardToDoList and customToDoList', () => {
const toDoListItems = DEFAULTFULLINFOHABIT.toDoListItems.concat(CUSTOMFULLINFOHABIT.toDoListItems);
component.getList(toDoListItems);
expect(component.customToDoList).toEqual(toDoListItems.filter((item) => item.custom));
expect(component.standardToDoList).toEqual(toDoListItems.filter((item) => !item.custom));
});
});
Loading

0 comments on commit 5d076f8

Please sign in to comment.