const ruleTester = require("../../ruletester");
import * as rule from "./masthead-structure-changes";
ruleTester.run("masthead-structure-changes", rule, {
valid: [
// no pf import and has NOT had MastheadBrand renamed to MastheadLogo by the masthead-name-changes codemod
{
code: `FooBar`,
},
// no pf import and has had MastheadBrand renamed to MastheadLogo by the masthead-name-changes codemod
{
code: `FooBar`,
},
//toggle already wrapped in MastheadMain and brand double wrapped with data-codemods on the top level, has NOT had MastheadBrand renamed to MastheadLogo by the masthead-name-changes codemod
{
code: `import { Masthead, MastheadBrand, MastheadMain, MastheadToggle } from '@patternfly/react-core'; FooBar`,
},
// toggle already wrapped in MastheadMain and logo wrapped in a brand with data-codemods, has had MastheadBrand renamed to MastheadLogo by the masthead-name-changes codemod
{
code: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core'; FooBar`,
},
],
invalid: [
// stage one of a file that has NOT had MastheadBrand renamed to MastheadLogo by the masthead-name-changes codemod
{
code: `import { Masthead, MastheadBrand, MastheadMain, MastheadToggle } from '@patternfly/react-core'; FooBar`,
output: `import { Masthead, MastheadBrand, MastheadMain, MastheadToggle } from '@patternfly/react-core'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, MastheadToggle should now be wrapped in MastheadMain.`,
type: "JSXOpeningElement",
},
{
message: `The structure of Masthead has been updated, the PF5 MastheadBrand has been renamed to MastheadLogo (this renaming is handled by our masthead-name-changes codemod) and should now be wrapped in a new MastheadBrand.`,
type: "JSXOpeningElement",
},
],
},
// stage two of a file that has NOT had MastheadBrand renamed to MastheadLogo by the masthead-name-changes codemod
{
code: `import { Masthead, MastheadBrand, MastheadMain, MastheadToggle } from '@patternfly/react-core'; FooBar`,
output: `import { Masthead, MastheadBrand, MastheadMain, MastheadToggle } from '@patternfly/react-core'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, the PF5 MastheadBrand has been renamed to MastheadLogo (this renaming is handled by our masthead-name-changes codemod) and should now be wrapped in a new MastheadBrand.`,
type: "JSXOpeningElement",
},
],
},
// stage one of a file that has had MastheadBrand renamed to MastheadLogo by the masthead-name-changes codemod
{
code: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle } from '@patternfly/react-core'; FooBar`,
output: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, MastheadToggle should now be wrapped in MastheadMain.`,
type: "JSXOpeningElement",
},
{
message: `The structure of Masthead has been updated, MastheadLogo should now be wrapped in MastheadBrand.`,
type: "JSXOpeningElement",
},
],
},
// stage two of a file that has had MastheadBrand renamed to MastheadLogo by the masthead-name-changes codemod
{
code: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core'; FooBar`,
output: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, MastheadToggle should now be wrapped in MastheadMain.`,
type: "JSXOpeningElement",
},
],
},
// with aliases
{
code: `import { Masthead as MH, MastheadBrand as MB, MastheadMain as MM, MastheadToggle as MT } from '@patternfly/react-core'; FooBar`,
output: `import { Masthead as MH, MastheadBrand as MB, MastheadMain as MM, MastheadToggle as MT } from '@patternfly/react-core'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, MastheadToggle should now be wrapped in MastheadMain.`,
type: "JSXOpeningElement",
},
{
message: `The structure of Masthead has been updated, the PF5 MastheadBrand has been renamed to MastheadLogo (this renaming is handled by our masthead-name-changes codemod) and should now be wrapped in a new MastheadBrand.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { Masthead as MH, MastheadBrand as MB, MastheadMain as MM, MastheadToggle as MT } from '@patternfly/react-core'; FooBar`,
output: `import { Masthead as MH, MastheadBrand as MB, MastheadMain as MM, MastheadToggle as MT } from '@patternfly/react-core'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, the PF5 MastheadBrand has been renamed to MastheadLogo (this renaming is handled by our masthead-name-changes codemod) and should now be wrapped in a new MastheadBrand.`,
type: "JSXOpeningElement",
},
],
},
// with dist imports
{
code: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle } from '@patternfly/react-core/dist/esm/components/Masthead'; FooBar`,
output: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core/dist/esm/components/Masthead'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, MastheadToggle should now be wrapped in MastheadMain.`,
type: "JSXOpeningElement",
},
{
message: `The structure of Masthead has been updated, MastheadLogo should now be wrapped in MastheadBrand.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core/dist/esm/components/Masthead'; FooBar`,
output: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core/dist/esm/components/Masthead'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, MastheadToggle should now be wrapped in MastheadMain.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle } from '@patternfly/react-core/dist/js/components/Masthead'; FooBar`,
output: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core/dist/js/components/Masthead'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, MastheadToggle should now be wrapped in MastheadMain.`,
type: "JSXOpeningElement",
},
{
message: `The structure of Masthead has been updated, MastheadLogo should now be wrapped in MastheadBrand.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core/dist/js/components/Masthead'; FooBar`,
output: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core/dist/js/components/Masthead'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, MastheadToggle should now be wrapped in MastheadMain.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle } from '@patternfly/react-core/dist/dynamic/components/Masthead'; FooBar`,
output: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core/dist/dynamic/components/Masthead'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, MastheadToggle should now be wrapped in MastheadMain.`,
type: "JSXOpeningElement",
},
{
message: `The structure of Masthead has been updated, MastheadLogo should now be wrapped in MastheadBrand.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core/dist/dynamic/components/Masthead'; FooBar`,
output: `import { Masthead, MastheadLogo, MastheadMain, MastheadToggle, MastheadBrand } from '@patternfly/react-core/dist/dynamic/components/Masthead'; FooBar`,
errors: [
{
message: `The structure of Masthead has been updated, MastheadToggle should now be wrapped in MastheadMain.`,
type: "JSXOpeningElement",
},
],
},
],
});