|
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'; |
5 | 4 |
|
6 | 5 | require('../assets/index.less'); |
7 | 6 |
|
@@ -41,31 +40,8 @@ describe('stack', () => { |
41 | 40 | expect(document.querySelectorAll('.rc-notification-notice')).toHaveLength(5); |
42 | 41 | expect(document.querySelector('.rc-notification-stack-expanded')).toBeFalsy(); |
43 | 42 |
|
44 | | - const notices = Array.from(document.querySelectorAll<HTMLElement>('.rc-notification-notice')); |
45 | | - expect(notices.map((notice) => notice.getAttribute('data-notification-index'))).toEqual([ |
46 | | - '4', |
47 | | - '3', |
48 | | - '2', |
49 | | - '1', |
50 | | - '0', |
51 | | - ]); |
52 | | - expect( |
53 | | - notices |
54 | | - .slice(0, 2) |
55 | | - .every((notice) => !notice.matches('.rc-notification-notice-stack-in-threshold')), |
56 | | - ).toBeTruthy(); |
57 | | - expect( |
58 | | - notices |
59 | | - .slice(2) |
60 | | - .every((notice) => notice.matches('.rc-notification-notice-stack-in-threshold')), |
61 | | - ).toBeTruthy(); |
62 | | - |
63 | 43 | fireEvent.mouseEnter(document.querySelector('.rc-notification-list')); |
64 | 44 | expect(document.querySelector('.rc-notification-stack-expanded')).toBeTruthy(); |
65 | | - expect(document.querySelector('.rc-notification-list-hovered')).toBeTruthy(); |
66 | | - |
67 | | - fireEvent.mouseLeave(document.querySelector('.rc-notification-list')); |
68 | | - expect(document.querySelector('.rc-notification-list-hovered')).toBeFalsy(); |
69 | 45 | }); |
70 | 46 |
|
71 | 47 | it('should collapse when amount is less than threshold', () => { |
@@ -108,133 +84,4 @@ describe('stack', () => { |
108 | 84 | fireEvent.mouseLeave(document.querySelector('.rc-notification-list')); |
109 | 85 | expect(document.querySelector('.rc-notification-stack-expanded')).toBeFalsy(); |
110 | 86 | }); |
111 | | - |
112 | | - it('passes stack offset to list position by bottom edge when collapsed', () => { |
113 | | - const offsetHeightSpy = vi |
114 | | - .spyOn(HTMLElement.prototype, 'offsetHeight', 'get') |
115 | | - .mockImplementation(function mockOffsetHeight() { |
116 | | - if (this.classList?.contains('rc-notification-notice')) { |
117 | | - if (this.querySelector('.context-content-first')) { |
118 | | - return 80; |
119 | | - } |
120 | | - |
121 | | - if (this.querySelector('.context-content-second')) { |
122 | | - return 40; |
123 | | - } |
124 | | - } |
125 | | - |
126 | | - return 0; |
127 | | - }); |
128 | | - |
129 | | - render( |
130 | | - <NotificationList |
131 | | - placement="topRight" |
132 | | - stack={{ threshold: 1, offset: 12 }} |
133 | | - configList={[ |
134 | | - { |
135 | | - key: 'first', |
136 | | - description: <div className="context-content-first">First</div>, |
137 | | - duration: false, |
138 | | - }, |
139 | | - { |
140 | | - key: 'second', |
141 | | - description: <div className="context-content-second">Second</div>, |
142 | | - duration: false, |
143 | | - }, |
144 | | - ]} |
145 | | - />, |
146 | | - ); |
147 | | - |
148 | | - const firstNotice = document |
149 | | - .querySelector('.context-content-first') |
150 | | - ?.closest<HTMLElement>('.rc-notification-notice'); |
151 | | - const secondNotice = document |
152 | | - .querySelector('.context-content-second') |
153 | | - ?.closest<HTMLElement>('.rc-notification-notice'); |
154 | | - const contentNode = document.querySelector<HTMLElement>('.rc-notification-list-content'); |
155 | | - |
156 | | - const getBottom = (notice: HTMLElement | undefined | null) => |
157 | | - (notice ? parseFloat(notice.style.getPropertyValue('--notification-y')) : 0) + |
158 | | - (notice?.offsetHeight ?? 0); |
159 | | - |
160 | | - expect(contentNode?.style.height).toBe('40px'); |
161 | | - expect(firstNotice?.style.getPropertyValue('--notification-y')).toBe('-28px'); |
162 | | - expect(secondNotice?.style.getPropertyValue('--notification-y')).toBe('0px'); |
163 | | - expect(getBottom(firstNotice) - getBottom(secondNotice)).toBe(12); |
164 | | - |
165 | | - fireEvent.mouseEnter(document.querySelector('.rc-notification-list')); |
166 | | - |
167 | | - expect(contentNode?.style.height).toBe('120px'); |
168 | | - expect(firstNotice?.style.getPropertyValue('--notification-y')).toBe('40px'); |
169 | | - expect(secondNotice?.style.getPropertyValue('--notification-y')).toBe('0px'); |
170 | | - |
171 | | - offsetHeightSpy.mockRestore(); |
172 | | - }); |
173 | | - |
174 | | - it('passes list css gap to list position when expanded', () => { |
175 | | - const offsetHeightSpy = vi |
176 | | - .spyOn(HTMLElement.prototype, 'offsetHeight', 'get') |
177 | | - .mockImplementation(function mockOffsetHeight() { |
178 | | - if ( |
179 | | - this.classList?.contains('rc-notification-notice-wrapper') || |
180 | | - this.classList?.contains('rc-notification-notice') |
181 | | - ) { |
182 | | - return 50; |
183 | | - } |
184 | | - |
185 | | - return 0; |
186 | | - }); |
187 | | - const originGetComputedStyle = window.getComputedStyle; |
188 | | - const getComputedStyleSpy = vi |
189 | | - .spyOn(window, 'getComputedStyle') |
190 | | - .mockImplementation((element) => { |
191 | | - const style = originGetComputedStyle(element); |
192 | | - |
193 | | - if ((element as HTMLElement).classList?.contains('rc-notification-list-content')) { |
194 | | - return new Proxy(style, { |
195 | | - get(target, prop, receiver) { |
196 | | - if (prop === 'gap' || prop === 'rowGap') { |
197 | | - return '8px'; |
198 | | - } |
199 | | - |
200 | | - return Reflect.get(target, prop, receiver); |
201 | | - }, |
202 | | - }) as CSSStyleDeclaration; |
203 | | - } |
204 | | - |
205 | | - return style; |
206 | | - }); |
207 | | - |
208 | | - render( |
209 | | - <NotificationList |
210 | | - configList={[ |
211 | | - { |
212 | | - key: 'first', |
213 | | - description: <div className="context-content-first">First</div>, |
214 | | - duration: false, |
215 | | - }, |
216 | | - { |
217 | | - key: 'second', |
218 | | - description: <div className="context-content-second">Second</div>, |
219 | | - duration: false, |
220 | | - }, |
221 | | - ]} |
222 | | - />, |
223 | | - ); |
224 | | - |
225 | | - const firstNotice = document |
226 | | - .querySelector('.context-content-first') |
227 | | - ?.closest<HTMLElement>('.rc-notification-notice'); |
228 | | - const secondNotice = document |
229 | | - .querySelector('.context-content-second') |
230 | | - ?.closest<HTMLElement>('.rc-notification-notice'); |
231 | | - |
232 | | - expect(firstNotice?.getAttribute('data-notification-index')).toBe('1'); |
233 | | - expect(secondNotice?.getAttribute('data-notification-index')).toBe('0'); |
234 | | - expect(firstNotice?.style.getPropertyValue('--notification-y')).toBe('58px'); |
235 | | - expect(secondNotice?.style.getPropertyValue('--notification-y')).toBe('0px'); |
236 | | - |
237 | | - getComputedStyleSpy.mockRestore(); |
238 | | - offsetHeightSpy.mockRestore(); |
239 | | - }); |
240 | 87 | }); |
0 commit comments