Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perfect-pens-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Added `setMediaWidth` breakpoints test utility
25 changes: 1 addition & 24 deletions polaris-react/src/components/AlphaCard/tests/AlphaCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import React from 'react';
import {mountWithApp} from 'tests/utilities';
import {matchMedia} from '@shopify/jest-dom-mocks';
import {
BreakpointsTokenName,
breakpoints,
getMediaConditions,
} from '@shopify/polaris-tokens';
import {setMediaWidth} from 'tests/utilities/breakpoints';

import {AlphaCard} from '..';

const mediaConditions = getMediaConditions(breakpoints);

const heading = <p>Online store dashboard</p>;
const subheading = <p>View a summary of your online store performance</p>;

Expand Down Expand Up @@ -53,20 +47,3 @@ describe('AlphaCard', () => {
});
});
});

function setMediaWidth(breakpointsTokenName: BreakpointsTokenName) {
const aliasDirectionConditions = Object.values(
mediaConditions[breakpointsTokenName],
);

jest.spyOn(window, 'matchMedia').mockImplementation((query) => ({
matches: aliasDirectionConditions.includes(query),
media: '',
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
}));
}
24 changes: 24 additions & 0 deletions polaris-react/tests/utilities/breakpoints.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
BreakpointsTokenName,
breakpoints,
getMediaConditions,
} from '@shopify/polaris-tokens';

const mediaConditions = getMediaConditions(breakpoints);

export function setMediaWidth(breakpointsTokenName: BreakpointsTokenName) {
const aliasDirectionConditions = Object.values(
mediaConditions[breakpointsTokenName],
);

jest.spyOn(window, 'matchMedia').mockImplementation((query) => ({
matches: aliasDirectionConditions.includes(query),
media: '',
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
}));
}