|
4 | 4 | View,
|
5 | 5 | TextInput,
|
6 | 6 | Text,
|
| 7 | + Modal, |
7 | 8 | } from "react-native";
|
8 | 9 |
|
9 | 10 | import { ElementAssertion } from "../../src/lib/ElementAssertion";
|
@@ -160,4 +161,114 @@ describe("[Unit] ElementAssertion.test.ts", () => {
|
160 | 161 | });
|
161 | 162 | });
|
162 | 163 | });
|
| 164 | + |
| 165 | + describe (".toBeVisible", () => { |
| 166 | + context("when the modal is visible", () => { |
| 167 | + it("returns the assertion instance", () => { |
| 168 | + const element = render( |
| 169 | + <Modal testID="id" visible={true} />, |
| 170 | + ); |
| 171 | + const test = new ElementAssertion(element.getByTestId("id")); |
| 172 | + |
| 173 | + expect(test.toBeVisible()).toBe(test); |
| 174 | + expect(() => test.not.toBeVisible()) |
| 175 | + .toThrowError(AssertionError) |
| 176 | + .toHaveMessage("Expected element <Modal ... /> NOT to be visible."); |
| 177 | + }); |
| 178 | + }); |
| 179 | + |
| 180 | + context("when the element contains 'display' property", () => { |
| 181 | + it("returns the assertion instance", () => { |
| 182 | + const element = render( |
| 183 | + <View testID="id" style={{ display: "flex" }} />, |
| 184 | + ); |
| 185 | + const test = new ElementAssertion(element.getByTestId("id")); |
| 186 | + |
| 187 | + expect(test.toBeVisible()).toBe(test); |
| 188 | + expect(() => test.not.toBeVisible()) |
| 189 | + .toThrowError(AssertionError) |
| 190 | + .toHaveMessage("Expected element <View ... /> NOT to be visible."); |
| 191 | + }); |
| 192 | + }); |
| 193 | + |
| 194 | + context("when the element contains 'accessibilityElementsHidden' property", () => { |
| 195 | + it("returns the assertion instance", () => { |
| 196 | + const element = render( |
| 197 | + <View testID="id" accessibilityElementsHidden={false} />, |
| 198 | + ); |
| 199 | + const test = new ElementAssertion(element.getByTestId("id")); |
| 200 | + |
| 201 | + expect(test.toBeVisible()).toBe(test); |
| 202 | + expect(() => test.not.toBeVisible()) |
| 203 | + .toThrowError(AssertionError) |
| 204 | + .toHaveMessage("Expected element <View ... /> NOT to be visible."); |
| 205 | + }); |
| 206 | + }); |
| 207 | + |
| 208 | + context("when the element contains 'importantForAccessibility' property", () => { |
| 209 | + it("returns the assertion instance", () => { |
| 210 | + const element = render( |
| 211 | + <View testID="id" importantForAccessibility={"yes"} />, |
| 212 | + ); |
| 213 | + const test = new ElementAssertion(element.getByTestId("id")); |
| 214 | + |
| 215 | + expect(test.toBeVisible()).toBe(test); |
| 216 | + expect(() => test.not.toBeVisible()) |
| 217 | + .toThrowError(AssertionError) |
| 218 | + .toHaveMessage("Expected element <View ... /> NOT to be visible."); |
| 219 | + }); |
| 220 | + }); |
| 221 | + |
| 222 | + context("when the parent element contains 'opacity' property", () => { |
| 223 | + context("if parent opacity = 0", () => { |
| 224 | + const element = render( |
| 225 | + <View testID="parentId" style={{ opacity: 0 }} > |
| 226 | + <View testID="childId" style={{ opacity: 1 }} /> |
| 227 | + </View>, |
| 228 | + ); |
| 229 | + |
| 230 | + const parent = new ElementAssertion(element.getByTestId("parentId")); |
| 231 | + const child = new ElementAssertion(element.getByTestId("childId")); |
| 232 | + |
| 233 | + it("returns assertion instance for NOT visible elements", () => { |
| 234 | + expect(parent.not.toBeVisible()).toBeEqual(parent); |
| 235 | + expect(child.not.toBeVisible()).toBeEqual(child); |
| 236 | + }); |
| 237 | + |
| 238 | + it("throws an error for visible elements", () => { |
| 239 | + expect(() => parent.toBeVisible()) |
| 240 | + .toThrowError(AssertionError) |
| 241 | + .toHaveMessage("Expected element <View ... /> to be visible."); |
| 242 | + expect(() => child.toBeVisible()) |
| 243 | + .toThrowError(AssertionError) |
| 244 | + .toHaveMessage("Expected element <View ... /> to be visible."); |
| 245 | + }); |
| 246 | + }); |
| 247 | + |
| 248 | + context("if child opacity = 0", () => { |
| 249 | + const element = render( |
| 250 | + <View testID="parentId" style={{ opacity: 1 }} > |
| 251 | + <View testID="childId" style={{ opacity: 0 }} /> |
| 252 | + </View>, |
| 253 | + ); |
| 254 | + |
| 255 | + const parent = new ElementAssertion(element.getByTestId("parentId")); |
| 256 | + const child = new ElementAssertion(element.getByTestId("childId")); |
| 257 | + |
| 258 | + it("returns assertion instance for NOT visible elements", () => { |
| 259 | + expect(parent.toBeVisible()).toBeEqual(parent); |
| 260 | + expect(child.not.toBeVisible()).toBeEqual(child); |
| 261 | + }); |
| 262 | + |
| 263 | + it("throws an error for visible elements", () => { |
| 264 | + expect(() => parent.not.toBeVisible()) |
| 265 | + .toThrowError(AssertionError) |
| 266 | + .toHaveMessage("Expected element <View ... /> NOT to be visible."); |
| 267 | + expect(() => child.toBeVisible()) |
| 268 | + .toThrowError(AssertionError) |
| 269 | + .toHaveMessage("Expected element <View ... /> to be visible."); |
| 270 | + }); |
| 271 | + }); |
| 272 | + }); |
| 273 | + }); |
163 | 274 | });
|
0 commit comments