-
Notifications
You must be signed in to change notification settings - Fork 1
87 save customers #139
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
Merged
Merged
87 save customers #139
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
016d0c6
fix: #87 c1-save-customers
daros10 d038c10
fix: #87 c2-save-customers-tests
daros10 4863d19
fix: #87 c3-save-customers
daros10 f2f62e4
fix: #87 c1-save-customers
daros10 2cc4c8c
Merge branch '87-Save-customers' of https://github.com/ioet/time-trac…
daros10 2e9aef9
fix: #87 fixed issues and remove search component
daros10 b760c32
Merge branch 'master' of https://github.com/ioet/time-tracker-ui into…
daros10 925becb
fix: #87 get tenant_id from session storage
daros10 d4ff348
fix: #87 get tenant_id from AzureServices
daros10 b2a4427
remove console log
daros10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...tomer-management/components/customer-info/components/create-customer/create-customer.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <div class="container"> | ||
| <form style="width: 600px;" [formGroup]="customerForm" (ngSubmit)="onSubmit(customerForm.value)"> | ||
| <div class="form-group"> | ||
| <div | ||
| *ngIf="showAlert && messageToShow !== ''" | ||
| [ngClass]="{'bg-secondary': messageToShow == 'Customer created successfully!', 'bg-primary': messageToShow != 'Customer created successfully!'}" | ||
| class="alert alert-dismissible fade fade-in show text-white" | ||
| role="alert" | ||
| > | ||
| <strong>{{ messageToShow }}</strong> | ||
| </div> | ||
|
|
||
| <input | ||
| class="form-control form-control-sm" | ||
| id="name" | ||
| type="text" | ||
| formControlName="name" | ||
| placeholder="Customer name" | ||
| [class.is-invalid]="customerForm.invalid && customerForm.touched" | ||
| required | ||
| /> | ||
| <span | ||
| class="badge badge-pill badge-light text-danger" | ||
| *ngIf="(customerForm.dirty || customerForm.touched) && customerForm.invalid" | ||
| >Activity name is required</span | ||
| > | ||
| <textarea | ||
| class="form-control form-control-sm mt-2" | ||
| id="description" | ||
| rows="3" | ||
| formControlName="description" | ||
| placeholder="Customer description" | ||
| ></textarea> | ||
| <button type="submit" class="btn btn-sm btn-primary" [disabled]="!customerForm.valid">Save</button> | ||
| <button (click)="resetCustomerForm()" id="cancel" type="button" class="btn btn-sm btn-secondary mb-2 ml-2 mt-2"> | ||
| Cancel | ||
| </button> | ||
| </div> | ||
| </form> | ||
| </div> |
File renamed without changes.
106 changes: 106 additions & 0 deletions
106
...er-management/components/customer-info/components/create-customer/create-customer.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { FormBuilder } from '@angular/forms'; | ||
| import { MockStore, provideMockStore } from '@ngrx/store/testing'; | ||
|
|
||
| import { CreateCustomerComponent } from './create-customer'; | ||
| import { CustomerState, CreateCustomer } from 'src/app/modules/customer-management/store'; | ||
| import * as models from 'src/app/modules/shared/models/index'; | ||
|
|
||
| describe('CreateCustomerComponent', () => { | ||
| let component: CreateCustomerComponent; | ||
| let fixture: ComponentFixture<CreateCustomerComponent>; | ||
| let store: MockStore<CustomerState>; | ||
|
|
||
| const state = { | ||
| data: [], | ||
| isLoading: false, | ||
| message: '', | ||
| }; | ||
|
|
||
| const customerData: models.Customer = { | ||
| name: 'aa', | ||
| description: 'bb', | ||
| tenant_id: 'cc', | ||
| }; | ||
|
|
||
| beforeEach(async(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [CreateCustomerComponent], | ||
| providers: [FormBuilder, provideMockStore({ initialState: state })], | ||
| }).compileComponents(); | ||
| })); | ||
|
|
||
| beforeEach(() => { | ||
| fixture = TestBed.createComponent(CreateCustomerComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
|
|
||
| store = TestBed.inject(MockStore); | ||
| store.setState(state); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fixture.destroy(); | ||
| }); | ||
|
|
||
| it('component should be created', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should call resetCustomerForm', () => { | ||
| spyOn(component.customerForm, 'reset'); | ||
|
|
||
| component.resetCustomerForm(); | ||
|
|
||
| expect(component.customerForm.reset).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('onSubmit and dispatch CreateCustomer action', () => { | ||
| spyOn(store, 'dispatch'); | ||
|
|
||
| component.onSubmit(customerData); | ||
|
|
||
| expect(store.dispatch).toHaveBeenCalledTimes(1); | ||
| expect(store.dispatch).toHaveBeenCalledWith(new CreateCustomer(customerData)); | ||
| }); | ||
|
|
||
| it('should call resetCustomerForm', () => { | ||
| spyOn(component.customerForm, 'reset'); | ||
|
|
||
| component.resetCustomerForm(); | ||
|
|
||
| expect(component.customerForm.reset).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should be enable tabs and show message Customer created successfully! ', () => { | ||
| component.areTabsActive = false; | ||
| component.messageToShow = ''; | ||
|
|
||
| spyOn(store, 'dispatch'); | ||
|
|
||
| component.ngOnInit(); | ||
|
|
||
| component.onSubmit(customerData); | ||
|
|
||
| component.setStatusOnScreen('Customer created successfully!'); | ||
|
|
||
| expect(component.messageToShow).toEqual('Customer created successfully!'); | ||
| expect(component.areTabsActive).toBeTrue(); | ||
| }); | ||
|
|
||
| it('should be disabled tabs and show message An error occurred, try again later. ', () => { | ||
| component.areTabsActive = false; | ||
| component.messageToShow = ''; | ||
|
|
||
| spyOn(store, 'dispatch'); | ||
|
|
||
| component.ngOnInit(); | ||
|
|
||
| component.onSubmit(customerData); | ||
|
|
||
| component.setStatusOnScreen('An error occurred, try again later.'); | ||
|
|
||
| expect(component.messageToShow).toEqual('An error occurred, try again later.'); | ||
| expect(component.areTabsActive).toBeFalse(); | ||
| }); | ||
| }); |
62 changes: 62 additions & 0 deletions
62
...ustomer-management/components/customer-info/components/create-customer/create-customer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { Component, Input, Output, EventEmitter, OnDestroy, OnInit } from '@angular/core'; | ||
| import { FormGroup, FormBuilder, Validators } from '@angular/forms'; | ||
| import { Store, select } from '@ngrx/store'; | ||
|
|
||
| import { Subscription } from 'rxjs'; | ||
| import { CustomerState, CreateCustomer } from 'src/app/modules/customer-management/store'; | ||
| import { getStatusMessage } from 'src/app/modules/customer-management/store/customer-management.selectors'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-create-customer', | ||
| templateUrl: './create-customer.html', | ||
| styleUrls: ['./create-customer.scss'], | ||
| }) | ||
| export class CreateCustomerComponent implements OnInit, OnDestroy { | ||
| customerForm: FormGroup; | ||
| @Input() areTabsActive: boolean; | ||
| @Output() changeValueAreTabsActives = new EventEmitter<boolean>(); | ||
| showAlert = false; | ||
| messageToShow = ''; | ||
| saveSubscription: Subscription; | ||
|
|
||
| constructor(private formBuilder: FormBuilder, private store: Store<CustomerState>) { | ||
| this.customerForm = this.formBuilder.group({ | ||
| name: ['', Validators.required], | ||
| description: [''], | ||
| }); | ||
| } | ||
|
|
||
| ngOnInit() { | ||
| const messages$ = this.store.pipe(select(getStatusMessage)); | ||
| this.saveSubscription = messages$.subscribe((valueMessage) => { | ||
| this.setStatusOnScreen(valueMessage); | ||
| }); | ||
| } | ||
|
|
||
| ngOnDestroy() { | ||
| this.areTabsActive = false; | ||
| this.saveSubscription.unsubscribe(); | ||
| } | ||
|
|
||
| onSubmit(customerData) { | ||
| this.store.dispatch(new CreateCustomer(customerData)); | ||
| this.showAlert = true; | ||
| } | ||
|
|
||
| setStatusOnScreen(message: string) { | ||
| if (message === 'Customer created successfully!') { | ||
| this.messageToShow = message; | ||
| this.areTabsActive = true; | ||
| this.changeValueAreTabsActives.emit(this.areTabsActive); | ||
| } else if (message === 'An error occurred, try again later.') { | ||
| this.messageToShow = message; | ||
| this.areTabsActive = false; | ||
| this.changeValueAreTabsActives.emit(this.areTabsActive); | ||
| } | ||
| } | ||
|
|
||
| resetCustomerForm() { | ||
| this.showAlert = false; | ||
| this.customerForm.reset(); | ||
| } | ||
| } | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions
42
src/app/modules/customer-management/services/customer.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
| import { TestBed, inject } from '@angular/core/testing'; | ||
|
|
||
| import { CustomerService } from './customer.service'; | ||
| import { Customer } from '../../shared/models/customer.model'; | ||
|
|
||
| describe('CustomerService', () => { | ||
| let service: CustomerService; | ||
| let httpMock: HttpTestingController; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ imports: [HttpClientTestingModule] }); | ||
| service = TestBed.inject(CustomerService); | ||
| httpMock = TestBed.inject(HttpTestingController); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| httpMock.verify(); | ||
| }); | ||
|
|
||
| it('services are ready to be used', inject( | ||
| [HttpClientTestingModule, CustomerService], | ||
| (httpClient: HttpClientTestingModule, customerService: CustomerService) => { | ||
| expect(customerService).toBeTruthy(); | ||
| expect(httpClient).toBeTruthy(); | ||
| } | ||
| )); | ||
|
|
||
| it('create customer using POST from baseUrl', () => { | ||
| const customer: Customer[] = [{ name: 'aa', description: 'bb', tenant_id: 'cc' }]; | ||
|
|
||
| service.baseUrl = 'customers'; | ||
|
|
||
| service.createCustomer(customer).subscribe((response) => { | ||
| expect(response.length).toBe(1); | ||
| }); | ||
|
|
||
| const createCustomerRequest = httpMock.expectOne(service.baseUrl); | ||
| expect(createCustomerRequest.request.method).toBe('POST'); | ||
| createCustomerRequest.flush(customer); | ||
| }); | ||
| }); |
24 changes: 24 additions & 0 deletions
24
src/app/modules/customer-management/services/customer.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { HttpClient, HttpHeaders } from '@angular/common/http'; | ||
|
|
||
| import { environment } from './../../../../environments/environment'; | ||
| import { AzureAdB2CService } from 'src/app/modules/login/services/azure.ad.b2c.service'; | ||
| import { Observable } from 'rxjs'; | ||
|
|
||
| @Injectable({ | ||
| providedIn: 'root', | ||
| }) | ||
| export class CustomerService { | ||
| baseUrl = `${environment.timeTrackerApiUrl}/customers`; | ||
|
|
||
| constructor(private http: HttpClient, private service: AzureAdB2CService) {} | ||
|
|
||
| createCustomer(customerData): Observable<any> { | ||
| const body = { | ||
| ...customerData, | ||
| tenant_id: this.service.getTenantId(), | ||
| }; | ||
| console.log(this.service.getTenantId()); | ||
|
||
| return this.http.post(this.baseUrl, body); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please sort imports by module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done