Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
(#28) fixed mock injections for axAssets and axConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
x1B committed Aug 22, 2016
1 parent c6a2eff commit abffd3b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Last Changes

- [#28](https://github.com/LaxarJS/laxar-mocks/issues/28): fixed mock injections for axAssets and axConfiguration
- [#27](https://github.com/LaxarJS/laxar-mocks/issues/27): updated for LaxarJS v2.0 compatibility (laxar#358)


Expand Down
22 changes: 14 additions & 8 deletions laxar-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ const nextTick = f => {

const noOp = () => {};

let laxarServices;
let anchorElement;
let adapterInstance;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
Expand All @@ -54,6 +50,13 @@ export const fixtures = {};

export let eventBus;

let adapterInstance;
let adapter;
let anchorElement;
let artifacts;
let configuration;
let laxarServices;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
Expand Down Expand Up @@ -180,8 +183,11 @@ function decoratedAdapter( adapter ) {
return function serviceDecorators() {
return {
...( adapterFactory.serviceDecorators || noOp )(),
axAssets: () => createAxAssetsMock( /* TODO pass artifacts listing */ ),
axConfiguration: () => createAxConfigurationMock( /* TODO pass configuration data */ ),
axAssets: () => {
const { assets } = artifacts.widgets[ 0 ];
return createAxAssetsMock( assets );
},
axConfiguration: () => createAxConfigurationMock( configuration ),
axEventBus: eventBus => {
const methods = [ 'subscribe', 'publish', 'publishAndGatherReplies', 'addInspector' ];
methods.forEach( method => {
Expand Down Expand Up @@ -415,10 +421,10 @@ export function triggerStartupEvents( optionalEvents = {} ) {
*/
export function createSetupForWidget( descriptor, optionalOptions = {} ) {
return done => {
const { artifacts = {}, adapter = plainAdapter, configuration = {} } = {
({ artifacts = {}, adapter = plainAdapter, configuration = {} } = {
...fixtures[ descriptor.name ],
...optionalOptions
};
});

let htmlTemplate;
let features = {};
Expand Down
42 changes: 30 additions & 12 deletions spec/laxar-mocks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ describe( 'A laxar-mocks test runner', () => {
beforeEach( done => {
descriptor = createFakeDescriptor( 'some-activity', 'activity' );
create = jasmine.createSpy( 'widgetModule.create' );
artifacts = createFakeArtifacts( descriptor, {
create,
// TODO (after laxar#358): remove
name: 'some-activity'
} );
artifacts = createFakeArtifacts( descriptor, { create } );
configuration = { baseHref: '/' };
axMocks.createSetupForWidget( descriptor, { artifacts, configuration } )( done );
} );
Expand Down Expand Up @@ -77,10 +73,8 @@ describe( 'A laxar-mocks test runner', () => {
onDomAvailable: () => {}
}) );
artifacts = createFakeArtifacts( descriptor, {
injections: [ 'axFeatures', 'axStorage', 'axLog' ],
create,
// TODO (after laxar#358): remove
name: 'some-widget'
injections: [ 'axFeatures', 'axStorage', 'axLog', 'axConfiguration', 'axAssets' ],
create
} );
configuration = { baseHref: '/' };
axMocks.createSetupForWidget( descriptor, { artifacts, configuration } )( done );
Expand All @@ -99,31 +93,55 @@ describe( 'A laxar-mocks test runner', () => {

it( 'instantiates the widget controller with the requested injections', () => {
expect( create ).toHaveBeenCalled();
const [ features, storage, log ] = create.calls.mostRecent().args;
const [ features, storage, log, configuration, assets ] = create.calls.mostRecent().args;
expect( features ).toEqual( { someFeature: 'someValue', other: 'default' } );
expect( storage.local.setItem ).toEqual( jasmine.any( Function ) );
expect( log.info ).toEqual( jasmine.any( Function ) );
expect( configuration.get ).toEqual( jasmine.any( Function ) );
expect( assets ).toEqual( jasmine.any( Function ) );
} );

/////////////////////////////////////////////////////////////////////////////////////////////////////

it( 'provides a mock-storage injection without side-effects', () => {
expect( create ).toHaveBeenCalled();
const [ , storage ] = create.calls.mostRecent().args;
const storage = create.calls.mostRecent().args[ 1 ];
storage.mockBackends.session.test = '"mockValue"';
expect( storage.session.getItem( 'test' ) ).toEqual( 'mockValue' );
} );

/////////////////////////////////////////////////////////////////////////////////////////////////////

it( 'provides a mock-log injection without side-effects', () => {
const [ , , log ] = create.calls.mostRecent().args;
const log = create.calls.mostRecent().args[ 2 ];
log.error( 'test error' );
expect( log.error ).toHaveBeenCalled();
} );

/////////////////////////////////////////////////////////////////////////////////////////////////////

it( 'provides a mock-configuration injection with the values given to setup', () => {
const configuration = create.calls.mostRecent().args[ 3 ];
expect( configuration.get( 'baseHref' ) ).toEqual( '/' );
expect( configuration.get ).toHaveBeenCalled();
} );

/////////////////////////////////////////////////////////////////////////////////////////////////////

it( 'provides a mock-assets injection with the values given to setup', done => {
const assets = create.calls.mostRecent().args[ 4 ];

assets.forTheme( 'some-widget.html' )
.then( html => {
expect( html ).toEqual( '<h1>hey</h1>' );
} )
.then( done, done.fail );

expect( assets.forTheme ).toHaveBeenCalled();
} );

/////////////////////////////////////////////////////////////////////////////////////////////////////

describe( 'and then to render the widget', () => {

let container;
Expand Down

0 comments on commit abffd3b

Please sign in to comment.