// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { assert } from 'chai';
import { describeWithEnvironment, } from '../../../testing/EnvironmentHelpers.js';
import * as Recorder from './models.js';
describeWithEnvironment('RecordingStorage', () => {
    beforeEach(() => {
        Recorder.RecordingStorage.RecordingStorage.instance().clearForTest();
    });
    after(() => {
        Recorder.RecordingStorage.RecordingStorage.instance().clearForTest();
    });
    class MockIdGenerator {
        #id = 1;
        next() {
            const result = `recording_${this.#id}`;
            this.#id++;
            return result;
        }
    }
    it('should create and retrieve recordings', async () => {
        const storage = Recorder.RecordingStorage.RecordingStorage.instance();
        storage.setIdGeneratorForTest(new MockIdGenerator());
        const flow1 = { title: 'Test1', steps: [] };
        const flow2 = { title: 'Test2', steps: [] };
        const flow3 = { title: 'Test3', steps: [] };
        assert.deepEqual(await storage.upsertRecording(flow1), {
            storageName: 'recording_1',
            flow: flow1,
        });
        assert.deepEqual(await storage.upsertRecording(flow2), {
            storageName: 'recording_2',
            flow: flow2,
        });
        assert.deepEqual(await storage.getRecordings(), [
            { storageName: 'recording_1', flow: flow1 },
            { storageName: 'recording_2', flow: flow2 },
        ]);
        assert.deepEqual(await storage.getRecording('recording_2'), {
            storageName: 'recording_2',
            flow: flow2,
        });
        assert.isUndefined(await storage.getRecording('recording_3'));
        assert.deepEqual(await storage.upsertRecording(flow3, 'recording_2'), {
            storageName: 'recording_2',
            flow: flow3,
        });
        assert.deepEqual(await storage.getRecording('recording_2'), {
            storageName: 'recording_2',
            flow: flow3,
        });
        await storage.deleteRecording('recording_2');
        assert.deepEqual(await storage.getRecordings(), [
            { storageName: 'recording_1', flow: flow1 },
        ]);
    });
});
//# sourceMappingURL=recording-storage.test.js.map