Skip to content

Commit a76051c

Browse files
Merge branch 'master' into TT-208-don't-allow-deleting-activities
2 parents 5c19c86 + e16c4c8 commit a76051c

24 files changed

+540
-113
lines changed

angular.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"src/assets"
2525
],
2626
"styles": [
27+
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
2728
"node_modules/datatables.net-dt/css/jquery.dataTables.css",
2829
"node_modules/datatables.net-responsive-dt/css/responsive.dataTables.css",
2930
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
@@ -106,6 +107,7 @@
106107
"src/assets"
107108
],
108109
"styles": [
110+
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
109111
"src/styles.scss"
110112
],
111113
"scripts": []

package-lock.json

Lines changed: 43 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "time-tracker",
3-
"version": "1.38.1",
3+
"version": "1.40.0",
44
"scripts": {
55
"preinstall": "npx npm-force-resolutions",
66
"ng": "ng",
@@ -20,6 +20,8 @@
2020
"@angular/compiler": "~10.2.2",
2121
"@angular/core": "~10.2.2",
2222
"@angular/forms": "~10.2.2",
23+
"@angular/material": "^11.2.3",
24+
"@angular/material-moment-adapter": "^11.2.9",
2325
"@angular/platform-browser": "~10.2.2",
2426
"@angular/platform-browser-dynamic": "~10.2.2",
2527
"@angular/router": "~10.2.2",

src/app/app.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { StoreModule } from '@ngrx/store';
1111
import { EffectsModule } from '@ngrx/effects';
1212
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
1313
import { DragDropModule } from '@angular/cdk/drag-drop';
14-
14+
import { MatDatepickerModule } from '@angular/material/datepicker';
15+
import { MatInputModule } from '@angular/material/input';
16+
import { MatMomentDateModule } from '@angular/material-moment-adapter';
1517
import { NgxPaginationModule } from 'ngx-pagination';
1618
import { AutocompleteLibModule } from 'angular-ng-autocomplete';
1719

@@ -134,6 +136,9 @@ const maskConfig: Partial<IConfig> = {
134136
],
135137
imports: [
136138
NgxMaskModule.forRoot(maskConfig),
139+
MatInputModule,
140+
MatDatepickerModule,
141+
MatMomentDateModule,
137142
CommonModule,
138143
BrowserModule,
139144
BrowserAnimationsModule,

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,36 @@
88
>
99
<thead class="thead-blue">
1010
<tr class="d-flex">
11-
<th class="col-5 text-center">Customer ID</th>
12-
<th class="col-3 text-center">Name</th>
13-
<th class="col-4 text-center">Options</th>
11+
<th class="col-4 text-center">Customer ID</th>
12+
<th class="col-4 text-center">Name</th>
13+
<th class="col-2 text-center">Options</th>
14+
<th class="col-2 text-center">Visibility</th>
1415
</tr>
1516
</thead>
1617
<app-loading-bar *ngIf="(isLoading$ | async)"></app-loading-bar>
1718
<tbody *ngIf="((isLoading$ | async) === false)">
1819
<tr class="d-flex" *ngFor="let customer of customers">
19-
<td class="col-5 text-break">{{ customer.id }}</td>
20-
<td class="col-3 text-break">{{ customer.name }}</td>
21-
<td class="col-4 text-center">
22-
<button
23-
data-toggle="modal"
24-
(click)="editCustomer(customer.id)"
25-
type="button"
26-
data-target="#editModal"
27-
class="btn btn-sm btn-primary"
28-
>
20+
<td class="col-4 text-break">{{ customer.id }}</td>
21+
<td class="col-4 text-break">{{ customer.name }}</td>
22+
<td class="col-2 text-center">
23+
<button
24+
data-toggle="modal"
25+
(click)="editCustomer(customer.id)"
26+
type="button" data-target="#editModal"
27+
class="btn btn-sm btn-primary">
2928
<i class="fa fa-pen fa-xs"></i>
3029
</button>
31-
32-
<button
33-
data-toggle="modal"
34-
data-target="#deleteModal"
35-
(click)="openModal(customer)"
36-
type="button"
37-
class="btn btn-sm btn-danger ml-2"
30+
</td>
31+
<td class="col-2 text-center">
32+
<button
33+
class="btn btn-sm"
34+
data-toggle="modal"
35+
data-target="#deleteModal"
36+
[ngClass]="customer.btnColor"
37+
(click)="switchStatus(customer)"
3838
>
39-
<i class="fa fa-trash-alt fa-xs"></i>
39+
<i class="fa" [ngClass]="customer.btnIcon" ></i>
40+
{{customer.btnName}}
4041
</button>
4142
</td>
4243
</tr>
@@ -68,4 +69,4 @@
6869
[body]="message"
6970
(closeModalEvent)="closeModal()"
7071
>
71-
</app-dialog>
72+
</app-dialog>

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.spec.ts

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,39 @@ describe('CustomerTableListComponent', () => {
2323
const actionSub: ActionsSubject = new ActionsSubject();
2424

2525
const state = {
26-
data: [{ tenant_id: 'id', name: 'name', description: 'description' }],
26+
data: [{ tenant_id: 'id', name: 'name', description: 'description', status: 'inactive' }],
2727
isLoading: false,
2828
message: '',
2929
customerIdToEdit: '',
3030
customerId: '',
3131
};
3232

33-
beforeEach(waitForAsync(() => {
34-
TestBed.configureTestingModule({
35-
imports: [NgxPaginationModule, DataTablesModule],
36-
declarations: [CustomerListComponent],
37-
providers: [provideMockStore({ initialState: state }), { provide: ActionsSubject, useValue: actionSub }],
38-
}).compileComponents();
39-
}));
33+
const btnProps = [
34+
{
35+
key: 'active',
36+
_status: false,
37+
btnColor: 'btn-danger',
38+
btnIcon: 'fa-arrow-circle-down',
39+
btnName: 'Archive',
40+
},
41+
{
42+
key: 'inactive',
43+
_status: true,
44+
btnColor: 'btn-primary',
45+
btnIcon: 'fa-arrow-circle-up',
46+
btnName: 'Active',
47+
},
48+
];
49+
50+
beforeEach(
51+
waitForAsync(() => {
52+
TestBed.configureTestingModule({
53+
imports: [NgxPaginationModule, DataTablesModule],
54+
declarations: [CustomerListComponent],
55+
providers: [provideMockStore({ initialState: state }), { provide: ActionsSubject, useValue: actionSub }],
56+
}).compileComponents();
57+
})
58+
);
4059

4160
beforeEach(() => {
4261
fixture = TestBed.createComponent(CustomerListComponent);
@@ -175,7 +194,12 @@ describe('CustomerTableListComponent', () => {
175194

176195
actionSubject.next(action);
177196

178-
expect(component.customers).toEqual(state.data);
197+
const StateWithBtnProperties = state.data.map((customer) => {
198+
const addProps = btnProps.find((prop) => prop.key === component.setActive(customer.status));
199+
return { ...customer, ...addProps };
200+
});
201+
202+
expect(component.customers).toEqual(StateWithBtnProperties);
179203
});
180204

181205
it('on success load customer, the datatable should be reloaded', async () => {
@@ -191,6 +215,60 @@ describe('CustomerTableListComponent', () => {
191215
expect(component.dtElement.dtInstance.then).toHaveBeenCalled();
192216
});
193217

218+
it('openModal should set on true and display "Are you sure you want to archive customer"', () => {
219+
const message = 'Are you sure you want to archive name?';
220+
const itemData = {
221+
id: '1',
222+
name: 'name',
223+
description: 'description',
224+
status: 'active',
225+
key: 'active',
226+
_status: false,
227+
btnColor: 'btn-danger',
228+
btnIcon: 'fa-arrow-circle-down',
229+
btnName: 'Archive',
230+
};
231+
232+
component.openModal(itemData);
233+
expect(component.showModal).toBeTrue();
234+
expect(component.message).toBe(message);
235+
});
236+
237+
it('switchStatus should call openModal() on item.status = activate', () => {
238+
const itemData = {
239+
id: '1',
240+
name: 'name',
241+
description: 'description',
242+
status: 'activate',
243+
key: 'activate',
244+
_status: false,
245+
btnColor: 'btn-danger',
246+
btnIcon: 'fa-arrow-circle-down',
247+
btnName: 'Archive',
248+
};
249+
250+
spyOn(component, 'openModal');
251+
component.switchStatus(itemData);
252+
expect(component.openModal).toHaveBeenCalled();
253+
});
254+
255+
it('switchStatus should set showModal false when item.status = inactive', () => {
256+
const itemData = {
257+
id: '1',
258+
name: 'name',
259+
description: 'description',
260+
status: 'inactive',
261+
key: 'inactive',
262+
_status: true,
263+
btnColor: 'btn-primary',
264+
btnIcon: 'fa-arrow-circle-up',
265+
btnName: 'Active',
266+
};
267+
268+
component.switchStatus(itemData);
269+
expect(component.showModal).toBeFalse();
270+
});
271+
194272
afterEach(() => {
195273
component.dtTrigger.unsubscribe();
196274
component.changeCustomerSubscription.unsubscribe();

0 commit comments

Comments
 (0)