"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const notesSortOrderUtils_1 = require("./notesSortOrderUtils");
const Setting_1 = require("../../models/Setting");
const { shimInit } = require('../../shim-init-node.js');
describe('notesSortOrderUtils', () => {
    beforeAll(() => {
        shimInit();
        Setting_1.default.autoSaveEnabled = false;
    });
    // Disabling as the test doesn't seem very useful.
    // it('should always provide the same ordered fields', async () => {
    // 	const expected = ['user_updated_time', 'user_created_time', 'title', 'order'];
    // 	expect(notesSortOrderFieldArray()).toStrictEqual(expected);
    // 	expect(notesSortOrderFieldArray()).toStrictEqual(expected);
    // });
    it('should provide the next field cyclically', async () => {
        expect((0, notesSortOrderUtils_1.notesSortOrderNextField)('user_updated_time')).toBe('user_created_time');
        expect((0, notesSortOrderUtils_1.notesSortOrderNextField)('order')).toBe('user_updated_time');
    });
    test('setNoteSortOrder(), when perFieldReversalEnabled is false', async () => {
        Setting_1.default.setValue('notes.perFieldReversalEnabled', false);
        // It should set field and reverse of sort order.
        (0, notesSortOrderUtils_1.setNotesSortOrder)('user_created_time', false);
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('user_created_time');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(false);
        (0, notesSortOrderUtils_1.setNotesSortOrder)('user_updated_time', true);
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('user_updated_time');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(true);
        (0, notesSortOrderUtils_1.setNotesSortOrder)('title', true);
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('title');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(true);
        // It should affect the current field of sort order, if arg1 is undefined.
        (0, notesSortOrderUtils_1.setNotesSortOrder)(undefined, false);
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('title');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(false);
        // it should only set field of sort order, if arg2 is undefined.
        (0, notesSortOrderUtils_1.setNotesSortOrder)('user_updated_time');
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('user_updated_time');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(false);
        // It should select the next field, if arg1 and arg2 are undefined.
        (0, notesSortOrderUtils_1.setNotesSortOrder)();
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('user_created_time');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(false);
    });
    test('setNoteSortOrder(), when perFieldReversalEnabled is true', async () => {
        Setting_1.default.setValue('notes.perFieldReversalEnabled', true);
        // It should set field and reverse of sort order.
        (0, notesSortOrderUtils_1.setNotesSortOrder)('user_created_time', false);
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('user_created_time');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(false);
        (0, notesSortOrderUtils_1.setNotesSortOrder)('user_updated_time', true);
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('user_updated_time');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(true);
        (0, notesSortOrderUtils_1.setNotesSortOrder)('title', true);
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('title');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(true);
        // it should affect the current field of sort order, if arg1 is undefined.
        (0, notesSortOrderUtils_1.setNotesSortOrder)(undefined, false);
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('title');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(false);
        // It should remember a reverse state, if arg2 is undefined.
        (0, notesSortOrderUtils_1.setNotesSortOrder)('user_updated_time');
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('user_updated_time');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(true);
        // It should select the next field and remember a reverse state, if arg1 and arg2 are undefined.
        (0, notesSortOrderUtils_1.setNotesSortOrder)();
        expect(Setting_1.default.value('notes.sortOrder.field')).toBe('user_created_time');
        expect(Setting_1.default.value('notes.sortOrder.reverse')).toBe(false);
    });
    it('should not accept an invalid field name', async () => {
        expect(() => (0, notesSortOrderUtils_1.setNotesSortOrder)('hoge', true)).toThrow();
    });
});
//# sourceMappingURL=notesSortOrderUtils.test.js.map