Skip to content

Commit

Permalink
test(): Remove main method wrapper from all test files (#494)
Browse files Browse the repository at this point in the history
Closes #480
  • Loading branch information
trik authored and jelbourn committed May 23, 2016
1 parent f428ded commit e8cf256
Show file tree
Hide file tree
Showing 16 changed files with 2,378 additions and 2,385 deletions.
185 changes: 91 additions & 94 deletions src/components/button/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,135 +5,132 @@ import {By} from '@angular/platform-browser';
import {MdButton, MdAnchor} from './button';


describe('MdButton', () => {
let builder: TestComponentBuilder;

beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
builder = tcb;
}));

// General button tests
it('should apply class based on color attribute', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
let aDebugElement = fixture.debugElement.query(By.css('a'));

testComponent.buttonColor = 'primary';
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.classList.contains('md-primary')).toBe(true);
expect(aDebugElement.nativeElement.classList.contains('md-primary')).toBe(true);

testComponent.buttonColor = 'accent';
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.classList.contains('md-accent')).toBe(true);
expect(aDebugElement.nativeElement.classList.contains('md-accent')).toBe(true);
done();
});
});

it('should should not clear previous defined classes', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'));

buttonDebugElement.nativeElement.classList.add('custom-class');

testComponent.buttonColor = 'primary';
fixture.detectChanges();

export function main() {
describe('MdButton', () => {
let builder: TestComponentBuilder;
expect(buttonDebugElement.nativeElement.classList.contains('md-primary')).toBe(true);
expect(buttonDebugElement.nativeElement.classList.contains('custom-class')).toBe(true);

beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
builder = tcb;
}));
testComponent.buttonColor = 'accent';
fixture.detectChanges();

// General button tests
it('should apply class based on color attribute', (done: () => void) => {
expect(buttonDebugElement.nativeElement.classList.contains('md-primary')).toBe(false);
expect(buttonDebugElement.nativeElement.classList.contains('md-accent')).toBe(true);
expect(buttonDebugElement.nativeElement.classList.contains('custom-class')).toBe(true);

done();
});
});

// Regular button tests
describe('button[md-button]', () => {
it('should handle a click on the button', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
let aDebugElement = fixture.debugElement.query(By.css('a'));

testComponent.buttonColor = 'primary';
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.classList.contains('md-primary')).toBe(true);
expect(aDebugElement.nativeElement.classList.contains('md-primary')).toBe(true);

testComponent.buttonColor = 'accent';
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.classList.contains('md-accent')).toBe(true);
expect(aDebugElement.nativeElement.classList.contains('md-accent')).toBe(true);
buttonDebugElement.nativeElement.click();
expect(testComponent.clickCount).toBe(1);
done();
});
});

it('should should not clear previous defined classes', (done: () => void) => {
it('should not increment if disabled', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'));

buttonDebugElement.nativeElement.classList.add('custom-class');

testComponent.buttonColor = 'primary';
fixture.detectChanges();

expect(buttonDebugElement.nativeElement.classList.contains('md-primary')).toBe(true);
expect(buttonDebugElement.nativeElement.classList.contains('custom-class')).toBe(true);

testComponent.buttonColor = 'accent';
testComponent.isDisabled = true;
fixture.detectChanges();

expect(buttonDebugElement.nativeElement.classList.contains('md-primary')).toBe(false);
expect(buttonDebugElement.nativeElement.classList.contains('md-accent')).toBe(true);
expect(buttonDebugElement.nativeElement.classList.contains('custom-class')).toBe(true);
buttonDebugElement.nativeElement.click();

expect(testComponent.clickCount).toBe(0);
done();
});
});

// Regular button tests
describe('button[md-button]', () => {
it('should handle a click on the button', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'));

buttonDebugElement.nativeElement.click();
expect(testComponent.clickCount).toBe(1);
done();
});
});

it('should not increment if disabled', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
});

testComponent.isDisabled = true;
fixture.detectChanges();
// Anchor button tests
describe('a[md-button]', () => {
it('should not redirect if disabled', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'));

buttonDebugElement.nativeElement.click();
testComponent.isDisabled = true;
fixture.detectChanges();

expect(testComponent.clickCount).toBe(0);
done();
});
buttonDebugElement.nativeElement.click();
// will error if page reloads
done();
});

});

// Anchor button tests
describe('a[md-button]', () => {
it('should not redirect if disabled', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'));

testComponent.isDisabled = true;
fixture.detectChanges();
it('should remove tabindex if disabled', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
expect(buttonDebugElement.nativeElement.getAttribute('tabIndex')).toBe(null);

buttonDebugElement.nativeElement.click();
// will error if page reloads
done();
});
testComponent.isDisabled = true;
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('tabIndex')).toBe('-1');
done();
});
});

it('should remove tabindex if disabled', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
expect(buttonDebugElement.nativeElement.getAttribute('tabIndex')).toBe(null);

testComponent.isDisabled = true;
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('tabIndex')).toBe('-1');
done();
});
});
it('should add aria-disabled attribute if disabled', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled')).toBe('false');

it('should add aria-disabled attribute if disabled', (done: () => void) => {
return builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled')).toBe('false');

testComponent.isDisabled = true;
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled')).toBe('true');
done();
});
testComponent.isDisabled = true;
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled')).toBe('true');
done();
});

});

});
}
});

/** Test component that contains an MdButton. */
@Component({
Expand Down
Loading

0 comments on commit e8cf256

Please sign in to comment.