Skip to content

Commit

Permalink
update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
tihuan committed Jul 28, 2023
1 parent 1078aaa commit e6728ba
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 80 deletions.
41 changes: 41 additions & 0 deletions fileTransformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const path = require("path");

/**
* (thuang): Inspired by https://github.com/cwmoo740/jest-svg-transformer/issues/3#issuecomment-1229928189
* We export as { ReactComponent }, because we import svg that way
* E.g., import { ReactComponent as IconBacteriaLarge }
*/
module.exports = {
process(_, filePath) {
if (path.extname(filePath) !== ".svg") {
return {
code: `module.exports = ${JSON.stringify(path.basename(filePath))};`,
};
}

const name = `${path.basename(filePath, ".svg")}`
.split(/\W+/)
.map((x) => `${x.charAt(0).toUpperCase()}${x.slice(1)}`)
.join("");

return {
code: `
const React = require('react');
function ${name}(props) {
return React.createElement(
'svg',
Object.assign(
{},
props,
{
'data-file-name': ${name}.name,
'data-testid': ${name}.name,
}
)
);
}
module.exports = { ReactComponent: ${name} };
`,
};
},
};
20 changes: 20 additions & 0 deletions intersectionObserverMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Mock IntersectionObserver
class IntersectionObserver {
observe = jest.fn();

disconnect = jest.fn();

unobserve = jest.fn();
}

Object.defineProperty(window, "IntersectionObserver", {
configurable: true,
value: IntersectionObserver,
writable: true,
});

