-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feature/admin-pagination (pull request #13)
Added generalised Material pagination table for admin backend views Approved-by: Marcus Riemer
- Loading branch information
Showing
96 changed files
with
2,763 additions
and
913 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
172 changes: 172 additions & 0 deletions
172
client/src/app/admin/block-language/overview-block-language.component.spec.ts
This file contains 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,172 @@ | ||
import { FormsModule } from "@angular/forms"; | ||
import { RouterTestingModule } from "@angular/router/testing"; | ||
import { TestBed } from "@angular/core/testing"; | ||
import { NoopAnimationsModule } from "@angular/platform-browser/animations"; | ||
import { | ||
HttpClientTestingModule, | ||
HttpTestingController, | ||
} from "@angular/common/http/testing"; | ||
import { MatSnackBarModule } from "@angular/material/snack-bar"; | ||
import { MatTableModule } from "@angular/material/table"; | ||
import { MatPaginatorModule } from "@angular/material/paginator"; | ||
import { MatSortModule } from "@angular/material/sort"; | ||
import { PortalModule } from "@angular/cdk/portal"; | ||
|
||
import { first } from "rxjs/operators"; | ||
|
||
import { ServerApiService, ToolbarService } from "../../shared"; | ||
import { | ||
ListBlockLanguageDataService, | ||
MutateBlockLanguageService, | ||
} from "../../shared/serverdata"; | ||
import { DefaultValuePipe } from "../../shared/default-value.pipe"; | ||
import { | ||
provideBlockLanguageList, | ||
buildBlockLanguage, | ||
} from "../../editor/spec-util"; | ||
|
||
import { OverviewBlockLanguageComponent } from "./overview-block-language.component"; | ||
import { PaginatorTableComponent } from "../../shared/table/paginator-table.component"; | ||
|
||
describe("OverviewBlockLanguageComponent", () => { | ||
async function createComponent() { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
FormsModule, | ||
NoopAnimationsModule, | ||
MatSnackBarModule, | ||
MatTableModule, | ||
MatPaginatorModule, | ||
MatSortModule, | ||
PortalModule, | ||
HttpClientTestingModule, | ||
RouterTestingModule.withRoutes([]), | ||
], | ||
providers: [ | ||
ToolbarService, | ||
ServerApiService, | ||
ListBlockLanguageDataService, | ||
MutateBlockLanguageService, | ||
], | ||
declarations: [ | ||
OverviewBlockLanguageComponent, | ||
DefaultValuePipe, | ||
PaginatorTableComponent, | ||
], | ||
}).compileComponents(); | ||
|
||
let fixture = TestBed.createComponent(OverviewBlockLanguageComponent); | ||
let component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
|
||
const httpTesting = TestBed.inject(HttpTestingController); | ||
const serverApi = TestBed.inject(ServerApiService); | ||
|
||
return { | ||
fixture, | ||
component, | ||
element: fixture.nativeElement as HTMLElement, | ||
httpTesting, | ||
serverApi, | ||
}; | ||
} | ||
|
||
it(`can be instantiated`, async () => { | ||
const t = await createComponent(); | ||
|
||
expect(t.component).toBeDefined(); | ||
}); | ||
|
||
it(`Displays a loading indicator (or not)`, async () => { | ||
const t = await createComponent(); | ||
|
||
const initialLoading = await t.component.blockLanguages.listCache.inProgress | ||
.pipe(first()) | ||
.toPromise(); | ||
expect(initialLoading).toBe(true); | ||
|
||
provideBlockLanguageList([]); | ||
|
||
const afterResponse = await t.component.blockLanguages.listCache.inProgress | ||
.pipe(first()) | ||
.toPromise(); | ||
expect(afterResponse).toBe(false); | ||
}); | ||
|
||
it(`Displays an empty list`, async () => { | ||
const t = await createComponent(); | ||
|
||
provideBlockLanguageList([]); | ||
|
||
t.fixture.detectChanges(); | ||
await t.fixture.whenRenderingDone(); | ||
}); | ||
|
||
it(`Displays a list with a single element`, async () => { | ||
const t = await createComponent(); | ||
|
||
const i1 = buildBlockLanguage({ name: "B1" }); | ||
provideBlockLanguageList([i1]); | ||
|
||
t.fixture.detectChanges(); | ||
await t.fixture.whenRenderingDone(); | ||
|
||
const tableElement = t.element.querySelector("table"); | ||
const i1Row = tableElement.querySelector("tbody > tr"); | ||
|
||
expect(i1Row.textContent).toMatch(i1.name); | ||
expect(i1Row.textContent).toMatch(i1.id); | ||
}); | ||
|
||
it(`reloads data on refresh`, async () => { | ||
const t = await createComponent(); | ||
|
||
const i1 = buildBlockLanguage({ name: "B1" }); | ||
provideBlockLanguageList([i1]); | ||
|
||
const initialData = await t.component.blockLanguages.list | ||
.pipe(first()) | ||
.toPromise(); | ||
expect(initialData).toEqual([i1]); | ||
|
||
t.component.onRefresh(); | ||
provideBlockLanguageList([]); | ||
|
||
const refreshedData = await t.component.blockLanguages.list | ||
.pipe(first()) | ||
.toPromise(); | ||
expect(refreshedData).toEqual([]); | ||
}); | ||
|
||
it(`Triggers deletion`, async () => { | ||
const t = await createComponent(); | ||
|
||
const i1 = buildBlockLanguage({ name: "B1" }); | ||
provideBlockLanguageList([i1]); | ||
|
||
t.fixture.detectChanges(); | ||
await t.fixture.whenRenderingDone(); | ||
|
||
const tableElement = t.element.querySelector("table"); | ||
const i1Row = tableElement.querySelector("tbody > tr"); | ||
const i1Delete = i1Row.querySelector( | ||
"button[data-spec=delete]" | ||
) as HTMLButtonElement; | ||
|
||
i1Delete.click(); | ||
|
||
t.httpTesting | ||
.expectOne({ | ||
method: "DELETE", | ||
url: t.serverApi.individualBlockLanguageUrl(i1.id), | ||
}) | ||
.flush(""); | ||
|
||
provideBlockLanguageList([]); | ||
|
||
const refreshedData = await t.component.blockLanguages.list | ||
.pipe(first()) | ||
.toPromise(); | ||
expect(refreshedData).toEqual([]); | ||
}); | ||
}); |
Oops, something went wrong.