|
1 | 1 | import { useNotification } from '../src'; |
2 | 2 | import { fireEvent, render } from '@testing-library/react'; |
3 | 3 | import React from 'react'; |
| 4 | +import NotificationList from '../src/NotificationList'; |
4 | 5 |
|
5 | 6 | require('../assets/index.less'); |
6 | 7 |
|
@@ -130,4 +131,62 @@ describe('stack', () => { |
130 | 131 | notices.every((notice) => notice.style.getPropertyValue('--notification-y') === '0px'), |
131 | 132 | ).toBeTruthy(); |
132 | 133 | }); |
| 134 | + |
| 135 | + it('passes list css gap to list position when expanded', () => { |
| 136 | + const offsetHeightSpy = vi |
| 137 | + .spyOn(HTMLElement.prototype, 'offsetHeight', 'get') |
| 138 | + .mockImplementation(function mockOffsetHeight() { |
| 139 | + return this.classList?.contains('rc-notification-notice-wrapper') ? 50 : 0; |
| 140 | + }); |
| 141 | + const originGetComputedStyle = window.getComputedStyle; |
| 142 | + const getComputedStyleSpy = vi |
| 143 | + .spyOn(window, 'getComputedStyle') |
| 144 | + .mockImplementation((element) => { |
| 145 | + const style = originGetComputedStyle(element); |
| 146 | + |
| 147 | + if ((element as HTMLElement).classList?.contains('rc-notification-list-content')) { |
| 148 | + return new Proxy(style, { |
| 149 | + get(target, prop, receiver) { |
| 150 | + if (prop === 'gap' || prop === 'rowGap') { |
| 151 | + return '8px'; |
| 152 | + } |
| 153 | + |
| 154 | + return Reflect.get(target, prop, receiver); |
| 155 | + }, |
| 156 | + }) as CSSStyleDeclaration; |
| 157 | + } |
| 158 | + |
| 159 | + return style; |
| 160 | + }); |
| 161 | + |
| 162 | + render( |
| 163 | + <NotificationList |
| 164 | + configList={[ |
| 165 | + { |
| 166 | + key: 'first', |
| 167 | + content: <div className="context-content-first">First</div>, |
| 168 | + duration: false, |
| 169 | + }, |
| 170 | + { |
| 171 | + key: 'second', |
| 172 | + content: <div className="context-content-second">Second</div>, |
| 173 | + duration: false, |
| 174 | + }, |
| 175 | + ]} |
| 176 | + />, |
| 177 | + ); |
| 178 | + |
| 179 | + const firstNotice = document |
| 180 | + .querySelector('.context-content-first') |
| 181 | + ?.closest<HTMLElement>('.rc-notification-notice'); |
| 182 | + const secondNotice = document |
| 183 | + .querySelector('.context-content-second') |
| 184 | + ?.closest<HTMLElement>('.rc-notification-notice'); |
| 185 | + |
| 186 | + expect(firstNotice?.style.getPropertyValue('--notification-y')).toBe('58px'); |
| 187 | + expect(secondNotice?.style.getPropertyValue('--notification-y')).toBe('0px'); |
| 188 | + |
| 189 | + getComputedStyleSpy.mockRestore(); |
| 190 | + offsetHeightSpy.mockRestore(); |
| 191 | + }); |
133 | 192 | }); |
0 commit comments