Skip to content

Commit

Permalink
Add tests for UDC dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelwedler committed Mar 31, 2021
1 parent be3ac60 commit 034b74f
Show file tree
Hide file tree
Showing 19 changed files with 520 additions and 97 deletions.
18 changes: 2 additions & 16 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ import { NotificationItemComponent } from './components/notification/notificatio
import { HttpErrorResponse } from '@angular/common/http';
import { RaidenIconsModule } from './modules/raiden-icons/raiden-icons.module';
import { stub } from '../testing/stub';
import {
createNetworkMock,
createAddress,
createToken,
} from '../testing/test-data';
import { createNetworkMock, createAddress } from '../testing/test-data';
import { PendingTransferPollingService } from './services/pending-transfer-polling.service';
import { PaymentHistoryPollingService } from './services/payment-history-polling.service';
import { SharedService } from './services/shared.service';
Expand All @@ -53,8 +49,6 @@ import {
import { By } from '@angular/platform-browser';
import { ToastrModule } from 'ngx-toastr';
import { MatSidenav } from '@angular/material/sidenav';
import { UserDepositService } from './services/user-deposit.service';
import BigNumber from 'bignumber.js';
import { DecimalPipe } from './pipes/decimal.pipe';
import { BalanceWithSymbolComponent } from './components/balance-with-symbol/balance-with-symbol.component';
import { TokenNetworkSelectorComponent } from './components/token-network-selector/token-network-selector.component';
Expand Down Expand Up @@ -105,14 +99,6 @@ describe('AppComponent', () => {
// @ts-ignore
tokenPollingMock.tokens$ = of([]);

const userDepositMock = stub<UserDepositService>();
// @ts-ignore
userDepositMock.balance$ = of(new BigNumber('750000000000000000'));
// @ts-ignore
userDepositMock.servicesToken$ = of(createToken());
// @ts-ignore
userDepositMock.blocksUntilWithdraw$ = of(99);

TestBed.configureTestingModule({
declarations: [
AppComponent,
Expand Down Expand Up @@ -156,7 +142,7 @@ describe('AppComponent', () => {
provide: TokenPollingService,
useValue: tokenPollingMock,
},
{ provide: UserDepositService, useValue: userDepositMock },
TestProviders.MockUserDepositService(),
],
imports: [
MaterialComponentsModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('AddEditContactDialogComponent', () => {
],
providers: [
TestProviders.MockMatDialogData(payload),
TestProviders.MockMatDialogRef({ close: () => {} }),
TestProviders.MockMatDialogRef(),
TestProviders.MockRaidenConfigProvider(),
TestProviders.AddressBookStubProvider(),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('ConfirmationDialogComponent', () => {
],
providers: [
TestProviders.MockMatDialogData(payload),
TestProviders.MockMatDialogRef({ close: () => {} }),
TestProviders.MockMatDialogRef(),
],
imports: [
MaterialComponentsModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('DepositWithdrawDialogComponent', () => {
],
providers: [
TestProviders.MockMatDialogData(payload),
TestProviders.MockMatDialogRef({ close: () => {} }),
TestProviders.MockMatDialogRef(),
{
provide: TokenPollingService,
useValue: tokenPollingMock,
Expand Down
39 changes: 13 additions & 26 deletions src/app/components/header/header.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import { SearchFieldComponent } from '../search-field/search-field.component';
import { ToastrModule } from 'ngx-toastr';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { DecimalPipe } from '../../pipes/decimal.pipe';
import { UserDepositService } from '../../services/user-deposit.service';
import BigNumber from 'bignumber.js';
import { SharedService } from '../../services/shared.service';
import { UserToken } from '../../models/usertoken';
import { BalanceWithSymbolComponent } from '../balance-with-symbol/balance-with-symbol.component';
import { SelectedTokenService } from 'app/services/selected-token.service';
import { getMintAmount } from 'app/shared/mint-amount';
import { UserDepositDialogComponent } from '../user-deposit-dialog/user-deposit-dialog.component';

describe('HeaderComponent', () => {
let component: HeaderComponent;
Expand Down Expand Up @@ -79,12 +79,6 @@ describe('HeaderComponent', () => {
// @ts-ignore
channelPollingMock.channels$ = of(channels);

const userDepositMock = stub<UserDepositService>();
// @ts-ignore
userDepositMock.balance$ = of(new BigNumber('750000000000000000'));
// @ts-ignore
userDepositMock.servicesToken$ = of(servicesToken);

TestBed.configureTestingModule({
declarations: [
HeaderComponent,
Expand All @@ -107,7 +101,7 @@ describe('HeaderComponent', () => {
TestProviders.MockRaidenConfigProvider(),
TestProviders.MockMatDialog(),
TestProviders.AddressBookStubProvider(),
{ provide: UserDepositService, useValue: userDepositMock },
TestProviders.MockUserDepositService(servicesToken),
SharedService,
SelectedTokenService,
],
Expand Down Expand Up @@ -260,7 +254,7 @@ describe('HeaderComponent', () => {
tick();
}));

it('should mint 0.5 tokens when token has 18 decimals', () => {
it('should mint tokens', () => {
const raidenService = TestBed.inject(RaidenService);
const mintSpy = spyOn(raidenService, 'mintToken').and.callThrough();

Expand All @@ -270,27 +264,20 @@ describe('HeaderComponent', () => {
expect(mintSpy).toHaveBeenCalledTimes(1);
expect(mintSpy).toHaveBeenCalledWith(
tokens[0],
component.raidenAddress,
new BigNumber(500000000000000000)
getMintAmount(tokens[0].decimals)
);
});

it('should mint 5000 tokens when token has no decimals', () => {
const raidenService = TestBed.inject(RaidenService);
const mintSpy = spyOn(raidenService, 'mintToken').and.callThrough();
const selectedTokenService = TestBed.inject(SelectedTokenService);
const noDecimalsToken = createToken({ decimals: 0 });
selectedTokenService.setToken(noDecimalsToken);
fixture.detectChanges();
it('should open the UDC dialog', () => {
const dialog = (TestBed.inject(MatDialog) as unknown) as MockMatDialog;
const dialogSpy = spyOn(dialog, 'open');

clickElement(fixture.debugElement, '#mint');
clickElement(fixture.debugElement, '#open-udc');
fixture.detectChanges();

expect(mintSpy).toHaveBeenCalledTimes(1);
expect(mintSpy).toHaveBeenCalledWith(
noDecimalsToken,
component.raidenAddress,
new BigNumber(5000)
);
expect(dialogSpy).toHaveBeenCalledTimes(1);
expect(dialogSpy).toHaveBeenCalledWith(UserDepositDialogComponent, {
width: '509px',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('OpenDialogComponent', () => {
],
providers: [
TestProviders.MockMatDialogData(payload),
TestProviders.MockMatDialogRef({ close: () => {} }),
TestProviders.MockMatDialogRef(),
TestProviders.MockRaidenConfigProvider(),
TestProviders.AddressBookStubProvider(),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('PaymentDialogComponent', () => {
],
providers: [
TestProviders.MockMatDialogData(payload),
TestProviders.MockMatDialogRef({ close: () => {} }),
TestProviders.MockMatDialogRef(),
TestProviders.MockRaidenConfigProvider(),
TestProviders.AddressBookStubProvider(),
TestProviders.MockMatDialog(),
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/qr-code/qr-code.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('QrCodeComponent', () => {
declarations: [QrCodeComponent, RaidenDialogComponent],
providers: [
TestProviders.MockMatDialogData(payload),
TestProviders.MockMatDialogRef({ close: () => {} }),
TestProviders.MockMatDialogRef(),
],
imports: [
ClipboardModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('QuickConnectDialogComponent', () => {
],
providers: [
TestProviders.MockMatDialogData(payload),
TestProviders.MockMatDialogRef({ close: () => {} }),
TestProviders.MockMatDialogRef(),
TestProviders.MockRaidenConfigProvider(),
{
provide: TokenPollingService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('RegisterDialogComponent', () => {
],
providers: [
TestProviders.MockMatDialogData(),
TestProviders.MockMatDialogRef({ close: () => {} }),
TestProviders.MockMatDialogRef(),
TestProviders.MockRaidenConfigProvider(),
TestProviders.AddressBookStubProvider(),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
fxLayoutAlign="center start"
[formGroup]="form"
(keyup.enter)="onEnter($event)"
id="deposit-withdraw-form"
>
<button
class="cancel"
Expand All @@ -28,6 +29,7 @@
[matTooltip]="depositing ? 'Deposit' : 'Plan withdrawal'"
(click)="submit()"
[disabled]="form.invalid"
id="accept"
>
<mat-icon
class="accept__icon"
Expand Down
Loading

0 comments on commit 034b74f

Please sign in to comment.