-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add popper changes for v6 (#6482)
- Loading branch information
1 parent
4ba1b01
commit e9b3abb
Showing
19 changed files
with
246 additions
and
28 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
packages/codemods/src/transforms/__testfixtures__/tooltip-container/basic.input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { TooltipContainer } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
return ( | ||
<React.Fragment> | ||
<TooltipContainer>Tooltip</TooltipContainer> | ||
</React.Fragment> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/codemods/src/transforms/__tests__/__snapshots__/tooltip-container.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`tooltip-container transforms correctly 1`] = ` | ||
"import { OnboardingTooltipContainer } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
const App = () => { | ||
return ( | ||
<React.Fragment> | ||
<OnboardingTooltipContainer>Tooltip</OnboardingTooltipContainer> | ||
</React.Fragment> | ||
); | ||
};" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/codemods/src/transforms/__tests__/tooltip-container.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
jest.autoMockOff(); | ||
|
||
import { defineSnapshotTestFromFixture } from '../../testHelpers/testHelper'; | ||
|
||
const name = 'tooltip-container'; | ||
const fixtures = ['basic'] as const; | ||
|
||
describe(name, () => { | ||
fixtures.forEach((test) => | ||
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { API, FileInfo } from 'jscodeshift'; | ||
import { getImportInfo } from '../codemod-helpers'; | ||
import type { JSCodeShiftOptions } from '../types'; | ||
|
||
export const parser = 'tsx'; | ||
|
||
const componentName = 'TooltipContainer'; | ||
const componentNameTo = 'OnboardingTooltipContainer'; | ||
|
||
export default function transformer(file: FileInfo, api: API, options: JSCodeShiftOptions) { | ||
const { alias } = options; | ||
const j = api.jscodeshift; | ||
const source = j(file.source); | ||
const { localName } = getImportInfo(j, file, componentName, alias); | ||
let needRename = true; | ||
|
||
// подменяем импорт | ||
source | ||
.find(j.ImportDeclaration) | ||
.filter((path) => path.node.source.value === alias) | ||
.find(j.ImportSpecifier, { imported: { name: componentName } }) | ||
.forEach((path) => { | ||
j(path).replaceWith((path) => { | ||
if (path.node.local && path.node.local.name !== path.node.imported.name) { | ||
needRename = false; | ||
} | ||
return j.importSpecifier( | ||
j.jsxIdentifier(componentNameTo), | ||
needRename ? null : path.node.local, | ||
); | ||
}); | ||
}); | ||
|
||
source.findJSXElements(localName).forEach((element) => { | ||
// меняем название компонента в JSX на переименованный в импорте (если нужно) | ||
j(element).replaceWith((path) => { | ||
const renamedLocalName = needRename ? componentNameTo : localName; | ||
return j.jsxElement( | ||
j.jsxOpeningElement( | ||
j.jsxIdentifier(renamedLocalName), | ||
path.node.openingElement.attributes, | ||
path.node.closingElement ? false : true, | ||
), | ||
path.node.closingElement ? j.jsxClosingElement(j.jsxIdentifier(renamedLocalName)) : null, | ||
path.node.children, | ||
); | ||
}); | ||
}); | ||
|
||
return source.toSource(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
import * as React from 'react'; | ||
import { baselineComponent } from '../../testing/utils'; | ||
import { Tooltip } from './Tooltip'; | ||
import { render } from '@testing-library/react'; | ||
import { baselineComponent, waitForFloatingPosition } from '../../testing/utils'; | ||
import { Tooltip, TooltipProps } from './Tooltip'; | ||
|
||
describe(Tooltip, () => { | ||
baselineComponent((props) => ( | ||
<Tooltip shown text="test" {...props}> | ||
<div>Target</div> | ||
</Tooltip> | ||
)); | ||
|
||
it('should call onPlacementChange', async () => { | ||
const onPlacementChange = jest.fn(); | ||
|
||
const Fixture = (props: TooltipProps) => ( | ||
<Tooltip defaultShown {...props}> | ||
<div>Target</div> | ||
</Tooltip> | ||
); | ||
|
||
const result = render(<Fixture placement="bottom" onPlacementChange={onPlacementChange} />); | ||
await waitForFloatingPosition(); | ||
|
||
expect(onPlacementChange).not.toHaveBeenCalled(); | ||
|
||
result.rerender(<Fixture placement="auto" onPlacementChange={onPlacementChange} />); | ||
await waitForFloatingPosition(); | ||
|
||
expect(onPlacementChange).toHaveBeenCalledWith('top'); | ||
}); | ||
}); |
Oops, something went wrong.