|
@@ -17,7 +17,14 @@ describe( 'FocusCycler', () => {
|
|
|
testUtils.createSinonSandbox();
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ testUtils.sinon.stub( global.window, 'getComputedStyle' );
|
|
|
|
|
+ focusables = new ViewCollection( [
|
|
|
|
|
+ nonFocusable(),
|
|
|
|
|
+ focusable(),
|
|
|
|
|
+ focusable(),
|
|
|
|
|
+ focusable(),
|
|
|
|
|
+ nonFocusable()
|
|
|
|
|
+ ] );
|
|
|
focusTracker = {
|
|
focusTracker = {
|
|
|
focusedElement: null
|
|
focusedElement: null
|
|
|
};
|
|
};
|
|
@@ -25,14 +32,6 @@ describe( 'FocusCycler', () => {
|
|
|
focusables,
|
|
focusables,
|
|
|
focusTracker
|
|
focusTracker
|
|
|
} );
|
|
} );
|
|
|
-
|
|
|
|
|
- testUtils.sinon.stub( global.window, 'getComputedStyle' );
|
|
|
|
|
-
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( focusable() );
|
|
|
|
|
- focusables.add( focusable() );
|
|
|
|
|
- focusables.add( focusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'constructor()', () => {
|
|
describe( 'constructor()', () => {
|
|
@@ -60,12 +59,9 @@ describe( 'FocusCycler', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns null when no focusable items', () => {
|
|
it( 'returns null when no focusable items', () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), nonFocusable() ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
-
|
|
|
|
|
expect( cycler.first ).to.be.null;
|
|
expect( cycler.first ).to.be.null;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -83,12 +79,9 @@ describe( 'FocusCycler', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns null when no focusable items', () => {
|
|
it( 'returns null when no focusable items', () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), nonFocusable() ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
-
|
|
|
|
|
expect( cycler.last ).to.be.null;
|
|
expect( cycler.last ).to.be.null;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -126,23 +119,16 @@ describe( 'FocusCycler', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns null when no focusable items', () => {
|
|
it( 'returns null when no focusable items', () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), nonFocusable() ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
-
|
|
|
|
|
expect( cycler.next ).to.be.null;
|
|
expect( cycler.next ).to.be.null;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns null if the only focusable in focusables', () => {
|
|
it( 'returns null if the only focusable in focusables', () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), focusable(), nonFocusable() ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( focusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
-
|
|
|
|
|
focusTracker.focusedElement = focusables.get( 1 ).element;
|
|
focusTracker.focusedElement = focusables.get( 1 ).element;
|
|
|
|
|
|
|
|
expect( cycler.first ).to.equal( focusables.get( 1 ) );
|
|
expect( cycler.first ).to.equal( focusables.get( 1 ) );
|
|
@@ -176,23 +162,16 @@ describe( 'FocusCycler', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns null when no focusable items', () => {
|
|
it( 'returns null when no focusable items', () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), nonFocusable() ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
-
|
|
|
|
|
expect( cycler.previous ).to.be.null;
|
|
expect( cycler.previous ).to.be.null;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns null if the only focusable in focusables', () => {
|
|
it( 'returns null if the only focusable in focusables', () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), focusable(), nonFocusable() ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( focusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
-
|
|
|
|
|
focusTracker.focusedElement = focusables.get( 1 ).element;
|
|
focusTracker.focusedElement = focusables.get( 1 ).element;
|
|
|
|
|
|
|
|
expect( cycler.first ).to.equal( focusables.get( 1 ) );
|
|
expect( cycler.first ).to.equal( focusables.get( 1 ) );
|
|
@@ -208,12 +187,9 @@ describe( 'FocusCycler', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'does not throw when no focusable items', () => {
|
|
it( 'does not throw when no focusable items', () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), nonFocusable() ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
-
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
cycler.focusFirst();
|
|
cycler.focusFirst();
|
|
|
} ).to.not.throw();
|
|
} ).to.not.throw();
|
|
@@ -231,11 +207,7 @@ describe( 'FocusCycler', () => {
|
|
|
it( 'ignores invisible items', () => {
|
|
it( 'ignores invisible items', () => {
|
|
|
const item = focusable();
|
|
const item = focusable();
|
|
|
|
|
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( focusable( true ) );
|
|
|
|
|
- focusables.add( item );
|
|
|
|
|
-
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), focusable( true ), item ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
cycler.focusFirst();
|
|
cycler.focusFirst();
|
|
@@ -251,12 +223,9 @@ describe( 'FocusCycler', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'does not throw when no focusable items', () => {
|
|
it( 'does not throw when no focusable items', () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), nonFocusable() ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
-
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
cycler.focusLast();
|
|
cycler.focusLast();
|
|
|
} ).to.not.throw();
|
|
} ).to.not.throw();
|
|
@@ -281,12 +250,9 @@ describe( 'FocusCycler', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'does not throw when no focusable items', () => {
|
|
it( 'does not throw when no focusable items', () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), nonFocusable() ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
-
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
cycler.focusNext();
|
|
cycler.focusNext();
|
|
|
} ).to.not.throw();
|
|
} ).to.not.throw();
|
|
@@ -311,12 +277,9 @@ describe( 'FocusCycler', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'does not throw when no focusable items', () => {
|
|
it( 'does not throw when no focusable items', () => {
|
|
|
- focusables = new ViewCollection();
|
|
|
|
|
|
|
+ focusables = new ViewCollection( [ nonFocusable(), nonFocusable() ] );
|
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
cycler = new FocusCycler( { focusables, focusTracker } );
|
|
|
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
- focusables.add( nonFocusable() );
|
|
|
|
|
-
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
cycler.focusPrevious();
|
|
cycler.focusPrevious();
|
|
|
} ).to.not.throw();
|
|
} ).to.not.throw();
|