diff --git a/jest.conf/setup.js b/jest.conf/setup.js index 07955cc33..fa952be35 100644 --- a/jest.conf/setup.js +++ b/jest.conf/setup.js @@ -1,4 +1,3 @@ -import 'mock-match-media/jest-setup.cjs'; import 'regenerator-runtime/runtime'; import '@testing-library/jest-dom'; import * as Aphrodite from 'aphrodite'; diff --git a/lib/useKResponsiveWindow/__tests__/useKResponsiveWindow.spec.js b/lib/useKResponsiveWindow/__tests__/useKResponsiveWindow.spec.js index 93f666f6d..c320c4565 100644 --- a/lib/useKResponsiveWindow/__tests__/useKResponsiveWindow.spec.js +++ b/lib/useKResponsiveWindow/__tests__/useKResponsiveWindow.spec.js @@ -1,3 +1,4 @@ +import 'mock-match-media/jest-setup.cjs'; import { setMedia } from 'mock-match-media'; import { defineComponent } from '@vue/composition-api'; import { mount } from '@vue/test-utils'; @@ -18,7 +19,7 @@ const TestComponent = () => }, }); -describe('useKWindowDimensions composable', () => { +describe('useKResponsiveWindow composable', () => { beforeEach(() => { setMedia({ width: '1700px', @@ -42,16 +43,74 @@ describe('useKWindowDimensions composable', () => { expect(wrapper.vm.windowIsSmall).toEqual(false); }); - it('check if windowBreakpoint is set on width change', () => { - setMedia({ - width: '480px', + describe('check if windowBreakpoint is set on width change', () => { + it('windowBreakpoint is 0 if width <= 480px', () => { + setMedia({ + width: '400px', + }); + const wrapper = mount(TestComponent()); + expect(wrapper.vm.windowBreakpoint).toEqual(0); + }); + + it('windowBreakpoint is 1 if 480px < width <= 600px', () => { + setMedia({ + width: '540px', + }); + const wrapper = mount(TestComponent()); + expect(wrapper.vm.windowBreakpoint).toEqual(1); + }); + + it('windowBreakpoint is 2 if 600px < width <= 840px', () => { + setMedia({ + width: '800px', + }); + const wrapper = mount(TestComponent()); + expect(wrapper.vm.windowBreakpoint).toEqual(2); + }); + + it('windowBreakpoint is 3 if 840px < width <= 944px', () => { + setMedia({ + width: '944px', + }); + const wrapper = mount(TestComponent()); + expect(wrapper.vm.windowBreakpoint).toEqual(3); + }); + + it('windowBreakpoint is 4 if 944px < width <= 1264px', () => { + setMedia({ + width: '1264px', + }); + const wrapper = mount(TestComponent()); + expect(wrapper.vm.windowBreakpoint).toEqual(4); + }); + + it('windowBreakpoint is 5 if 1264px < width <= 1424px', () => { + setMedia({ + width: '1424px', + }); + const wrapper = mount(TestComponent()); + expect(wrapper.vm.windowBreakpoint).toEqual(5); + }); + + it('windowBreakpoint is 6 if 1424px < width <= 1584px', () => { + setMedia({ + width: '1584px', + }); + const wrapper = mount(TestComponent()); + expect(wrapper.vm.windowBreakpoint).toEqual(6); + }); + + it('windowBreakpoint is 7 if width >= 1601px', () => { + setMedia({ + width: '1800px', + }); + const wrapper = mount(TestComponent()); + expect(wrapper.vm.windowBreakpoint).toEqual(7); }); - const wrapper = mount(TestComponent()); - expect(wrapper.vm.windowBreakpoint).toEqual(0); }); - describe('check if windowIsSmall is set on windowBreakpoint change', () => { - it('windowIsSmall is false if greater than 600px', () => { + describe('check if windowIsSmall is set on width change', () => { + it('windowIsSmall is false if width > 600px', () => { setMedia({ width: '601px', }); @@ -59,7 +118,7 @@ describe('useKWindowDimensions composable', () => { expect(wrapper.vm.windowIsSmall).toEqual(false); }); - it('windowIsSmall is true if less than or equal to 600px', () => { + it('windowIsSmall is true if width <= 600px', () => { setMedia({ width: '600px', }); @@ -68,8 +127,8 @@ describe('useKWindowDimensions composable', () => { }); }); - describe('check if windowIsMedium is set on windowBreakpoint change', () => { - it('windowIsMedium is false if less than or equal to 600px', () => { + describe('check if windowIsMedium is set on width change', () => { + it('windowIsMedium is false if width <= 600px', () => { setMedia({ width: '600px', }); @@ -77,7 +136,7 @@ describe('useKWindowDimensions composable', () => { expect(wrapper.vm.windowIsMedium).toEqual(false); }); - it('windowIsMedium is true if greater than 600px and less than or equal to 840px', () => { + it('windowIsMedium is true if 600px < width >= 840px', () => { setMedia({ width: '700px', }); @@ -86,8 +145,8 @@ describe('useKWindowDimensions composable', () => { }); }); - describe('check if windowIsLarge is set on windowBreakpoint change', () => { - it('windowIsLarge is false if less than to 840px', () => { + describe('check if windowIsLarge is set on width change', () => { + it('windowIsLarge is false if width <= 840px', () => { setMedia({ width: '840px', }); @@ -95,7 +154,7 @@ describe('useKWindowDimensions composable', () => { expect(wrapper.vm.windowIsLarge).toEqual(false); }); - it('windowIsLarge is true if greater than to 840px', () => { + it('windowIsLarge is true if width > 840px', () => { setMedia({ width: '841px', }); @@ -105,7 +164,7 @@ describe('useKWindowDimensions composable', () => { }); describe('check if windowIsShort is set on height change', () => { - it('windowIsShort is false if greater than 600px', () => { + it('windowIsShort is false if height > 600px', () => { setMedia({ height: '601px', }); @@ -113,7 +172,7 @@ describe('useKWindowDimensions composable', () => { expect(wrapper.vm.windowIsShort).toEqual(false); }); - it('windowIsShort is true if less than or equal to 600px', () => { + it('windowIsShort is true if height <= 600px', () => { setMedia({ height: '400px', }); @@ -131,8 +190,8 @@ describe('useKWindowDimensions composable', () => { expect(wrapper.vm.windowIsLandscape).toEqual(false); }); - describe('check if windowGutter is set on windowBreakpoint and windowIsSmall change', () => { - it('windowGutter is 16px if windowIsSmall is true', () => { + describe('check if windowGutter is set on width change', () => { + it('windowGutter is 16px if windowIsSmall is true(width <= 600px)', () => { setMedia({ width: '600px', }); @@ -140,7 +199,7 @@ describe('useKWindowDimensions composable', () => { expect(wrapper.vm.windowIsSmall).toEqual(true); expect(wrapper.vm.windowGutter).toEqual(16); }); - it('windowGutter is 16px if windowBreakpoint < 4 and smallest dimension(width, height) is smaller than 600px', () => { + it('windowGutter is 16px if windowBreakpoint < 4(width < 1264px) and smallest dimension(width, height) is smaller than 600px', () => { setMedia({ width: '500px', }); @@ -148,7 +207,7 @@ describe('useKWindowDimensions composable', () => { expect(wrapper.vm.windowBreakpoint).toEqual(1); expect(wrapper.vm.windowGutter).toEqual(16); }); - it('windowGutter is 24px if windowIsSmall is false, windowBreakpoint > 4 and smallest dimension(width, height) > 600px', () => { + it('windowGutter is 24px if windowIsSmall is false(width > 600px)', () => { setMedia({ width: '841px', });