FR-737: Refactor create claim selection (#563)

This commit is contained in:
Rinat Arsaev 2021-09-01 15:38:56 +03:00 committed by GitHub
parent 7a6b731827
commit f20380187b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 17 additions and 58 deletions

View File

@ -2,6 +2,6 @@
<project version="4">
<component name="PrettierConfiguration">
<option name="myRunOnSave" value="true" />
<option name="myFilesPattern" value="{**/*,*}.{js,ts,jsx,tsx,md,json,html,svg}" />
<option name="myFilesPattern" value="{**/*,*}.{js,ts,jsx,tsx,md,json,html,svg,scss,css}" />
</component>
</project>

4
.idea/watcherTasks.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectTasksOptions" suppressed-tasks="SCSS" />
</project>

View File

@ -9,7 +9,7 @@
"build": "ng build --extra-webpack-config webpack.extra.js",
"test": "ng test",
"coverage": "npx http-server -c-1 -o -p 9875 ./coverage",
"lint-cmd": "eslint \"src/**/*.{ts,js,html}\" --max-warnings 1665",
"lint-cmd": "eslint \"src/**/*.{ts,js,html}\" --max-warnings 1653",
"lint-cache-cmd": "npm run lint-cmd -- --cache",
"lint": "npm run lint-cache-cmd",
"lint-fix": "npm run lint-cache-cmd -- --fix",

View File

@ -10,12 +10,6 @@
(change)="onTypeChange($event.value)"
>{{ t('russianLegalEntityType') }}</mat-radio-button
>
<mat-radio-button
[checked]="selectedShopType === shopType.New"
[value]="shopType.New"
(change)="onTypeChange($event.value)"
>{{ t('newLegalEntityType') }}</mat-radio-button
>
<mat-radio-button
[checked]="selectedShopType === shopType.International"
[value]="shopType.International"
@ -26,19 +20,17 @@
>
</mat-radio-group>
</div>
<div dshBaseDialogActions *transloco="let c" fxLayout fxLayoutAlign="end">
<dsh-actions dshBaseDialogActions *transloco="let c">
<button
fxFlex="160px"
fxFlex.xs="none"
class="dsh-next-button"
dsh-button
(click)="next()"
color="accent"
class="dsh-next-button"
[disabled]="!selectedShopType"
>
{{ c('next') }}
</button>
</div>
</dsh-actions>
</dsh-base-dialog>
</ng-container>
</ng-container>

View File

@ -1,5 +1,5 @@
.dsh-next-button {
min-width: 100px;
min-width: 160px;
}
.dsh-wrap-mat-radio-label {

View File

@ -2,10 +2,9 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogRef } from '@angular/material/dialog';
import { MatRadioModule } from '@angular/material/radio';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslocoTestingModule } from '@ngneat/transloco';
import { instance, mock, verify } from 'ts-mockito';
import { instance, mock } from 'ts-mockito';
import { CreateShopDialogComponent } from './create-shop-dialog.component';
import { ShopType } from './types/shop-type';
@ -17,7 +16,6 @@ describe('CreateShopDialogComponent', () => {
let component: CreateShopDialogComponent;
let fixture: ComponentFixture<CreateShopDialogComponent>;
let mockDialogRef: MatDialogRef<CreateShopDialogComponent, 'cancel' | 'send'>;
let router: Router;
beforeEach(() => {
mockDialogRef = mock<MatDialogRef<CreateShopDialogComponent, 'cancel' | 'send'>>(MatDialogRef);
@ -64,7 +62,6 @@ describe('CreateShopDialogComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(CreateShopDialogComponent);
component = fixture.componentInstance;
router = TestBed.inject(Router);
fixture.detectChanges();
});
@ -77,9 +74,6 @@ describe('CreateShopDialogComponent', () => {
component.onTypeChange(ShopType.International);
expect(component.selectedShopType).toBe(ShopType.International);
component.onTypeChange(ShopType.New);
expect(component.selectedShopType).toBe(ShopType.New);
component.onTypeChange(ShopType.Russian);
expect(component.selectedShopType).toBe(ShopType.Russian);
});
@ -93,28 +87,5 @@ describe('CreateShopDialogComponent', () => {
expect(component.selectionConfirmed).toBe(true);
});
it('should close dialog if selectedShopType is new', () => {
component.onTypeChange(ShopType.New);
fixture.ngZone.run(() => {
component.next();
});
expect().nothing();
verify(mockDialogRef.close()).once();
});
it('should navigate to onboarding if selectedShopType is new', () => {
const spyOnNavigate = spyOn(router, 'navigate').and.callThrough();
component.onTypeChange(ShopType.New);
fixture.ngZone.run(() => {
component.next();
});
expect(spyOnNavigate).toHaveBeenCalledTimes(1);
expect(spyOnNavigate).toHaveBeenCalledWith(['claim-section', 'onboarding']);
});
});
});

View File

@ -1,6 +1,5 @@
import { Component } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { Shop } from '@dsh/api-codegen/capi';
@ -30,20 +29,13 @@ export class CreateShopDialogComponent {
selectionConfirmed = false;
shopType = ShopType;
constructor(
public dialogRef: MatDialogRef<CreateShopDialogComponent, BaseDialogResponseStatus>,
private router: Router
) {}
constructor(public dialogRef: MatDialogRef<CreateShopDialogComponent, BaseDialogResponseStatus>) {}
onTypeChange(type: ShopType): void {
this.selectedShopType = type;
}
next(): void {
if (this.selectedShopType === ShopType.New) {
this.dialogRef.close();
void this.router.navigate(['claim-section', 'onboarding']);
}
this.selectionConfirmed = true;
}

View File

@ -1,5 +1,4 @@
export enum ShopType {
Russian = 'RussianLegalEntity',
New = 'NewLegalEntity',
International = 'InternationalLegalEntity',
}

View File

@ -6,6 +6,7 @@ import { MatRadioModule } from '@angular/material/radio';
import { TranslocoModule } from '@ngneat/transloco';
import { PayoutsModule } from '@dsh/api/payouts';
import { ActionsModule } from '@dsh/app/shared/components/actions';
import { BaseDialogModule } from '@dsh/app/shared/components/dialog/base-dialog';
import { ShopCreationService } from '@dsh/app/shared/components/shop-creation/shop-creation.service';
import { ShopContractDetailsModule } from '@dsh/app/shared/services/shop-contract-details';
@ -28,6 +29,7 @@ import { CreateRussianShopEntityModule } from './create-russian-shop-entity';
PayoutsModule,
BaseDialogModule,
ShopContractDetailsModule,
ActionsModule,
],
declarations: [CreateShopDialogComponent],
providers: [ShopCreationService],

View File

@ -1,9 +1,8 @@
{
"title": "Новая заявка",
"type": "Выберите тип заявки",
"russianLegalEntityType": "Создание магазина (текущее ЮЛ)",
"newLegalEntityType": "Создание магазина (новое ЮЛ)",
"internationalLegalEntityType": "Создание магазина (международное ЮЛ)",
"type": "Создание магазина",
"russianLegalEntityType": "Российское ЮЛ",
"internationalLegalEntityType": "Международное ЮЛ",
"russianLegalEntity": {
"title": "Заявка на создание магазина",
"orgDetails": {