package p.studio.workspaces.editor;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import p.studio.projects.ProjectReference;

import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.*;

final class EditorProjectSnapshotServiceTest {
    @TempDir
    Path tempDir;

    @Test
    void snapshotIncludesHiddenFilesOrdersFoldersFirstAndTagsSourceRoots() throws Exception {
        Files.createDirectories(tempDir.resolve("src"));
        Files.createDirectories(tempDir.resolve("assets"));
        Files.writeString(tempDir.resolve(".env"), "TOKEN=1\n");
        Files.writeString(tempDir.resolve("README.md"), "# project\n");

        final var snapshot = new EditorProjectSnapshotService().createSnapshot(new ProjectReference(
                "Example",
                "1.0.0",
                "pbs",
                1,
                tempDir));

        assertEquals("Example", snapshot.rootNode().displayName());
        assertEquals("assets", snapshot.rootNode().children().get(0).displayName());
        assertEquals("src", snapshot.rootNode().children().get(1).displayName());
        assertEquals(".env", snapshot.rootNode().children().get(2).displayName());
        assertTrue(snapshot.rootNode().children().get(1).taggedSourceRoot());
    }
}
