diff --git a/src/app/main/component/eco-news/components/news-list/news-list.component.spec.ts b/src/app/main/component/eco-news/components/news-list/news-list.component.spec.ts index 1ad3829980..c8818f6255 100644 --- a/src/app/main/component/eco-news/components/news-list/news-list.component.spec.ts +++ b/src/app/main/component/eco-news/components/news-list/news-list.component.spec.ts @@ -25,11 +25,7 @@ describe('NewsListComponent', () => { let component: NewsListComponent; let fixture: ComponentFixture; - const ecoNewsServiceMock: EcoNewsService = jasmine.createSpyObj('EcoNewsService', [ - 'getAllPresentTags', - 'getNewsListByTags', - 'getEcoNewsListByPage' - ]); + const ecoNewsServiceMock: EcoNewsService = jasmine.createSpyObj('EcoNewsService', ['getAllPresentTags', 'getEcoNewsListByPage']); ecoNewsServiceMock.getEcoNewsListByPage = () => new Observable(); diff --git a/src/app/main/component/eco-news/components/news-list/news-list.component.ts b/src/app/main/component/eco-news/components/news-list/news-list.component.ts index e95ed22857..b1111b3b0d 100644 --- a/src/app/main/component/eco-news/components/news-list/news-list.component.ts +++ b/src/app/main/component/eco-news/components/news-list/news-list.component.ts @@ -1,7 +1,7 @@ import { Breakpoints } from '../../../../config/breakpoints.constants'; import { Component, OnInit, OnDestroy } from '@angular/core'; -import { ReplaySubject } from 'rxjs'; -import { take, takeUntil } from 'rxjs/operators'; +import { Observable, of, ReplaySubject } from 'rxjs'; +import { map, take, takeUntil } from 'rxjs/operators'; import { EcoNewsModel } from '@eco-news-models/eco-news-model'; import { FilterModel } from '@shared/components/tag-filter/tag-filter.model'; import { UserOwnAuthService } from '@auth-service/user-own-auth.service'; @@ -133,24 +133,25 @@ export class NewsListComponent implements OnInit, OnDestroy { this.isSearchVisible = !this.isSearchVisible; } + private checkAuthentication(): Observable { + if (!this.userId) { + this.openAuthModalWindow('sign-in'); + return this.dialogRef.afterClosed().pipe( + take(1), + map((result) => !!result) + ); + } + return of(true); + } + changeFavoriteStatus(event: Event, data: EcoNewsModel) { event.preventDefault(); event.stopPropagation(); - let isRegistered = !!this.userId; + this.checkAuthentication(); - if (!isRegistered) { - this.openAuthModalWindow('sign-in'); - this.dialogRef - .afterClosed() - .pipe(take(1)) - .subscribe((result) => { - isRegistered = !!result; - }); - } else { - const action = ChangeEcoNewsFavoriteStatusAction({ id: data.id, favorite: !data.favorite, isFavoritesPage: this.bookmarkSelected }); - this.store.dispatch(action); - } + const action = ChangeEcoNewsFavoriteStatusAction({ id: data.id, favorite: !data.favorite, isFavoritesPage: this.bookmarkSelected }); + this.store.dispatch(action); } openAuthModalWindow(page: string): void { @@ -165,20 +166,9 @@ export class NewsListComponent implements OnInit, OnDestroy { } showSelectedNews(): void { - let isRegistered = !!this.userId; - - if (!isRegistered) { - this.openAuthModalWindow('sign-in'); - this.dialogRef - .afterClosed() - .pipe(take(1)) - .subscribe((result) => { - isRegistered = !!result; - }); - } else { - this.bookmarkSelected = !this.bookmarkSelected; - this.dispatchStore(true); - } + this.checkAuthentication(); + this.bookmarkSelected = !this.bookmarkSelected; + this.dispatchStore(true); } dispatchStore(res: boolean): void { @@ -189,13 +179,11 @@ export class NewsListComponent implements OnInit, OnDestroy { this.noNewsMatch = false; this.newsTotal = 0; } - console.log('in2'); if (!this.hasNext || this.loading) { console.log(this.hasNext, this.loading); return; } - console.log('in3'); this.loading = true; const params = this.ecoNewsService.getNewsHttpParams({ diff --git a/src/app/main/component/eco-news/services/eco-news.service.spec.ts b/src/app/main/component/eco-news/services/eco-news.service.spec.ts index cc409fdbb3..9bbafa3da6 100644 --- a/src/app/main/component/eco-news/services/eco-news.service.spec.ts +++ b/src/app/main/component/eco-news/services/eco-news.service.spec.ts @@ -63,17 +63,6 @@ describe('EcoNewsService', () => { req.flush(newsDtoMock); }); - it('should return news list', () => { - const arr = [newsMock]; - service.getNewsList().subscribe((data) => { - expect(data).toBe(arr); - }); - - const req = httpTestingController.expectOne(`${environment.backendLink}eco-news`); - expect(req.request.method).toEqual('GET'); - req.flush(arr); - }); - it('should return news list by id', () => { service.getEcoNewsById(13578).subscribe((data) => { expect(data).toBeDefined(); diff --git a/src/app/main/component/eco-news/services/eco-news.service.ts b/src/app/main/component/eco-news/services/eco-news.service.ts index 9b56a2c874..694256c363 100644 --- a/src/app/main/component/eco-news/services/eco-news.service.ts +++ b/src/app/main/component/eco-news/services/eco-news.service.ts @@ -34,19 +34,6 @@ export class EcoNewsService implements OnDestroy { return this.http.get(`${this.backEnd}eco-news?author-id=${authorId}&page=${page}&size=${quantity}`); } - getNewsList(): Observable { - const headers = new HttpHeaders(); - headers.set('Content-type', 'application/json'); - return new Observable((observer: Observer) => { - this.http - .get(`${this.backEnd}eco-news`) - .pipe(take(1)) - .subscribe((newsDto: EcoNewsDto) => { - observer.next(newsDto); - }); - }); - } - getEcoNewsById(id: number): Observable { return this.http.get(`${this.backEnd}eco-news/${id}?lang=${this.language}`); } @@ -86,7 +73,6 @@ export class EcoNewsService implements OnDestroy { }): HttpParams { let params = new HttpParams().set('page', parameters.page.toString()).set('size', parameters.size.toString()); - console.log(parameters); const optionalParams = [ parameters.favorite && this.appendIfNotEmpty('user-id', parameters.userId.toString()), !parameters.favorite && this.appendIfNotEmpty('author-id', parameters.authorId ? parameters?.authorId.toString() : null), diff --git a/src/app/main/component/user/components/profile/profile-dashboard/profile-dashboard.component.spec.ts b/src/app/main/component/user/components/profile/profile-dashboard/profile-dashboard.component.spec.ts index b85670685c..a8204ef804 100644 --- a/src/app/main/component/user/components/profile/profile-dashboard/profile-dashboard.component.spec.ts +++ b/src/app/main/component/user/components/profile/profile-dashboard/profile-dashboard.component.spec.ts @@ -10,11 +10,12 @@ import { InfiniteScrollModule } from 'ngx-infinite-scroll'; import { LocalStorageService } from '@global-service/localstorage/local-storage.service'; import { EventsService } from 'src/app/main/component/events/services/events.service'; import { NgxPaginationModule } from 'ngx-pagination'; -import { HttpClient, HttpParams } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations'; import { EventType } from 'src/app/ubs/ubs/services/event-type.enum'; -import { mockEvent, mockFavouriteEvents, mockHabitAssign } from '@assets/mocks/events/mock-events'; +import { mockEvent, mockFavouriteEvents } from '@assets/mocks/events/mock-events'; import { mockHabits } from '@assets/mocks/habit/mock-habit-calendar'; +import { newsMock } from '@assets/mocks/eco-news/mock-news-item'; describe('ProfileDashboardComponent', () => { let component: ProfileDashboardComponent; @@ -33,23 +34,6 @@ describe('ProfileDashboardComponent', () => { LocalStorageServiceMock.setCurrentPage = () => of('previousPage', '/profile'); LocalStorageServiceMock.getCurrentLanguage = () => of('ua'); - const newsMock = { - countComments: 5, - id: 13578, - imagePath: null, - title: '', - text: '', - content: '', - shortInfo: '', - tags: ['News', 'Events'], - tagsEn: ['News'], - tagsUa: ['Новини'], - creationDate: '2021-11-25T22:32:30.555088+02:00', - likes: 0, - source: '', - author: { id: 312, name: 'taqcTestName' } - }; - const storeMock = jasmine.createSpyObj('store', ['select', 'dispatch']); storeMock.select = () => of({ ecoNews: {}, pages: [], pageNumber: 1, error: 'error' }); diff --git a/src/app/main/component/user/components/profile/profile-dashboard/profile-dashboard.component.ts b/src/app/main/component/user/components/profile/profile-dashboard/profile-dashboard.component.ts index 774fbce825..8283ab9cd7 100644 --- a/src/app/main/component/user/components/profile/profile-dashboard/profile-dashboard.component.ts +++ b/src/app/main/component/user/components/profile/profile-dashboard/profile-dashboard.component.ts @@ -48,7 +48,6 @@ export class ProfileDashboardComponent implements OnInit, OnDestroy { eventsList: EventResponse[] = []; eventsPerPage = 6; eventsPage = 1; - favoriteEventsPage = 0; totalEvents = 0; totalNews = 0; tagsList: Array = []; diff --git a/src/assets/mocks/eco-news/mock-news-item.ts b/src/assets/mocks/eco-news/mock-news-item.ts new file mode 100644 index 0000000000..e9fff31356 --- /dev/null +++ b/src/assets/mocks/eco-news/mock-news-item.ts @@ -0,0 +1,16 @@ +export const newsMock = { + countComments: 5, + id: 13578, + imagePath: null, + title: '', + text: '', + content: '', + shortInfo: '', + tags: ['News', 'Events'], + tagsEn: ['News'], + tagsUa: ['Новини'], + creationDate: '2021-11-25T22:32:30.555088+02:00', + likes: 0, + source: '', + author: { id: 312, name: 'taqcTestName' } +};