-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into optimize-ci
- Loading branch information
Showing
42 changed files
with
822 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { storiesOf, setAddon, addDecorator, configure, getStorybook } from './preview'; | ||
|
||
export { moduleMetadata } from './preview/angular/decorators'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { moduleMetadata } from './decorators'; | ||
import { addDecorator, storiesOf, clearDecorators, getStorybook } from '..'; | ||
|
||
class MockModule {} | ||
class MockModuleTwo {} | ||
class MockService {} | ||
class MockComponent {} | ||
|
||
describe('moduleMetadata', () => { | ||
it('should add metadata to a story without it', () => { | ||
const result = moduleMetadata({ | ||
imports: [MockModule], | ||
providers: [MockService], | ||
})(() => ({ | ||
component: MockComponent, | ||
})); | ||
|
||
expect(result).toEqual({ | ||
component: MockComponent, | ||
moduleMetadata: { | ||
declarations: [], | ||
entryComponents: [], | ||
imports: [MockModule], | ||
schemas: [], | ||
providers: [MockService], | ||
}, | ||
}); | ||
}); | ||
|
||
it('should combine with individual metadata on a story', () => { | ||
const result = moduleMetadata({ | ||
imports: [MockModule], | ||
})(() => ({ | ||
component: MockComponent, | ||
moduleMetadata: { | ||
imports: [MockModuleTwo], | ||
providers: [MockService], | ||
}, | ||
})); | ||
|
||
expect(result).toEqual({ | ||
component: MockComponent, | ||
moduleMetadata: { | ||
declarations: [], | ||
entryComponents: [], | ||
imports: [MockModule, MockModuleTwo], | ||
schemas: [], | ||
providers: [MockService], | ||
}, | ||
}); | ||
}); | ||
|
||
it('should return the original metadata if passed null', () => { | ||
const result = moduleMetadata(null)(() => ({ | ||
component: MockComponent, | ||
moduleMetadata: { | ||
providers: [MockService], | ||
}, | ||
})); | ||
|
||
expect(result).toEqual({ | ||
component: MockComponent, | ||
moduleMetadata: { | ||
declarations: [], | ||
entryComponents: [], | ||
imports: [], | ||
schemas: [], | ||
providers: [MockService], | ||
}, | ||
}); | ||
}); | ||
|
||
it('should work when added globally', () => { | ||
const metadata = { | ||
declarations: [MockComponent], | ||
providers: [MockService], | ||
entryComponents: [MockComponent], | ||
imports: [MockModule], | ||
}; | ||
|
||
addDecorator(moduleMetadata(metadata)); | ||
|
||
storiesOf('Test', module).add('Default', () => ({ | ||
component: MockComponent, | ||
})); | ||
|
||
const [storybook] = getStorybook(); | ||
|
||
expect(storybook.stories[0].render().moduleMetadata).toEqual({ | ||
declarations: [MockComponent], | ||
providers: [MockService], | ||
entryComponents: [MockComponent], | ||
imports: [MockModule], | ||
schemas: [], | ||
}); | ||
|
||
clearDecorators(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NgModuleMetadata } from './types'; | ||
|
||
export const moduleMetadata = (metadata: Partial<NgModuleMetadata>) => (storyFn: () => any) => { | ||
const story = storyFn(); | ||
const storyMetadata = story.moduleMetadata || {}; | ||
metadata = metadata || {}; | ||
|
||
return { | ||
...story, | ||
moduleMetadata: { | ||
declarations: [...(metadata.declarations || []), ...(storyMetadata.declarations || [])], | ||
entryComponents: [ | ||
...(metadata.entryComponents || []), | ||
...(storyMetadata.entryComponents || []), | ||
], | ||
imports: [...(metadata.imports || []), ...(storyMetadata.imports || [])], | ||
schemas: [...(metadata.schemas || []), ...(storyMetadata.schemas || [])], | ||
providers: [...(metadata.providers || []), ...(storyMetadata.providers || [])], | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function storiesOf(kind: string, module: NodeModule): IApi; | ||
export function setAddon(addon: any): void; | ||
export function addDecorator(decorator: any): IApi; | ||
export function configure(loaders: () => NodeRequire, module: NodeModule): void; | ||
export function getStorybook(): IStoribookSection[]; | ||
export function clearDecorators(): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.