Merge pull request #58 from Quantum-P3/feature/US-23
Eliminar encuestas
This commit is contained in:
commit
b48360f9aa
|
@ -1,4 +1,4 @@
|
|||
<form *ngIf="encuesta" name="deleteForm" (ngSubmit)="confirmDelete(encuesta.id!)">
|
||||
<form *ngIf="encuesta" name="deleteForm" (ngSubmit)="confirmDelete(encuesta)">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" data-cy="encuestaDeleteDialogHeading" jhiTranslate="entity.delete.title">Confirm delete operation</h4>
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
|||
<jhi-alert-error></jhi-alert-error>
|
||||
|
||||
<p id="jhi-delete-encuesta-heading" jhiTranslate="dataSurveyApp.encuesta.delete.question" [translateValues]="{ id: encuesta.id }">
|
||||
Are you sure you want to delete this Encuesta?
|
||||
Are you sure you want to delete this survey?
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
jest.mock('@ng-bootstrap/ng-bootstrap');
|
||||
|
||||
import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { HttpResponse } from '@angular/common/http';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
import { EncuestaService } from '../service/encuesta.service';
|
||||
|
||||
import { EncuestaDeleteDialogComponent } from './encuesta-delete-dialog.component';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('Encuesta Management Delete Component', () => {
|
||||
let comp: EncuestaDeleteDialogComponent;
|
||||
let fixture: ComponentFixture<EncuestaDeleteDialogComponent>;
|
||||
let service: EncuestaService;
|
||||
let mockActiveModal: NgbActiveModal;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
declarations: [EncuestaDeleteDialogComponent],
|
||||
providers: [NgbActiveModal],
|
||||
})
|
||||
.overrideTemplate(EncuestaDeleteDialogComponent, '')
|
||||
.compileComponents();
|
||||
fixture = TestBed.createComponent(EncuestaDeleteDialogComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = TestBed.inject(EncuestaService);
|
||||
mockActiveModal = TestBed.inject(NgbActiveModal);
|
||||
});
|
||||
|
||||
describe('confirmDelete', () => {
|
||||
it('Should call delete service on confirmDelete', inject(
|
||||
[],
|
||||
fakeAsync(() => {
|
||||
// GIVEN
|
||||
jest.spyOn(service, 'delete').mockReturnValue(of(new HttpResponse({})));
|
||||
|
||||
// WHEN
|
||||
comp.confirmDelete(123);
|
||||
tick();
|
||||
|
||||
// THEN
|
||||
expect(service.delete).toHaveBeenCalledWith(123);
|
||||
expect(mockActiveModal.close).toHaveBeenCalledWith('deleted');
|
||||
})
|
||||
));
|
||||
|
||||
it('Should not call delete service on clear', () => {
|
||||
// GIVEN
|
||||
jest.spyOn(service, 'delete');
|
||||
|
||||
// WHEN
|
||||
comp.cancel();
|
||||
|
||||
// THEN
|
||||
expect(service.delete).not.toHaveBeenCalled();
|
||||
expect(mockActiveModal.close).not.toHaveBeenCalled();
|
||||
expect(mockActiveModal.dismiss).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,5 +1,6 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { EstadoEncuesta } from 'app/entities/enumerations/estado-encuesta.model';
|
||||
|
||||
import { IEncuesta } from '../encuesta.model';
|
||||
import { EncuestaService } from '../service/encuesta.service';
|
||||
|
@ -16,8 +17,9 @@ export class EncuestaDeleteDialogComponent {
|
|||
this.activeModal.dismiss();
|
||||
}
|
||||
|
||||
confirmDelete(id: number): void {
|
||||
this.encuestaService.delete(id).subscribe(() => {
|
||||
confirmDelete(encuesta: IEncuesta): void {
|
||||
encuesta.estado = EstadoEncuesta.DELETED;
|
||||
this.encuestaService.update(encuesta).subscribe(() => {
|
||||
this.activeModal.close('deleted');
|
||||
});
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Lista de Encuestas del Usuario -->
|
||||
<div class="ds-list" (contextmenu)="openContextMenu($event)" *ngIf="!isAdmin">
|
||||
<div class="ds-list" (contextmenu)="openContextMenu($event)" *ngIf="!isAdmin()">
|
||||
<!-- Context Menu -->
|
||||
<div class="ds-contextmenu ds-contextmenu--closed" id="contextmenu">
|
||||
<ul id="ds-context-menu__list">
|
||||
|
@ -205,7 +205,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive" id="entities" *ngIf="isAdmin && encuestas && encuestas.length > 0">
|
||||
<div class="table-responsive" id="entities" *ngIf="isAdmin() && encuestas && encuestas.length > 0">
|
||||
<table class="table table-striped" aria-describedby="page-heading">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
@ -57,6 +57,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
|||
|
||||
account: Account | null = null;
|
||||
usuarioExtra: UsuarioExtra | null = null;
|
||||
estadoDeleted = EstadoEncuesta.DELETED;
|
||||
|
||||
encuestas?: IEncuesta[];
|
||||
isLoading = false;
|
||||
|
@ -109,7 +110,9 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
|||
if (this.isAdmin()) {
|
||||
this.encuestas = tmpEncuestas;
|
||||
} else {
|
||||
this.encuestas = tmpEncuestas.filter(e => e.usuarioExtra?.id === this.usuarioExtra?.id);
|
||||
this.encuestas = tmpEncuestas
|
||||
.filter(e => e.usuarioExtra?.id === this.usuarioExtra?.id)
|
||||
.filter(e => e.estado !== EstadoEncuesta.DELETED);
|
||||
}
|
||||
},
|
||||
() => {
|
||||
|
@ -167,7 +170,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
|||
|
||||
ngAfterViewInit(): void {}
|
||||
|
||||
trackId(index: number, item: IEncuesta): number {
|
||||
trackId(_index: number, item: IEncuesta): number {
|
||||
return item.id!;
|
||||
}
|
||||
|
||||
|
@ -197,11 +200,11 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
|||
}
|
||||
}
|
||||
|
||||
trackCategoriaById(index: number, item: ICategoria): number {
|
||||
trackCategoriaById(_index: number, item: ICategoria): number {
|
||||
return item.id!;
|
||||
}
|
||||
|
||||
trackUsuarioExtraById(index: number, item: IUsuarioExtra): number {
|
||||
trackUsuarioExtraById(_index: number, item: IUsuarioExtra): number {
|
||||
return item.id!;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue