Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danilowoz committed Feb 1, 2022
1 parent 6fe9f09 commit dac3a1f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
8 changes: 1 addition & 7 deletions sandpack-react/src/presets/Sandpack.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import React from "react";

import {
SandpackProvider,
SandpackLayout,
SandpackCodeEditor,
SandpackPreview,
Sandpack,
} from "../";
import { Sandpack } from "../";

export default {
title: "presets/Sandpack: options",
Expand Down
10 changes: 4 additions & 6 deletions sandpack-react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ import type { CodeEditorProps } from ".";

export interface SandpackOptions {
/**
* TODO: Editor state - docs
* List the file path listed in the file tab,
* which will allow the user to interact with.
*/
openPaths?: string[];
/**
* TODO: Editor state -docs
*/
activePath?: string;

/**
* Execution and recompile
* Path to the file will be open in the code editor when the component mounts
*/
activePath?: string;

/**
* This provides a way to control how some components are going to
Expand Down
29 changes: 29 additions & 0 deletions sandpack-react/src/utils/sandpackUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,35 @@ describe(getSandpackStateFromProps, () => {
expect(setup.openPaths.sort()).toEqual(["/App.js"]);
});

/**
* Files - openPaths - activePath
*/
test("openPaths override the files configurations", () => {
const setup = getSandpackStateFromProps({
files: {
A: { hidden: true, code: "" },
B: { hidden: true, code: "" },
},
customSetup: { entry: "A" },
options: { openPaths: ["A", "B"] },
});

expect(setup.openPaths).toEqual(["A", "B"]);
});

test("activePath override the files configurations", () => {
const setup = getSandpackStateFromProps({
files: {
A: { active: true, code: "" },
B: { code: "" },
},
customSetup: { entry: "A" },
options: { activePath: "B" },
});

expect(setup.activePath).toEqual("B");
});

/**
* entry file
*/
Expand Down
5 changes: 1 addition & 4 deletions sandpack-react/src/utils/sandpackUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ type SandpackContextInfo = Pick<
export const getSandpackStateFromProps = (
props: SandpackProviderProps
): SandpackContextInfo => {
const internalTemplate =
typeof props.template === "string" ? props.template : undefined;

// Merge predefined template with custom setup
const projectSetup = getSetup({
template: internalTemplate,
template: props.template,
customSetup: props.customSetup,
files: props.files,
});
Expand Down

0 comments on commit dac3a1f

Please sign in to comment.