Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
Connections test seems to be using the mock service now.
Browse files Browse the repository at this point in the history
  • Loading branch information
elvisisking committed Oct 24, 2017
1 parent 07f92f8 commit 98580ea
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 32 deletions.
61 changes: 31 additions & 30 deletions ngapp/src/app/connections/connections.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ describe("ConnectionsComponent", () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ CoreModule, FormsModule, HttpModule, ModalModule.forRoot(), RouterTestingModule, SharedModule ],
declarations: [ ConnectionsComponent, ConnectionsListComponent, ConnectionsCardsComponent ],
providers: [
{ provide: ConnectionService, useValue: MockConnectionService },
]
})
.compileComponents().then(() => {
// Nothing
declarations: [ ConnectionsComponent, ConnectionsListComponent, ConnectionsCardsComponent ]
});

// use mock service
TestBed.overrideComponent( ConnectionsComponent, {
set: {
providers: [
{ provide: ConnectionService, useClass: MockConnectionService },
]
}
});
}));

beforeEach(() => {
fixture = TestBed.createComponent(ConnectionsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
}));

it("should be created", () => {
expect(component).toBeTruthy();
Expand All @@ -52,27 +53,27 @@ describe("ConnectionsComponent", () => {
expect(de).toBeDefined();
});

// it("should have Connections", () => {
// // Check component object
// const connections = component.allConnections;
// expect(connections.length).toEqual(3);
//
// // Check html has the same number of connection cards
// const cardDebugElems = fixture.debugElement.queryAll(By.css(".connection-card-title"));
// expect(cardDebugElems).toBeDefined();
// expect(cardDebugElems.length).toEqual(3);
// });
it("should have Connections", () => {
// Check component object
const connections = component.allConnections;
expect(connections.length).toEqual(3);

// it("should have initial card layout", () => {
// // app-connections-cards should be present
// let debugEl = fixture.debugElement.query(By.css("app-connections-cards"));
// const element = debugEl.nativeElement;
// expect(element).toBeDefined();
//
// // app-connections-list should not be present
// debugEl = fixture.debugElement.query(By.css("app-connections-list"));
// expect(debugEl).toBeNull();
// });
// Check html has the same number of connection cards
const cardDebugElems = fixture.debugElement.queryAll(By.css(".connection-card-title"));
expect(cardDebugElems).toBeDefined();
expect(cardDebugElems.length).toEqual(3);
});

it("should have initial card layout", () => {
// app-connections-cards should be present
let debugEl = fixture.debugElement.query(By.css("app-connections-cards"));
const element = debugEl.nativeElement;
expect(element).toBeDefined();

// app-connections-list should not be present
debugEl = fixture.debugElement.query(By.css("app-connections-list"));
expect(debugEl).toBeNull();
});

// it("should toggle layout", () => {
// // Initial layout should be Card Layout
Expand Down
19 changes: 17 additions & 2 deletions ngapp/src/app/connections/connections.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,25 @@ export class ConnectionsComponent extends AbstractPageComponent {
}
}
this.filteredConns.sort( (c1: Connection, c2: Connection) => {
let rval: number = c1.getId().localeCompare(c2.getId());
if (this.sortDirection === SortDirection.DESC) {
let rval = 0;

if ( c1.getId() ) {
if ( c2.getId() ) {
// both connections have an ID
rval = c1.getId().localeCompare( c2.getId() );
} else {
// c2 does not have an ID
rval = 1;
}
} else if ( c2.getId() ) {
// c1 does not have an ID and c2 does
rval = -1;
}

if ( this.sortDirection === SortDirection.DESC ) {
rval *= -1;
}

return rval;
});

Expand Down

0 comments on commit 98580ea

Please sign in to comment.