-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vanita Barrett-Smith
committed
Sep 1, 2022
1 parent
03d4fcc
commit e2e9b98
Showing
2 changed files
with
71 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* eslint-env jest */ | ||
|
||
const path = require('path') | ||
const fileHelper = require('../lib/file-helper') | ||
|
||
describe('getComponentData', () => { | ||
it('returns an error if unable to load component data', () => { | ||
expect(() => { fileHelper.getComponentData('not-a-real-component') }).toThrow(Error) | ||
}) | ||
|
||
it('looks up the correct component path', () => { | ||
jest.spyOn(path, 'join') | ||
|
||
fileHelper.getComponentData('accordion') | ||
|
||
expect(path.join).toHaveBeenCalledWith('src/govuk/components/', 'accordion', 'accordion.yaml') | ||
}) | ||
|
||
it('outputs objects with an array of params and examples', () => { | ||
var componentData = fileHelper.getComponentData('accordion') | ||
|
||
expect(componentData).toEqual(expect.objectContaining({ | ||
params: expect.any(Array), | ||
examples: expect.any(Array) | ||
})) | ||
}) | ||
|
||
it('outputs a param for each object with the expected attributes', () => { | ||
var componentData = fileHelper.getComponentData('accordion') | ||
|
||
componentData.params.forEach((param) => { | ||
expect(param).toEqual( | ||
expect.objectContaining({ | ||
name: expect.any(String), | ||
type: expect.any(String), | ||
required: expect.any(Boolean), | ||
description: expect.any(String) | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
it('contains example objects with the expected attributes', () => { | ||
var componentData = fileHelper.getComponentData('accordion') | ||
|
||
componentData.examples.forEach((example) => { | ||
expect(example).toEqual( | ||
expect.objectContaining({ | ||
name: expect.any(String), | ||
data: expect.any(Object) | ||
}) | ||
) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('fullPageExamples', () => { | ||
it('contains name and path of each example, at a minimum', () => { | ||
var fullPageExamples = fileHelper.fullPageExamples() | ||
|
||
fullPageExamples.forEach((example) => { | ||
expect(example).toEqual( | ||
expect.objectContaining({ | ||
name: expect.any(String), | ||
path: expect.any(String) | ||
}) | ||
) | ||
}) | ||
}) | ||
}) |