Object.defineProperty(global, "IntersectionObserver", {
configurable: true,
value: IntersectionObserver,
writable: true,
});
5 changes: 3 additions & 2 deletions jest.common.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = {
moduleDirectories: ["node_modules", "<rootDir>"],
preset: "ts-jest",
setupFiles: ["jest-canvas-mock"],
setupFiles: ["jest-canvas-mock", "../../intersectionObserverMock.js"],
testEnvironment: "jsdom",
transform: {
"^.+\\.svg$": "svg-jest",
"^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"../../fileTransformer.js",
"^.+\\.tsx?$": [
"ts-jest",
{
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
"stylelint": "^13.11.0",
"stylelint-config-recommended": "^3.0.0",
"stylelint-config-standard": "^20.0.0",
"svg-jest": "^1.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.1.3",
"url-loader": "^4.1.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ exports[`<Accordion /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-25m3b5-MuiSvgIcon-root"
data-jest-file-name="IconChevronDownSmall.svg"
data-jest-svg-name="IconChevronDownSmall"
data-file-name="IconChevronDownSmall"
data-testid="IconChevronDownSmall"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ exports[`<Banner /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-25m3b5-MuiSvgIcon-root"
data-jest-file-name="IconInfoCircleLarge.svg"
data-jest-svg-name="IconInfoCircleLarge"
data-file-name="IconInfoCircleLarge"
data-testid="IconInfoCircleLarge"
fillcontrast="white"
focusable="false"
Expand All @@ -40,8 +39,7 @@ exports[`<Banner /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-jest-file-name="IconXMarkSmall.svg"
data-jest-svg-name="IconXMarkSmall"
data-file-name="IconXMarkSmall"
data-testid="IconXMarkSmall"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ exports[`<ButtonDropdown /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-8icru1-MuiSvgIcon-root"
data-jest-file-name="IconDownloadLarge.svg"
data-jest-svg-name="IconDownloadLarge"
data-file-name="IconDownloadLarge"
data-testid="IconDownloadLarge"
fillcontrast="white"
focusable="false"
Expand All @@ -35,8 +34,7 @@ exports[`<ButtonDropdown /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-8icru1-MuiSvgIcon-root"
data-jest-file-name="IconChevronDownSmall.svg"
data-jest-svg-name="IconChevronDownSmall"
data-file-name="IconChevronDownSmall"
data-testid="IconChevronDownSmall"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ exports[`<ButtonIcon /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-jest-file-name="IconDotsHorizontal3Large.svg"
data-jest-svg-name="IconDotsHorizontal3Large"
data-file-name="IconDotsHorizontal3Large"
data-testid="IconDotsHorizontal3Large"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ exports[`<CellHeader /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-jest-file-name="IconChevronDownSmall.svg"
data-jest-svg-name="IconChevronDownSmall"
data-file-name="IconChevronDownSmall"
data-testid="IconChevronDownSmall"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ exports[`<ComplexFilter /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-tr2xv3-MuiSvgIcon-root"
data-jest-file-name="IconChevronDownSmall.svg"
data-jest-svg-name="IconChevronDownSmall"
data-file-name="IconChevronDownSmall"
data-testid="IconChevronDownSmall"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ exports[`<Dialog /> Dialog all sizes match the snapshots 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-jest-file-name="IconXMarkSmall.svg"
data-jest-svg-name="IconXMarkSmall"
data-file-name="IconXMarkSmall"
data-testid="IconXMarkSmall"
fillcontrast="white"
focusable="false"
Expand Down Expand Up @@ -112,8 +111,7 @@ exports[`<Dialog /> Dialog all sizes match the snapshots 4`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-jest-file-name="IconXMarkLarge.svg"
data-jest-svg-name="IconXMarkLarge"
data-file-name="IconXMarkLarge"
data-testid="IconXMarkLarge"
fillcontrast="white"
focusable="false"
Expand Down Expand Up @@ -192,8 +190,7 @@ exports[`<Dialog /> Dialog all sizes match the snapshots 7`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-jest-file-name="IconXMarkLarge.svg"
data-jest-svg-name="IconXMarkLarge"
data-file-name="IconXMarkLarge"
data-testid="IconXMarkLarge"
fillcontrast="white"
focusable="false"
Expand Down Expand Up @@ -272,8 +269,7 @@ exports[`<Dialog /> Dialog all sizes match the snapshots 10`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-jest-file-name="IconXMarkLarge.svg"
data-jest-svg-name="IconXMarkLarge"
data-file-name="IconXMarkLarge"
data-testid="IconXMarkLarge"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ exports[`<Dropdown /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-tr2xv3-MuiSvgIcon-root"
data-jest-file-name="IconChevronDownSmall.svg"
data-jest-svg-name="IconChevronDownSmall"
data-file-name="IconChevronDownSmall"
data-testid="IconChevronDownSmall"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ exports[`<InputCheckbox /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-jest-file-name="IconCheckboxUnchecked.svg"
data-jest-svg-name="IconCheckboxUnchecked"
data-file-name="IconCheckboxUnchecked"
data-testid="IconCheckboxUnchecked"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ exports[`<InputDropdown /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-tr2xv3-MuiSvgIcon-root"
data-jest-file-name="IconChevronDownSmall.svg"
data-jest-svg-name="IconChevronDownSmall"
data-file-name="IconChevronDownSmall"
data-testid="IconChevronDownSmall"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ exports[`<InputRadio /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-jest-file-name="IconRadioChecked.svg"
data-jest-svg-name="IconRadioChecked"
data-file-name="IconRadioChecked"
data-testid="IconRadioChecked"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ exports[`<LoadingIndicator /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-25m3b5-MuiSvgIcon-root"
data-jest-file-name="IconLoadingLarge.svg"
data-jest-svg-name="IconLoadingLarge"
data-file-name="IconLoadingLarge"
data-testid="IconLoadingLarge"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ exports[`<Pagination /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-jest-file-name="IconChevronLeftSmall.svg"
data-jest-svg-name="IconChevronLeftSmall"
data-file-name="IconChevronLeftSmall"
data-testid="IconChevronLeftSmall"
fillcontrast="white"
focusable="false"
Expand Down Expand Up @@ -71,8 +70,7 @@ exports[`<Pagination /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-jest-file-name="IconDotsHorizontal3Small.svg"
data-jest-svg-name="IconDotsHorizontal3Small"
data-file-name="IconDotsHorizontal3Small"
data-testid="IconDotsHorizontal3Small"
fillcontrast="white"
focusable="false"
Expand Down Expand Up @@ -105,8 +103,7 @@ exports[`<Pagination /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-jest-file-name="IconChevronRightSmall.svg"
data-jest-svg-name="IconChevronRightSmall"
data-file-name="IconChevronRightSmall"
data-testid="IconChevronRightSmall"
fillcontrast="white"
focusable="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ exports[`<SegmentedControl /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-8icru1-MuiSvgIcon-root"
data-jest-file-name="IconListSmall.svg"
data-jest-svg-name="IconListSmall"
data-file-name="IconListSmall"
data-testid="IconListSmall"
fillcontrast="white"
focusable="false"
Expand All @@ -51,8 +50,7 @@ exports[`<SegmentedControl /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-8icru1-MuiSvgIcon-root"
data-jest-file-name="IconListSmall.svg"
data-jest-svg-name="IconListSmall"
data-file-name="IconListSmall"
data-testid="IconListSmall"
fillcontrast="white"
focusable="false"
Expand All @@ -79,8 +77,7 @@ exports[`<SegmentedControl /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-8icru1-MuiSvgIcon-root"
data-jest-file-name="IconListSmall.svg"
data-jest-svg-name="IconListSmall"
data-file-name="IconListSmall"
data-testid="IconListSmall"
fillcontrast="white"
focusable="false"
Expand All @@ -107,8 +104,7 @@ exports[`<SegmentedControl /> Default story renders snapshot 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-8icru1-MuiSvgIcon-root"
data-jest-file-name="IconListSmall.svg"
data-jest-svg-name="IconListSmall"
data-file-name="IconListSmall"
data-testid="IconListSmall"
fillcontrast="white"
focusable="false"
Expand Down

0 comments on commit e6728ba

Please sign in to comment.