-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2818 from alphagov/kg-i18n-accordion-attributes
Add support for localisation via data-* attributes to Accordion component
- Loading branch information
Showing
10 changed files
with
395 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
/* eslint-env jest */ | ||
|
||
import { mergeConfigs, extractConfigByNamespace } from './common.mjs' | ||
|
||
// TODO: Write unit tests for `nodeListForEach` and `generateUniqueID` | ||
|
||
describe('Common JS utilities', () => { | ||
describe('mergeConfigs', () => { | ||
const config1 = { | ||
a: 'antelope', | ||
c: { a: 'camel' } | ||
} | ||
const config2 = { | ||
a: 'aardvark', | ||
b: 'bee', | ||
c: { a: 'cat', o: 'cobra' } | ||
} | ||
const config3 = { | ||
b: 'bat', | ||
c: { o: 'cow' }, | ||
d: 'dog' | ||
} | ||
|
||
it('flattens a single object', () => { | ||
const config = mergeConfigs(config1) | ||
expect(config).toEqual({ | ||
a: 'antelope', | ||
'c.a': 'camel' | ||
}) | ||
}) | ||
|
||
it('flattens and merges two objects', () => { | ||
const config = mergeConfigs(config1, config2) | ||
expect(config).toEqual({ | ||
a: 'aardvark', | ||
b: 'bee', | ||
'c.a': 'cat', | ||
'c.o': 'cobra' | ||
}) | ||
}) | ||
|
||
it('flattens and merges three objects', () => { | ||
const config = mergeConfigs(config1, config2, config3) | ||
expect(config).toEqual({ | ||
a: 'aardvark', | ||
b: 'bat', | ||
'c.a': 'cat', | ||
'c.o': 'cow', | ||
d: 'dog' | ||
}) | ||
}) | ||
|
||
it('prioritises the last parameter provided', () => { | ||
const config = mergeConfigs(config1, config2, config3, config1) | ||
expect(config).toEqual({ | ||
a: 'antelope', | ||
b: 'bat', | ||
'c.a': 'camel', | ||
'c.o': 'cow', | ||
d: 'dog' | ||
}) | ||
}) | ||
|
||
it('returns an empty object if no parameters are provided', () => { | ||
const config = mergeConfigs() | ||
expect(config).toEqual({}) | ||
}) | ||
}) | ||
|
||
describe('extractConfigByNamespace', () => { | ||
const flattenedConfig = { | ||
a: 'aardvark', | ||
'b.a': 'bat', | ||
'b.e': 'bear', | ||
'b.o': 'boar', | ||
'c.a': 'camel', | ||
'c.o': 'cow', | ||
d: 'dog', | ||
e: 'elephant' | ||
} | ||
|
||
it('can extract single key-value pairs', () => { | ||
const result = extractConfigByNamespace(flattenedConfig, 'a') | ||
expect(result).toEqual({ a: 'aardvark' }) | ||
}) | ||
|
||
it('can extract multiple key-value pairs', () => { | ||
const result = extractConfigByNamespace(flattenedConfig, 'b') | ||
expect(result).toEqual({ a: 'bat', e: 'bear', o: 'boar' }) | ||
}) | ||
|
||
it('throws an error if no `configObject` is provided', () => { | ||
expect(() => extractConfigByNamespace()).toThrow() | ||
}) | ||
|
||
it('throws an error if no `namespace` is provided', () => { | ||
expect(() => extractConfigByNamespace(flattenedConfig)).toThrow() | ||
}) | ||
}) | ||
}) |
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.