From 4456a0570d9c34c8cab014ee91e7d8b0439cadf2 Mon Sep 17 00:00:00 2001 From: sipolyashhivangi Date: Tue, 7 Feb 2023 14:28:08 -0500 Subject: [PATCH 1/2] added code for selected and unselected items --- src/app/list/list.component.css | 28 +++++++++++++++++++++++++ src/app/list/list.component.html | 36 ++++++++++++++++++++++++++++++++ src/app/list/list.component.ts | 24 ++++++++++++++++++++- 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/app/list/list.component.css b/src/app/list/list.component.css index ef11c96..51b1d79 100644 --- a/src/app/list/list.component.css +++ b/src/app/list/list.component.css @@ -8,3 +8,31 @@ h2 { border-bottom: 1px solid lightgray; } + +.data-list-container { + display: flex; +} + +.data-list { + width: 50%; + padding: 20px; +} + +.card-list { + display: flex; +} + +.card { + width: 200px; + border: 1px solid; + margin: 10px; + padding: 10px; + height: 100px; + position: relative; +} + +.remove { + position: absolute; + top: -9px; + right: -10px; +} \ No newline at end of file diff --git a/src/app/list/list.component.html b/src/app/list/list.component.html index e4b0765..f0eb5be 100644 --- a/src/app/list/list.component.html +++ b/src/app/list/list.component.html @@ -1,4 +1,40 @@

Providers

+
+ +
+

Provided List

+
+ +
+ {{item.name}} +

{{item.address}}

+ +
+
+ +
no record +
+
+
+
+ +
+

Selected Provided List

+
+ +
+ {{item.name}} +

{{item.address}}

+ +
+
+ +
no record +
+
+
+
+
diff --git a/src/app/list/list.component.ts b/src/app/list/list.component.ts index 8a50db6..acb760c 100644 --- a/src/app/list/list.component.ts +++ b/src/app/list/list.component.ts @@ -31,6 +31,28 @@ export class ListComponent implements OnInit { constructor() {} - ngOnInit() {} + ngOnInit() { + try { + let data = sessionStorage.getItem('selectedItems');; + data = data ? JSON.parse(data) : []; + this.selectedProviders = this.selectedProviders.concat(data); + this.unselectedProviders = this.unselectedProviders.filter(item => this.selectedProviders.findIndex(subitem => subitem.id === item.id) === -1); + } catch (e) {} + } + + select(item, index) { + console.log('hi', index) + this.unselectedProviders.splice(index, 1); + this.selectedProviders.push(item); + sessionStorage.setItem('selectedItems', JSON.stringify(this.selectedProviders)); + } + + deselect(item, index) { + console.log('bye', index) + + this.selectedProviders.splice(index, 1); + this.unselectedProviders.push(item); + sessionStorage.setItem('selectedItems', JSON.stringify(this.selectedProviders)); + } } From 161e855e857e33bf50fc91a5690c32a780a41c37 Mon Sep 17 00:00:00 2001 From: sipolyashhivangi Date: Tue, 7 Feb 2023 14:37:11 -0500 Subject: [PATCH 2/2] added unit tests for select and unselect methods --- src/app/list/list.component.spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/app/list/list.component.spec.ts b/src/app/list/list.component.spec.ts index 59bde51..a65e008 100644 --- a/src/app/list/list.component.spec.ts +++ b/src/app/list/list.component.spec.ts @@ -38,4 +38,17 @@ describe('ListComponent', () => { expect(component.selectedProviders.length).toEqual(0); }); }); + + describe('provider selection and deselection', () => { + it('should select provider', () => { + component.select(component.unselectedProviders[0], 0); + expect(component.selectedProviders.length).toEqual(1); + }); + + it('should deselect provider', () => { + component.select(component.unselectedProviders[0], 0); + component.deselect(component.selectedProviders[0], 0); + expect(component.unselectedProviders.length).toEqual(3); + }); + }); });