2024-03-02 17:29:18 +02:00
|
|
|
import { NoteListColumns, defaultListColumns } from '@joplin/lib/services/plugins/api/noteListType';
|
|
|
|
import validateColumns from './validateColumns';
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2024-03-02 17:29:18 +02:00
|
|
|
const makeColumns = (props: any) => {
|
|
|
|
const columns: NoteListColumns = [];
|
|
|
|
for (const p of props) {
|
|
|
|
columns.push({
|
|
|
|
name: 'note.title',
|
|
|
|
width: 100,
|
|
|
|
...p,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return columns;
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('validateColumns', () => {
|
|
|
|
|
|
|
|
test.each([
|
|
|
|
[
|
|
|
|
[{ width: 100 }, { width: 200 }, { width: 0 }],
|
|
|
|
[{ width: 100 }, { width: 200 }, { width: 0 }],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[{ width: 100 }, { width: 200 }, { width: 100 }],
|
|
|
|
[{ width: 100 }, { width: 200 }, { width: 0 }],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[{ width: 0 }, { width: 0 }, { width: 100 }],
|
|
|
|
[{ width: 100 }, { width: 100 }, { width: 0 }],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[],
|
|
|
|
defaultListColumns(),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
null,
|
|
|
|
defaultListColumns(),
|
|
|
|
],
|
|
|
|
])('should drop columns', (columnProps, expectedProps) => {
|
|
|
|
const columns = columnProps ? makeColumns(columnProps) : columnProps;
|
|
|
|
const expected = makeColumns(expectedProps);
|
|
|
|
|
|
|
|
const actual = validateColumns(columns);
|
|
|
|
expect(actual).toEqual(expected);
|
|
|
|
|
|
|
|
const mustBeIdentical = JSON.stringify(columns) === JSON.stringify(expected);
|
|
|
|
|
|
|
|
expect(actual === columns).toBe(mustBeIdentical);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|