Giter Site home page Giter Site logo

Comments (5)

chych avatar chych commented on May 21, 2024 1

I'm agree with you it's the solution that i adopted

from ngx-materialize.

jfcere avatar jfcere commented on May 21, 2024

Hi @chych, can you provide a sample of your html, component and test code? I'm wondering if the error is related to your test code or to our library ...

from ngx-materialize.

chych avatar chych commented on May 21, 2024

Actually my component is empty, no code except constructor...,
html template just content mz-sidenav component
the problem appear with the [collapseButtonId]="'btnSidenav'" because i split the header and sidenav in two differents component.

My home component contains :


<app-header></app-header>
<app-home-sidenav></app-home-sidenav>

My header template:

<header>
    <div class="navbar-fixed navbar-mycj">
        <nav class="nav-mycj blue-grey" [ngClass]="{navFixed: navIsFixed}" role="navigation">
            <div class="nav-wrapper container">
                <a id="logo-container" href="#" class="brand-logo position">
                    <img alt="logo mycloudjob" src="./assets/images/mycj/logo-navbar.png">
                </a>
                <ul class="right hide-on-med-and-down">
                    <li><a href="#" class="btn blue-grey">Se connecter</a></li>
                    <li><a href="#" class="btn pink">S'inscrire</a></li>
                </ul>

                <a href="#"
                   [id]="'btnSidenav'"
                   class="button-collapse hide-on-large-only right"><i class="material-icons">menu</i></a>

            </div>
        </nav>
    </div>
</header>

My component containing(app-home-sidenav) :

import {Component, OnInit} from "@angular/core";

@Component({
    selector: 'app-home-sidenav',
    templateUrl: './home-sidenav.component.html',
    styleUrls: ['./home-sidenav.component.css']
})
export class HomeSidenavComponent implements OnInit {


    constructor() { }

    ngOnInit() {
    }

}

My component html(app-home-sidenav) :

<mz-sidenav
    [id]="'sidenav'"
    [collapseButtonId]="'btnSidenav'">
    <mz-sidenav-header>
        Sidenav header
    </mz-sidenav-header>
    <mz-sidenav-subheader>Link Subheader</mz-sidenav-subheader>
    <mz-sidenav-link>
        <a href="#">First Link</a>
    </mz-sidenav-link>
    <!--<mz-sidenav-divider></mz-sidenav-divider>-->
    <mz-sidenav-link [active]="true">
        <a href="#">Active Link</a>
    </mz-sidenav-link>
    <mz-sidenav-divider></mz-sidenav-divider>
    <mz-sidenav-link>
        <a href="#" class="waves-effect">Second Link With Waves</a>
    </mz-sidenav-link>
</mz-sidenav>

My component test(app-home-sidenav)

import {async, ComponentFixture, TestBed} from "@angular/core/testing";
import {HomeSidenavComponent} from "./home-sidenav.component";
import {MaterializeModule} from "ng2-materialize";

describe('HomeSidenavComponent', () => {
    let component: HomeSidenavComponent;
    let fixture: ComponentFixture<HomeSidenavComponent>;

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [
                HomeSidenavComponent,
            ],
            imports: [
                MaterializeModule,
            ],
        })
            .compileComponents();
    }));

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

    });

    it('should be created', () => {
        expect(component).toBeTruthy();
    });
});

from ngx-materialize.

chych avatar chych commented on May 21, 2024

The solution i found it's to not separate my colapse button and the sidenav :

<header>
    <div class="navbar-fixed navbar-mycj">
        <nav class="nav-mycj blue-grey" [ngClass]="{navFixed: navIsFixed}" role="navigation">
            <div class="nav-wrapper container">
                <a id="logo-container" href="#" class="brand-logo position">
                    <img alt="logo mycloudjob" src="./assets/images/mycj/logo-navbar.png">
                </a>
                <ul class="right hide-on-med-and-down">
                    <li><a href="" class="btn blue-grey">Se connecter</a></li>
                    <li><a href="" class="btn pink">S'inscrire</a></li>
                </ul>

                <a href=""
                   [id]="'btnSidenav'"
                   class="button-collapse hide-on-large-only right"><i class="material-icons">menu</i></a>

            </div>
        </nav>
    </div>
</header>

<mz-sidenav
    [id]="'sidenav'"
    [collapseButtonId]="'btnSidenav'">
    <mz-sidenav-header>
        Sidenav header
    </mz-sidenav-header>
    <mz-sidenav-subheader>Link Subheader</mz-sidenav-subheader>
    <mz-sidenav-link>
        <a href="#">First Link</a>
    </mz-sidenav-link>
    <!--<mz-sidenav-divider></mz-sidenav-divider>-->
    <mz-sidenav-link [active]="true">
        <a href="#">Active Link</a>
    </mz-sidenav-link>
    <mz-sidenav-divider></mz-sidenav-divider>
    <mz-sidenav-link>
        <a href="#" class="waves-effect">Second Link With Waves</a>
    </mz-sidenav-link>
</mz-sidenav>

from ngx-materialize.

jfcere avatar jfcere commented on May 21, 2024

@chych the reason why your test fails is because it cannot find the provided collapseButtonId as it does not exist in the context of your test which only include the app-home-sidenav component.

If you absolutely want to keep them seperated you will need to create a fake collapse button element with the exact same button id in your app-home-sidenav test file.

function createCollapseButton(id: string): void {
  const collapseButton = document.createElement('a');
  collapseButton.setAttribute('id', id);
  document.body.appendChild(collapseButton);
}

beforeEach(() => {
  fixture = TestBed.createComponent(HomeSidenavComponent);
  component = fixture.componentInstance;
  // create fake collapse button in DOM before triggering 
  // change detection that initialize the component
  createCollapseButton('btnSidenav');
  fixture.detectChanges();
});

Although this would work I don't suggest you to seperate the collapse button and the sidenav because your test won't assure you that the button is really there at runtime or is really having the right id.

from ngx-materialize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.