generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 4
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 #77 from eea/develop
Release
- Loading branch information
Showing
14 changed files
with
205 additions
and
40 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
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,109 @@ | ||
import config from '@plone/volto/registry'; | ||
|
||
import { | ||
getColumns, | ||
hasColumns, | ||
forEachColumn, | ||
columnIsEmpty, | ||
empty, | ||
defaultNewColumn, | ||
} from './utils'; | ||
|
||
describe('getColumns', () => { | ||
it('should return an array of column IDs and their corresponding data', () => { | ||
const data = { | ||
blocks_layout: { | ||
items: ['1', '2'], | ||
}, | ||
blocks: { | ||
'1': { name: 'First' }, | ||
'2': { name: 'Second' }, | ||
}, | ||
}; | ||
expect(getColumns(data)).toEqual([ | ||
['1', { name: 'First' }], | ||
['2', { name: 'Second' }], | ||
]); | ||
}); | ||
|
||
it('should return an array of column IDs and their corresponding data', () => { | ||
const data = { | ||
blocks_layout: { | ||
items: undefined, | ||
}, | ||
blocks: { | ||
'1': { name: 'First' }, | ||
'2': { name: 'Second' }, | ||
}, | ||
}; | ||
expect(getColumns(data)).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('hasColumns', () => { | ||
it('should return true if data has columns', () => { | ||
const data = { | ||
blocks_layout: { | ||
items: ['1', '2'], | ||
}, | ||
}; | ||
expect(hasColumns(data)).toBe(true); | ||
}); | ||
|
||
it('should return false if data does not have columns', () => { | ||
const data = {}; | ||
expect(hasColumns(data)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('forEachColumn', () => { | ||
it('should call callback for each column', () => { | ||
const data = { | ||
blocks_layout: { | ||
items: ['1', '2'], | ||
}, | ||
blocks: { | ||
'1': { name: 'First' }, | ||
'2': { name: 'Second' }, | ||
}, | ||
}; | ||
const callback = jest.fn(); | ||
forEachColumn(data, callback); | ||
expect(callback).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
|
||
describe('columnIsEmpty', () => { | ||
it('should return true if column is empty', () => { | ||
const data = {}; | ||
expect(columnIsEmpty(data)).toBe(true); | ||
}); | ||
|
||
it('should return false if column is not empty', () => { | ||
const data = { | ||
blocks_layout: { | ||
items: ['1'], | ||
}, | ||
}; | ||
expect(columnIsEmpty(data)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('empty', () => { | ||
it('should return data for specified number of empty columns', () => { | ||
const result = empty(2); | ||
expect(Object.keys(result.blocks)).toHaveLength(2); | ||
expect(result.blocks_layout.items).toHaveLength(2); | ||
}); | ||
}); | ||
|
||
describe('defaultNewColumn', () => { | ||
it('should return data for new column with default block type', () => { | ||
const result = defaultNewColumn(); | ||
const [id] = Object.keys(result.blocks); | ||
expect(result.blocks[id]['@type']).toEqual( | ||
config.settings.defaultBlockType, | ||
); | ||
expect(result.blocks_layout.items).toEqual([id]); | ||
}); | ||
}); |
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.