Skip to content

Commit

Permalink
More feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeyer2115 committed Oct 25, 2023
1 parent 8c7bd62 commit a466379
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const basicPageState: PageState = {
};

describe("aggregates data as expected", () => {
const orchestrator = createParsingOrchestrator();
const orchestrator = createParsingOrchestrator({ isPagesJS: true });
let studioData: StudioData;

beforeAll(() => {
Expand Down
5 changes: 5 additions & 0 deletions packages/studio-ui/src/utils/PageDataValidator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { PagesRecord } from "../store/models/slices/PageSlice";

export const PAGES_JS_RESERVED_PAGE_NAMES = ["_server", "_client"];

export interface ValidationResult {
valid: boolean;
errorMessages: string[];
Expand Down Expand Up @@ -76,6 +78,9 @@ export default class PageDataValidator {
if (pageName.length > 255) {
errorMessages.push("Page name must be 255 characters or less.");
}
if (this.isPagesJSRepo && PAGES_JS_RESERVED_PAGE_NAMES.includes(pageName)) {
errorMessages.push(`Page name "${pageName}" is a reserved PagesJS filename.`);
}
if (this.pages[pageName]) {
errorMessages.push(`Page name "${pageName}" is already used.`);
}
Expand Down
19 changes: 15 additions & 4 deletions packages/studio-ui/tests/utils/PageDataValidator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import PageDataValidator, {
PAGES_JS_RESERVED_PAGE_NAMES,
ValidationResult,
} from "../../src/utils/PageDataValidator";

Expand Down Expand Up @@ -44,11 +45,12 @@ describe("URL slug validation", () => {
});

describe("page name validation", () => {
const validator = new PageDataValidator({
isEntityPage: false,
isPagesJSRepo: true,
});

function expectPageNameError(input: string, errorMessages: string[]) {
const validator = new PageDataValidator({
isEntityPage: false,
isPagesJSRepo: true,
});
const result: ValidationResult = validator.validate({ pageName: input });
expect(result.valid).toBeFalsy();
expect(result.errorMessages).toEqual(expect.arrayContaining(errorMessages));
Expand All @@ -74,4 +76,13 @@ describe("page name validation", () => {
const errorMessage = "Page name must be 255 characters or less.";
expectPageNameError(longName, [errorMessage]);
});

it("gives an error when using PagesJS Reserved Filenames", () => {
const checkReservedName = (pageName: string) => {
const errorMessage = `Page name "${pageName}" is a reserved PagesJS filename.`;
expectPageNameError(pageName, [errorMessage]);
}

PAGES_JS_RESERVED_PAGE_NAMES.forEach((name) => checkReservedName(name));
});
});

0 comments on commit a466379

Please sign in to comment.