Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
asliayk committed Sep 23, 2024
1 parent 5e0990e commit 8a1d9b3
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Observable, Subject, debounceTime, distinctUntilChanged, finalize, map, takeUntil } from 'rxjs';
import { faChevronRight } from '@fortawesome/free-solid-svg-icons';

import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { onError } from 'app/shared/util/global.utils';
import { AlertService } from 'app/core/util/alert.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
(delete)="deleteChannel()"
[dialogError]="dialogError$"
>
<fa-icon [icon]="faTimes" />
<fa-icon [icon]="faTrash" />
</button>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ConversationSettingsComponent implements OnInit, OnDestroy {
private dialogErrorSource = new Subject<string>();
dialogError$ = this.dialogErrorSource.asObservable();

readonly faTimes = faTrash;
readonly faTrash = faTrash;

conversationAsChannel: ChannelDTO | undefined;
canLeaveConversation: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
@if (sidebarItem.icon) {
<fa-icon [fixedWidth]="true" [icon]="sidebarItem.icon" />
}
{{ removeChannelPrefix(sidebarItem, sidebarItem.title) }}</span
{{ removeChannelPrefix(sidebarItem.title) }}</span
>
<span>
@if (sidebarItem.rightIcon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class SidebarCardItemComponent {
@Input() sidebarType?: SidebarTypes;
@Input() groupKey?: string;

removeChannelPrefix(item: SidebarCardElement, name: string): string {
removeChannelPrefix(name: string): string {
const prefixes = ['exercise-', 'lecture-', 'exam-'];
const channelTypes = ['exerciseChannels', 'lectureChannels', 'examChannels'];
for (const prefix of prefixes) {
Expand Down
1 change: 0 additions & 1 deletion src/main/webapp/app/shared/sidebar/sidebar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@

.btn-primary {
width: 100%;
box-sizing: border-box;
}

.btn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import { generateExampleChannelDTO } from '../../helpers/conversationExampleMode
import { ChannelService } from 'app/shared/metis/conversations/channel.service';
import { ConversationService } from 'app/shared/metis/conversations/conversation.service';
import { AlertService } from 'app/core/util/alert.service';
import { NgbActiveModal, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { HttpResponse } from '@angular/common/http';
import { By } from '@angular/platform-browser';
import { ChannelsCreateDialogComponent } from 'app/overview/course-conversations/dialogs/channels-create-dialog/channels-create-dialog.component';
import { defaultSecondLayerDialogOptions } from 'app/overview/course-conversations/other/conversation.util';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { NgbCollapseMocksModule } from '../../../../../helpers/mocks/directive/ngbCollapseMocks.module';

Expand Down Expand Up @@ -107,8 +105,7 @@ examples.forEach((exampleChannel) => {
expect(component).toBeTruthy();
expect(getChannelsOfCourseSpy).toHaveBeenCalledWith(course.id);
expect(getChannelsOfCourseSpy).toHaveBeenCalledOnce();
expect(component.noOfChannels).toBe(3);
expect(component.otherChannels).toHaveLength(3);
expect(component.noOfChannels).toBe(6);
expect(fixture.nativeElement.querySelectorAll('jhi-channel-item')).toHaveLength(6);
expect(channelItems).toHaveLength(6);
expect(channelItems[0].channel).toEqual(channelOne);
Expand Down Expand Up @@ -156,46 +153,5 @@ examples.forEach((exampleChannel) => {
expect(component.channelModificationPerformed).toBeTrue();
}));
}

it('should not show create channel button if user is missing the permission', fakeAsync(() => {
canCreateChannel.mockReturnValue(false);
fixture.detectChanges();
expect(fixture.debugElement.nativeElement.querySelector('#createChannel')).toBeFalsy();
}));

if (allowChannelCreation) {
it('should open create channel dialog when button is pressed', fakeAsync(() => {
const modalService = TestBed.inject(NgbModal);
const mockModalRef = {
componentInstance: { course: undefined, initialize: () => {} },
result: Promise.resolve(new ChannelDTO()),
};
const openDialogSpy = jest.spyOn(modalService, 'open').mockReturnValue(mockModalRef as unknown as NgbModalRef);
fixture.detectChanges();

const createChannelButton = fixture.debugElement.nativeElement.querySelector('#createChannel');
createChannelButton.click();
tick(501);
fixture.whenStable().then(() => {
expect(openDialogSpy).toHaveBeenCalledOnce();
expect(openDialogSpy).toHaveBeenCalledWith(ChannelsCreateDialogComponent, defaultSecondLayerDialogOptions);
expect(mockModalRef.componentInstance.course).toEqual(course);
});
}));
} else {
it('should hide create channel button if creation is not allowed', () => {
const createChannelButton = fixture.debugElement.nativeElement.querySelector('#createChannel');
expect(createChannelButton).toBeNull();
});
}

it('should toggle other channels on click', () => {
expect(component.otherChannelsAreCollapsed).toBeTrue();

const otherChannels = fixture.debugElement.nativeElement.querySelector('.other-channels');
otherChannels.click();

expect(component.otherChannelsAreCollapsed).toBeFalse();
});
});
});

0 comments on commit 8a1d9b3

Please sign in to comment.