Skip to content
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

Feature/1990 #1992

Merged
merged 3 commits into from
Jun 10, 2024
Merged
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
Expand Up @@ -7,6 +7,7 @@ import {
testActiveReport,
testContact,
testMockStore,
testScheduleATransaction,
} from 'app/shared/utils/unit-test.utils';
import { DropdownModule } from 'primeng/dropdown';
import { ErrorMessagesComponent } from '../error-messages/error-messages.component';
Expand All @@ -17,15 +18,14 @@ import { AutoCompleteModule } from 'primeng/autocomplete';
import { LabelPipe } from 'app/shared/pipes/label.pipe';
import { CandidateOfficeTypes, Contact } from 'app/shared/models/contact.model';
import { Confirmation, ConfirmationService } from 'primeng/api';
import { SchATransaction, ScheduleATransactionTypes } from '../../models/scha-transaction.model';
import { DatePipe } from '@angular/common';
import { TransactionService } from 'app/shared/services/transaction.service';
import { of } from 'rxjs';
import { TableLazyLoadEvent } from 'primeng/table';
import { ListRestResponse } from 'app/shared/models/rest-api.model';
import { ActivatedRoute } from '@angular/router';
import { Form24 } from 'app/shared/models/form-24.model';
import { ReportTypes } from 'app/shared/models/report.model';
import { SchATransaction, ScheduleATransactionTypes } from 'app/shared/models/scha-transaction.model';

describe('ContactDialogComponent', () => {
let component: ContactDialogComponent;
Expand All @@ -43,18 +43,7 @@ describe('ContactDialogComponent', () => {
ContactLookupComponent,
LabelPipe,
],
providers: [
ConfirmationService,
FormBuilder,
provideMockStore(testMockStore),
DatePipe,
{
provide: ActivatedRoute,
useValue: {
snapshot: { params: { report_id: '999' } },
},
},
],
providers: [ConfirmationService, FormBuilder, provideMockStore(testMockStore), DatePipe],
}).compileComponents();

testConfirmationService = TestBed.inject(ConfirmationService);
Expand Down Expand Up @@ -131,16 +120,13 @@ describe('ContactDialogComponent', () => {
});

describe('transactions', () => {
let transaction: SchATransaction;
beforeEach(() => {
transaction = getTestTransactionByType(ScheduleATransactionTypes.INDIVIDUAL_RECEIPT) as SchATransaction;
transaction.reports = [testActiveReport];
});

it('should route to transaction', async () => {
it('should route to transaction', () => {
const spy = spyOn(component.router, 'navigate');
await component.openTransaction(new TransactionData(transaction));
expect(spy).toHaveBeenCalledWith([`reports/transactions/report/999/list/${transaction.id}`]);
const transaction = testScheduleATransaction;
component.openTransaction(new TransactionData(transaction));
expect(spy).toHaveBeenCalledWith([
`reports/transactions/report/${transaction.report_ids?.[0]}/list/${transaction.id}`,
]);
});

it('should handle pagination', async () => {
Expand All @@ -153,6 +139,10 @@ describe('ContactDialogComponent', () => {
});

it('should not show Form 24s', async () => {
const transaction: SchATransaction = getTestTransactionByType(
ScheduleATransactionTypes.INDIVIDUAL_RECEIPT,
) as SchATransaction;
transaction.reports = [testActiveReport];
transaction.reports?.push(Form24.fromJSON({ id: '1', report_type: ReportTypes.F24 }));
spyOn(transactionService, 'getTableData').and.returnValue(
of({ results: [transaction], count: 1, pageNumber: 1, next: '', previous: '' } as ListRestResponse),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ScheduleC2TransactionTypeLabels } from '../../models/schc2-transaction.
import { ScheduleCTransactionTypeLabels } from '../../models/schc-transaction.model';
import { ScheduleDTransactionTypeLabels } from '../../models/schd-transaction.model';
import { ScheduleETransactionTypeLabels } from '../../models/sche-transaction.model';
import { ActivatedRoute, Router } from '@angular/router';
import { Router } from '@angular/router';
import { TransactionService } from '../../services/transaction.service';
import { TableLazyLoadEvent } from 'primeng/table';
import { getReportFromJSON } from '../../services/report.service';
Expand Down Expand Up @@ -126,7 +126,6 @@ export class ContactDialogComponent extends DestroyerComponent implements OnInit
private fb: FormBuilder,
private contactService: ContactService,
private transactionService: TransactionService,
private activatedRoute: ActivatedRoute,
protected confirmationService: ConfirmationService,
public router: Router,
) {
Expand Down Expand Up @@ -376,8 +375,7 @@ export class ContactDialogComponent extends DestroyerComponent implements OnInit
}

async openTransaction(transaction: TransactionData) {
const reportId = this.activatedRoute.snapshot.params['report_id'];
await this.router.navigate([`reports/transactions/report/${reportId}/list/${transaction.id}`]);
await this.router.navigate([`reports/transactions/report/${transaction.report_ids[0]}/list/${transaction.id}`]);
}

onRowsPerPageChange(rowsPerPage: number) {
Expand Down