<commit_before>const { ArchiveManager: NewArchiveManager, ArchiveSource } = ArchiveManager.v2;

describe("ArchiveManager", function() {
    describe("reorderSource", function() {
        beforeEach(function() {
            this.fakeSource1 = { id: "1", order: 0 };
            this.fakeSource2 = { id: "2", order: 1 };
            this.manager = new NewArchiveManager();
            this.manager.sources.push(this.fakeSource1, this.fakeSource2);
            sinon.stub(this.manager, "reorderSources");
        });

        it("calls to reorder all sources", function() {
            this.manager.reorderSource("1", 1);
            expect(this.manager.reorderSources.calledOnce).to.be.true;
        });

        it("sets the order", function() {
            this.manager.reorderSource("1", 1);
            expect(this.fakeSource1.order).to.equal(1);
        });

        it("reorders items with orders the same or higher", function() {
            this.manager.reorderSource("2", 0);
            expect(this.fakeSource1.order).to.equal(1);
            expect(this.fakeSource2.order).to.equal(0);
        });

        it("throws if there's no source for the provided ID", function() {
            expect(() => {
                this.manager.reorderSource("0", 0);
            }).to.throw(/No source found/i);
        });
    });

    describe("reorderSources", function() {
        beforeEach(function() {
            this.fakeSource1 = { id: "1", order: 2 };
            this.fakeSource2 = { id: "2", order: 0 };
            this.fakeSource3 = { id: "3", order: 1 };
            this.manager = new NewArchiveManager();
            this.manager.sources.push(this.fakeSource1, this.fakeSource2, this.fakeSource3);
            sinon.stub(this.manager, "_emitSourcesListUpdated");
        });

        it("calls to emit sources updated event", function() {
            this.manager.reorderSources();
            expect(this.manager._emitSourcesListUpdated.calledOnce).to.be.true;
        });

        it("sets the correct orders", function() {
            this.manager.reorderSources();
            expect(this.manager.sources).to.have.ordered.members([
                this.fakeSource2,<commit_msg>Add failing test for reordering<commit_after>const { ArchiveManager: NewArchiveManager, ArchiveSource } = ArchiveManager.v2;

describe("ArchiveManager", function() {
    describe("reorderSource", function() {
        beforeEach(function() {
            this.fakeSource1 = { id: "1", order: 0 };
            this.fakeSource2 = { id: "2", order: 1 };
            this.fakeSource3 = { id: "3", order: 2 };
            this.manager = new NewArchiveManager();
            this.manager.sources.push(this.fakeSource1, this.fakeSource2, this.fakeSource3);
            sinon.stub(this.manager, "reorderSources");
        });

        it("calls to reorder all sources", function() {
            this.manager.reorderSource("1", 1);
            expect(this.manager.reorderSources.calledOnce).to.be.true;
        });

        it("sets the order", function() {
            this.manager.reorderSource("1", 1);
            expect(this.fakeSource1.order).to.equal(1);
        });

        it("reorders items with orders the same or higher", function() {
            this.manager.reorderSource("2", 0);
            expect(this.fakeSource1.order).to.equal(1);
            expect(this.fakeSource2.order).to.equal(0);
        });

        it("throws if there's no source for the provided ID", function() {
            expect(() => {
                this.manager.reorderSource("0", 0);
            }).to.throw(/No source found/i);
        });

        it("reorders positions before the moved source", function() {
            this.manager.reorderSource("1", 1);
            this.manager.sources.sort((sourceA, sourceB) => {
                if (sourceA.order > sourceB.order) {
                    return 1;
                } else if (sourceB.order > sourceA.order) {
                    return -1;
                }
                return 0;
            });
            expect(this.manager.sources[1].id).to.equal("1");
        });
    });

    describe("reorderSources", function() {
        beforeEach(function() {
            this.fakeSource1 = { id: "1", order: 2 };
            this.fakeSource2 = { id: "2", order: 0 };
            this.fakeSource3 = { id: "3", order: 1 };
            this.manager = new NewArchiveManager();
            this.manager.sources.push(this.fakeSource1, this.fakeSource2, this.fakeSource3);
            sinon.stub(this.manager, "_emitSourcesListUpdated");
        });

        it("calls to emit sources updated event", function() {
            this.manager.reorderSources();
            expect(this.manager._emitSourcesListUpdated.calledOnce).to.be.true;
        });

        it("sets the correct orders", function() {
            this.manager.reorderSources();
            expect(this.manager.sources).to.have.ordered.members([
                this.fakeSource2,
{'fraction_non_alphanumeric': 0.14233944030601972, 'fraction_numerical': 0.01671028790014093, 'mean_word_length': 2.0704573547589615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3432842', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1357, 'n_words': 264}