import { transform } from '../../test-utils'; describe('xcss prop transformation', () => { it('should transform static inline object', () => { const result = transform(` `); expect(result).toMatchInlineSnapshot(` "import * as React from "react"; import { ax, ix, CC, CS } from "@compiled/react/runtime"; const _ = "._syaz5scu{color:red}"; {[_]} {} ; " `); }); it('should throw when not static', () => { expect(() => { transform( ` import { bar } from './foo'; `, { highlightCode: false } ); }).toThrowErrorMatchingInlineSnapshot(` "unknown file: Object given to the xcss prop must be static (4:23). 2 | import { bar } from './foo'; 3 | > 4 | | ^^^^^^^^^^^^^^ 5 | " `); }); it('should transform named xcss prop usage', () => { const result = transform(` `); expect(result).toMatchInlineSnapshot(` "import * as React from "react"; import { ax, ix, CC, CS } from "@compiled/react/runtime"; const _ = "._syaz5scu{color:red}"; {[_]} {} ; " `); }); it('should work with css map', () => { const result = transform(` import { cssMap } from '@compiled/react'; const styles = cssMap({ primary: { color: 'red' }, }); `); expect(result).toMatchInlineSnapshot(` "import * as React from "react"; import { ax, ix, CC, CS } from "@compiled/react/runtime"; const _ = "._syaz5scu{color:red}"; const styles = { primary: "_syaz5scu", }; {[_]} {} ; " `); }); it('should allow ternaries', () => { const result = transform(` import { cssMap } from '@compiled/react'; const styles = cssMap({ primary: { color: 'red' }, secondary: { color: 'blue' } }); `); expect(result).toMatchInlineSnapshot(` "import * as React from "react"; import { ax, ix, CC, CS } from "@compiled/react/runtime"; const _2 = "._syaz13q2{color:blue}"; const _ = "._syaz5scu{color:red}"; const styles = { primary: "_syaz5scu", secondary: "_syaz13q2", }; {[_, _2]} {} ; " `); }); it('should allow concatenating styles', () => { const result = transform(` import { cssMap, j } from '@compiled/react'; const styles = cssMap({ primary: { color: 'red' }, secondary: { color: 'blue' } }); `); expect(result).toMatchInlineSnapshot(` "import * as React from "react"; import { ax, ix, CC, CS } from "@compiled/react/runtime"; import { j } from "@compiled/react"; const _2 = "._syaz13q2{color:blue}"; const _ = "._syaz5scu{color:red}"; const styles = { primary: "_syaz5scu", secondary: "_syaz13q2", }; {[_, _2]} { } ; " `); }); it('should transform xcss prop when compiled is in scope', () => { const result = transform( ` import { cssMap } from '@compiled/react'; const styles = cssMap({ primary: { color: 'red' }, }); ` ); expect(result).toMatchInlineSnapshot(` "import * as React from "react"; import { ax, ix, CC, CS } from "@compiled/react/runtime"; const _ = "._syaz5scu{color:red}"; const styles = { primary: "_syaz5scu", }; {[_]} {} ; " `); }); it('should not blow up transforming an empty xcss object', () => { const result = transform( ` ` ); expect(result).toMatchInlineSnapshot(` "import * as React from "react"; import { ax, ix, CC, CS } from "@compiled/react/runtime"; {[]} {} ; " `); }); it('should ignore primitive components using runtime xcss prop', () => { const result = transform( ` import { Box, xcss } from '@atlaskit/primitives'; ` ); expect(result).toMatchInlineSnapshot(` "import { Box, xcss } from "@atlaskit/primitives"; ; " `); }); it('should only add styles to xcss call sites that use them', () => { const result = transform( ` import { cssMap } from '@compiled/react'; import Button from '@atlaskit/button'; const stylesOne = cssMap({ text: { color: 'red' } }) const stylesTwo = cssMap({ text: { color: 'blue' } }) export function Mixed() { return ( <>