|
| 1 | +import { Component } from "@angular/core"; |
| 2 | +import { async, TestBed } from "@angular/core/testing"; |
| 3 | +import { By } from "@angular/platform-browser"; |
| 4 | +import { ColumnDirective, GridDirective, RowDirective } from "./grid.directive"; |
| 5 | + |
| 6 | +@Component({ |
| 7 | + selector: "ibm-test-grid", |
| 8 | + template: "" |
| 9 | +}) |
| 10 | +class TestGridComponent {} |
| 11 | + |
| 12 | +describe("GridDirective", () => { |
| 13 | + beforeEach(() => { |
| 14 | + TestBed.configureTestingModule({ |
| 15 | + declarations: [ |
| 16 | + TestGridComponent, |
| 17 | + GridDirective, |
| 18 | + RowDirective, |
| 19 | + ColumnDirective |
| 20 | + ] |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + it("should render a grid", async(() => { |
| 25 | + TestBed.overrideComponent(TestGridComponent, { |
| 26 | + set: { |
| 27 | + template: `<div ibmGrid></div>` |
| 28 | + } |
| 29 | + }); |
| 30 | + |
| 31 | + TestBed.compileComponents().then(() => { |
| 32 | + const fixture = TestBed.createComponent(TestGridComponent); |
| 33 | + const directiveEl = fixture.debugElement.query( |
| 34 | + By.directive(GridDirective) |
| 35 | + ); |
| 36 | + fixture.detectChanges(); |
| 37 | + |
| 38 | + expect(directiveEl).not.toBeNull(); |
| 39 | + }); |
| 40 | + })); |
| 41 | + |
| 42 | + it("should render a row", async(() => { |
| 43 | + TestBed.overrideComponent(TestGridComponent, { |
| 44 | + set: { |
| 45 | + template: `<div ibmRow></div>` |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + TestBed.compileComponents().then(() => { |
| 50 | + const fixture = TestBed.createComponent(TestGridComponent); |
| 51 | + const directiveEl = fixture.debugElement.query( |
| 52 | + By.directive(RowDirective) |
| 53 | + ); |
| 54 | + fixture.detectChanges(); |
| 55 | + |
| 56 | + expect(directiveEl).not.toBeNull(); |
| 57 | + }); |
| 58 | + })); |
| 59 | + |
| 60 | + it("should render a column", async(() => { |
| 61 | + TestBed.overrideComponent(TestGridComponent, { |
| 62 | + set: { |
| 63 | + template: |
| 64 | + `<div ibmCol [offsets]="{'md': 2}" [columnNumbers]="{'lg': 3, 'md': 'nobreak'}" class='custom-class-example'></div>` |
| 65 | + } |
| 66 | + }); |
| 67 | + |
| 68 | + TestBed.compileComponents().then(() => { |
| 69 | + const fixture = TestBed.createComponent(TestGridComponent); |
| 70 | + const directiveEl = fixture.debugElement.query( |
| 71 | + By.directive(ColumnDirective) |
| 72 | + ); |
| 73 | + fixture.detectChanges(); |
| 74 | + |
| 75 | + expect(directiveEl).not.toBeNull(); |
| 76 | + |
| 77 | + const directiveInstance = directiveEl.injector.get(ColumnDirective); |
| 78 | + expect(directiveInstance.columnClasses).toBe( |
| 79 | + "bx--col-lg-3 bx--col-md bx--offset-md-2 custom-class-example" |
| 80 | + ); |
| 81 | + }); |
| 82 | + })); |
| 83 | +}); |
0 commit comments