const ruleTester = require('../../ruletester'); import * as rule from './chip-replace-with-label'; const chipImportError = { message: `Chip has been deprecated. Running the fix flag will replace Chip and ChipGroup components with Label and LabelGroup components respectively.`, type: 'ImportDeclaration', }; ruleTester.run('chip-replace-with-label', rule, { valid: [ { code: ``, }, { code: ``, }, // with import not from the deprecated package { code: `import { Chip, ChipGroup } from '@patternfly/react-core'; `, }, ], invalid: [ { code: `import { Chip } from '@patternfly/react-core/deprecated'; This is a chip`, output: `import { Label } from '@patternfly/react-core'; `, errors: [chipImportError], }, { code: `import { ChipGroup } from '@patternfly/react-core/deprecated'; This is a chipgroup`, output: `import { LabelGroup } from '@patternfly/react-core'; This is a chipgroup`, errors: [chipImportError], }, // with ChipGroup that has numChips { code: `import { ChipGroup } from '@patternfly/react-core/deprecated'; This is a chipgroup`, output: `import { LabelGroup } from '@patternfly/react-core'; This is a chipgroup`, errors: [chipImportError], }, // with Chip nested in ChipGroup { code: `import { Chip, ChipGroup } from '@patternfly/react-core/deprecated'; This is a chip `, output: `import { Label, LabelGroup } from '@patternfly/react-core'; `, errors: [chipImportError], }, // with Chip nested in ChipGroup that has numChips { code: `import { Chip, ChipGroup } from '@patternfly/react-core/deprecated'; This is a chip `, output: `import { Label, LabelGroup } from '@patternfly/react-core'; `, errors: [chipImportError], }, // with aliased Chip and ChipGroup { code: `import { Chip as PFChip, ChipGroup as PFChipGroup } from '@patternfly/react-core/deprecated'; This is a chip `, output: `import { Label, LabelGroup } from '@patternfly/react-core'; `, errors: [chipImportError], }, // with aliased Chip and ChipGroup that has numChips { code: `import { Chip as PFChip, ChipGroup as PFChipGroup } from '@patternfly/react-core/deprecated'; This is a chip `, output: `import { Label, LabelGroup } from '@patternfly/react-core'; `, errors: [chipImportError], }, // with other import specifiers from the deprecated package { code: `import { Chip, Select } from '@patternfly/react-core/deprecated'; This is a chip `, output: `import { Select } from '@patternfly/react-core/deprecated';import { Label } from '@patternfly/react-core'; `, errors: [chipImportError], }, // with Label import already included { code: `import { Label } from '@patternfly/react-core'; import { Chip } from '@patternfly/react-core/deprecated'; <> This is a chip `, output: `import { Label } from '@patternfly/react-core'; <> `, errors: [chipImportError], }, // with LabelGroup import already included { code: `import { LabelGroup } from '@patternfly/react-core'; import { Chip, ChipGroup } from '@patternfly/react-core/deprecated'; <> This is a chip This is a label group `, output: `import { LabelGroup, Label } from '@patternfly/react-core'; <> This is a label group `, errors: [chipImportError], }, // with LabelGroup import already included and ChipGroup that has numChips { code: `import { LabelGroup } from '@patternfly/react-core'; import { Chip, ChipGroup } from '@patternfly/react-core/deprecated'; <> This is a chip This is a label group `, output: `import { LabelGroup, Label } from '@patternfly/react-core'; <> This is a label group `, errors: [chipImportError], }, // with Label and LabelGroup imports already included with aliases { code: `import { Label as PFLabel, LabelGroup as PFLabelGroup } from '@patternfly/react-core'; import { Chip, ChipGroup } from '@patternfly/react-core/deprecated'; <> This is a chip This is a label `, output: `import { Label as PFLabel, LabelGroup as PFLabelGroup } from '@patternfly/react-core'; <> This is a chip This is a label `, errors: [chipImportError], }, // with isReadOnly prop { code: `import { Chip, ChipGroup } from '@patternfly/react-core/deprecated'; <> This is a chip `, output: `import { Label, LabelGroup } from '@patternfly/react-core'; <> `, errors: [chipImportError], }, ], });