Skip to content

Commit

Permalink
addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyakhajanchi committed Dec 8, 2023
1 parent 4d1b036 commit f8f4495
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
1 change: 1 addition & 0 deletions ui/dist/ui/main.8dfce83bcd067d5d.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { HttpClientModule } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { FormArray, FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { of } from 'rxjs';
import IConv from 'src/app/model/conv';
import IRule from 'src/app/model/rule';
import { ConversionService } from 'src/app/services/conversion/conversion.service';
import { DataService } from 'src/app/services/data/data.service';
Expand Down Expand Up @@ -50,10 +51,10 @@ describe('AddIndexFormComponent', () => {

fb = TestBed.inject(FormBuilder);

conversionServiceSpy.getColIdFromSpannerColName.and.returnValue("TestId")
conversionServiceSpy.getTableIdFromSpName.and.returnValue("t1")
// Added the spy methods in beforeEach block because these are referred in the ngOnInit function
conversionServiceSpy.getColIdFromSpannerColName.withArgs(jasmine.any(String),jasmine.any(String),jasmine.objectContaining<IConv>({})).and.returnValue("TestId")
conversionServiceSpy.getTableIdFromSpName.withArgs(jasmine.any(String), jasmine.objectContaining<IConv>({})).and.returnValue("t1")
dataServiceSpy.conv = of(mockIConv);
dataServiceSpy.dropRule.and.callThrough();
sidenavServiceSpy.sidenavAddIndexTable = of("t1");
sidenavServiceSpy.displayRuleFlag = of(true)
sidenavServiceSpy.ruleData = of()
Expand Down Expand Up @@ -83,7 +84,7 @@ describe('AddIndexFormComponent', () => {
Enabled: true,
Data: {
Id: "ind1",
Name: "ind1",
Name: "index1",
TableId: "t1",
Keys: [
{
Expand All @@ -96,10 +97,11 @@ describe('AddIndexFormComponent', () => {
}
sidenavServiceSpy.ruleData = of(addIndexRule)
component.ngOnInit()
const columnName = mockIConv.SpSchema[addIndexRule.Data.TableId]?.ColDefs[addIndexRule.Data.Keys[0].ColId].Name;
expect(component.ColsArray.length).toBe(1);
expect(component.ColsArray.at(0).value.columnName).toEqual('column1');
expect(component.addIndexForm.controls['tableName'].value).toEqual("table1");
expect(component.addIndexForm.controls['indexName'].value).toEqual("ind1")
expect(component.ColsArray.at(0).value.columnName).toEqual(columnName);
expect(component.addIndexForm.controls['tableName'].value).toEqual(mockIConv.SpSchema[addIndexRule.Data.TableId].Name);
expect(component.addIndexForm.controls['indexName'].value).toEqual(addIndexRule.Data.Name)
expect(component.addIndexForm.status).toEqual("DISABLED");
});

Expand Down Expand Up @@ -133,8 +135,9 @@ describe('AddIndexFormComponent', () => {
],
};
component.setColArraysForViewRules(tableId, ruleData.Keys);
const columnName = mockIConv.SpSchema[tableId]?.ColDefs[ruleData.Keys[0].ColId].Name;
expect(component.ColsArray.length).toBe(1);
expect(component.ColsArray.at(0).value.columnName).toEqual('column1');
expect(component.ColsArray.at(0).value.columnName).toEqual(columnName);
});

it('should clear column arrays for empty data', () => {
Expand Down Expand Up @@ -181,9 +184,12 @@ describe('AddIndexFormComponent', () => {
fb.group({ columnName: 'column1', sort: 'true' }),
]),
});
const tableNameValue = component.addIndexForm.get('tableName')?.value;
const colsArray = component.addIndexForm.get('ColsArray') as FormArray;
const columnNameValue = colsArray.at(0)?.get('columnName')?.value;
component.addIndex();
expect(conversionServiceSpy.getTableIdFromSpName).toHaveBeenCalledWith('table1', component.conv);
expect(conversionServiceSpy.getColIdFromSpannerColName).toHaveBeenCalledWith('column1', 't1', component.conv);
expect(conversionServiceSpy.getTableIdFromSpName).toHaveBeenCalledWith(tableNameValue, component.conv);
expect(conversionServiceSpy.getColIdFromSpannerColName).toHaveBeenCalledWith(columnNameValue, 't1', component.conv);
expect(dataServiceSpy.applyRule).toHaveBeenCalled();
expect(sidenavServiceSpy.setSidenavAddIndexTable).toHaveBeenCalledWith('');
expect(sidenavServiceSpy.closeSidenav).toHaveBeenCalled();
Expand Down
10 changes: 4 additions & 6 deletions ui/src/app/components/workspace/workspace.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ISpannerConfig from 'src/app/model/spanner-config'
import { MatTabsModule } from '@angular/material/tabs'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { FlatNode } from 'src/app/model/schema-object-node'
import IConv from 'src/app/model/conv'
const mockStructuredReport: IStructuredReport = {
summary: {
text: "",
Expand Down Expand Up @@ -115,9 +116,6 @@ describe('WorkspaceComponent', () => {
fetchServiceSpy.getLastSessionDetails.and.returnValue(of(mockIConv));
fetchServiceSpy.getSpannerConfig.and.returnValue(of(mockSpannerConfig));
fetchServiceSpy.getIsOffline.and.returnValue(of(false));
fetchServiceSpy.getDStructuredReport.and.returnValue(of({} as any));
fetchServiceSpy.getDTextReport.and.returnValue(of('textReport'));
fetchServiceSpy.getDSpannerDDL.and.returnValue(of('spannerDDL'));
})

beforeEach(() => {
Expand Down Expand Up @@ -422,8 +420,8 @@ describe('WorkspaceComponent', () => {
parent: '',
parentId: ''
};
conversionServiceSpy.getColumnMapping.and.returnValue([]);
conversionServiceSpy.getFkMapping.and.returnValue([]);
conversionServiceSpy.getColumnMapping.withArgs(jasmine.any(String), jasmine.objectContaining<IConv>({})).and.returnValue([]);
conversionServiceSpy.getFkMapping.withArgs(jasmine.any(String), jasmine.objectContaining<IConv>({})).and.returnValue([]);

component.changeCurrentObject(tableNode);

Expand All @@ -446,7 +444,7 @@ describe('WorkspaceComponent', () => {
isDeleted: false,
parent: ''
};
conversionServiceSpy.getIndexMapping.and.returnValue([]);
conversionServiceSpy.getIndexMapping.withArgs(jasmine.any(String),jasmine.objectContaining<IConv>({}),jasmine.any(String)).and.returnValue([]);
component.changeCurrentObject(indexNode);
expect(component.currentObject).toEqual(indexNode);
expect(component.indexData).toEqual([]);
Expand Down

0 comments on commit f8f4495

Please sign in to comment.