|
| 1 | +import * as EP from '../../../../core/shared/element-path' |
1 | 2 | import { assertNever } from '../../../../core/shared/utils'
|
| 3 | +import { TailwindConfigPath } from '../../../../core/tailwind/tailwind-config' |
| 4 | +import { createModifiedProject } from '../../../../sample-projects/sample-project-utils.test-utils' |
2 | 5 | import type { Modifiers } from '../../../../utils/modifiers'
|
3 |
| -import { cmdModifier, shiftModifier } from '../../../../utils/modifiers' |
4 |
| -import { expectSingleUndo2Saves, wait } from '../../../../utils/utils.test-utils' |
| 6 | +import { cmdModifier } from '../../../../utils/modifiers' |
| 7 | +import { |
| 8 | + expectSingleUndo2Saves, |
| 9 | + selectComponentsForTest, |
| 10 | + setFeatureForBrowserTestsUseInDescribeBlockOnly, |
| 11 | + wait, |
| 12 | +} from '../../../../utils/utils.test-utils' |
| 13 | +import { StoryboardFilePath } from '../../../editor/store/editor-state' |
5 | 14 | import { cssNumber } from '../../../inspector/common/css-utils'
|
6 | 15 | import type { EdgePiece } from '../../canvas-types'
|
7 | 16 | import { isHorizontalEdgePiece } from '../../canvas-types'
|
@@ -39,6 +48,7 @@ import {
|
39 | 48 | getPrintedUiJsCode,
|
40 | 49 | makeTestProjectCodeWithSnippet,
|
41 | 50 | renderTestEditorWithCode,
|
| 51 | + renderTestEditorWithModel, |
42 | 52 | } from '../../ui-jsx.test-utils'
|
43 | 53 | import { PaddingTearThreshold, SetPaddingStrategyName } from './set-padding-strategy'
|
44 | 54 |
|
@@ -745,6 +755,88 @@ describe('Padding resize strategy', () => {
|
745 | 755 | })
|
746 | 756 | })
|
747 | 757 | })
|
| 758 | + |
| 759 | + describe('Tailwind', () => { |
| 760 | + setFeatureForBrowserTestsUseInDescribeBlockOnly('Tailwind', true) |
| 761 | + |
| 762 | + const TailwindProject = (classes: string) => |
| 763 | + createModifiedProject({ |
| 764 | + [StoryboardFilePath]: ` |
| 765 | + import React from 'react' |
| 766 | + import { Scene, Storyboard } from 'utopia-api' |
| 767 | + export var storyboard = ( |
| 768 | + <Storyboard data-uid='sb'> |
| 769 | + <Scene |
| 770 | + id='scene' |
| 771 | + commentId='scene' |
| 772 | + data-uid='scene' |
| 773 | + style={{ |
| 774 | + width: 700, |
| 775 | + height: 759, |
| 776 | + position: 'absolute', |
| 777 | + left: 212, |
| 778 | + top: 128, |
| 779 | + }} |
| 780 | + > |
| 781 | + <div |
| 782 | + data-uid='mydiv' |
| 783 | + data-testid='mydiv' |
| 784 | + className='top-10 left-10 absolute flex flex-row ${classes}' |
| 785 | + > |
| 786 | + <div className='bg-red-500 w-10 h-10' data-uid='child-1' /> |
| 787 | + <div className='bg-red-500 w-10 h-10' data-uid='child-2' /> |
| 788 | + </div> |
| 789 | + </Scene> |
| 790 | + </Storyboard> |
| 791 | + ) |
| 792 | + |
| 793 | + `, |
| 794 | + [TailwindConfigPath]: ` |
| 795 | + const TailwindConfig = { } |
| 796 | + export default TailwindConfig |
| 797 | + `, |
| 798 | + 'app.css': ` |
| 799 | + @tailwind base; |
| 800 | + @tailwind components; |
| 801 | + @tailwind utilities;`, |
| 802 | + }) |
| 803 | + |
| 804 | + it('can set tailwind padding', async () => { |
| 805 | + const editor = await renderTestEditorWithModel( |
| 806 | + TailwindProject('p-12'), |
| 807 | + 'await-first-dom-report', |
| 808 | + ) |
| 809 | + await selectComponentsForTest(editor, [EP.fromString('sb/scene/mydiv')]) |
| 810 | + await testPaddingResizeForEdge(editor, 50, 'top', 'precise') |
| 811 | + await editor.getDispatchFollowUpActionsFinished() |
| 812 | + const div = editor.renderedDOM.getByTestId('mydiv') |
| 813 | + expect(div.className).toEqual('top-10 left-10 absolute flex flex-row p-[6rem_3rem_3rem_3rem]') |
| 814 | + }) |
| 815 | + |
| 816 | + it('can remove tailwind padding', async () => { |
| 817 | + const editor = await renderTestEditorWithModel( |
| 818 | + TailwindProject('p-4'), |
| 819 | + 'await-first-dom-report', |
| 820 | + ) |
| 821 | + await selectComponentsForTest(editor, [EP.fromString('sb/scene/mydiv')]) |
| 822 | + await testPaddingResizeForEdge(editor, -150, 'top', 'precise') |
| 823 | + await editor.getDispatchFollowUpActionsFinished() |
| 824 | + const div = editor.renderedDOM.getByTestId('mydiv') |
| 825 | + expect(div.className).toEqual('top-10 left-10 absolute flex flex-row pb-4 pl-4 pr-4') |
| 826 | + }) |
| 827 | + |
| 828 | + it('can set tailwind padding longhand', async () => { |
| 829 | + const editor = await renderTestEditorWithModel( |
| 830 | + TailwindProject('pt-12'), |
| 831 | + 'await-first-dom-report', |
| 832 | + ) |
| 833 | + await selectComponentsForTest(editor, [EP.fromString('sb/scene/mydiv')]) |
| 834 | + await testPaddingResizeForEdge(editor, 50, 'top', 'precise') |
| 835 | + await editor.getDispatchFollowUpActionsFinished() |
| 836 | + const div = editor.renderedDOM.getByTestId('mydiv') |
| 837 | + expect(div.className).toEqual('top-10 left-10 absolute flex flex-row pt-24') |
| 838 | + }) |
| 839 | + }) |
748 | 840 | })
|
749 | 841 |
|
750 | 842 | async function testAdjustIndividualPaddingValue(edge: EdgePiece, precision: AdjustPrecision) {
|
|
0 commit comments