|
11 | 11 | /* global device, element, by, expect */ |
12 | 12 |
|
13 | 13 | const jestExpect = require('expect'); |
| 14 | +const { |
| 15 | + openComponentWithLabel, |
| 16 | + openExampleWithTitle, |
| 17 | +} = require('../e2e-helpers'); |
14 | 18 |
|
15 | 19 | describe('Switch', () => { |
16 | | - beforeEach(async () => { |
| 20 | + beforeAll(async () => { |
17 | 21 | await device.reloadReactNative(); |
18 | | - await element(by.id('explorer_search')).replaceText('<Switch>'); |
19 | | - await element(by.label('<Switch> Native boolean input')).tap(); |
| 22 | + await openComponentWithLabel('<Switch>', '<Switch> Native boolean input'); |
20 | 23 | }); |
21 | 24 |
|
22 | | - it('Switch that starts off should switch', async () => { |
23 | | - const testID = 'on-off-initial-off'; |
24 | | - const indicatorID = 'on-off-initial-off-indicator'; |
| 25 | + describe('Switches can be set to true or false', () => { |
| 26 | + beforeAll(async () => { |
| 27 | + await openExampleWithTitle('Switches can be set to true or false'); |
| 28 | + }); |
25 | 29 |
|
26 | | - await expect(element(by.id(testID))).toHaveValue('0'); |
27 | | - await expect(element(by.id(indicatorID))).toHaveText('Off'); |
28 | | - await element(by.id(testID)).tap(); |
29 | | - await expect(element(by.id(testID))).toHaveValue('1'); |
30 | | - await expect(element(by.id(indicatorID))).toHaveText('On'); |
31 | | - }); |
| 30 | + it('Switch that starts off should switch', async () => { |
| 31 | + const testID = 'on-off-initial-off'; |
| 32 | + const indicatorID = 'on-off-initial-off-indicator'; |
| 33 | + |
| 34 | + await expect(element(by.id(testID))).toHaveValue('0'); |
| 35 | + await expect(element(by.id(indicatorID))).toHaveText('Off'); |
| 36 | + await element(by.id(testID)).tap(); |
| 37 | + await expect(element(by.id(testID))).toHaveValue('1'); |
| 38 | + await expect(element(by.id(indicatorID))).toHaveText('On'); |
| 39 | + }); |
32 | 40 |
|
33 | | - it('Switch that starts on should switch', async () => { |
34 | | - const testID = 'on-off-initial-on'; |
35 | | - const indicatorID = 'on-off-initial-on-indicator'; |
| 41 | + it('Switch that starts on should switch', async () => { |
| 42 | + const testID = 'on-off-initial-on'; |
| 43 | + const indicatorID = 'on-off-initial-on-indicator'; |
36 | 44 |
|
37 | | - await expect(element(by.id(testID))).toHaveValue('1'); |
38 | | - await expect(element(by.id(indicatorID))).toHaveText('On'); |
39 | | - await element(by.id(testID)).tap(); |
40 | | - await expect(element(by.id(testID))).toHaveValue('0'); |
41 | | - await expect(element(by.id(indicatorID))).toHaveText('Off'); |
| 45 | + await expect(element(by.id(testID))).toHaveValue('1'); |
| 46 | + await expect(element(by.id(indicatorID))).toHaveText('On'); |
| 47 | + await element(by.id(testID)).tap(); |
| 48 | + await expect(element(by.id(testID))).toHaveValue('0'); |
| 49 | + await expect(element(by.id(indicatorID))).toHaveText('Off'); |
| 50 | + }); |
42 | 51 | }); |
43 | 52 |
|
44 | | - it('disabled switch should not toggle', async () => { |
45 | | - const onTestID = 'disabled-initial-on'; |
46 | | - const offTestID = 'disabled-initial-off'; |
47 | | - const onIndicatorID = 'disabled-initial-on-indicator'; |
48 | | - const offIndicatorID = 'disabled-initial-off-indicator'; |
| 53 | + describe('Switches can be disabled', () => { |
| 54 | + beforeAll(async () => { |
| 55 | + await openExampleWithTitle('Switches can be disabled'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('disabled switch should not toggle', async () => { |
| 59 | + const onTestID = 'disabled-initial-on'; |
| 60 | + const offTestID = 'disabled-initial-off'; |
| 61 | + const onIndicatorID = 'disabled-initial-on-indicator'; |
| 62 | + const offIndicatorID = 'disabled-initial-off-indicator'; |
49 | 63 |
|
50 | | - await expect(element(by.id(onTestID))).toHaveValue('1'); |
51 | | - await expect(element(by.id(onIndicatorID))).toHaveText('On'); |
| 64 | + await expect(element(by.id(onTestID))).toHaveValue('1'); |
| 65 | + await expect(element(by.id(onIndicatorID))).toHaveText('On'); |
52 | 66 |
|
53 | | - try { |
54 | | - await element(by.id(onTestID)).tap(); |
55 | | - throw new Error('Does not match'); |
56 | | - } catch (err) { |
57 | | - jestExpect(err.message.message).toEqual( |
58 | | - jestExpect.stringContaining( |
59 | | - 'Cannot perform action due to constraint(s) failure', |
60 | | - ), |
61 | | - ); |
62 | | - } |
63 | | - await expect(element(by.id(onTestID))).toHaveValue('1'); |
64 | | - await expect(element(by.id(onIndicatorID))).toHaveText('On'); |
| 67 | + try { |
| 68 | + await element(by.id(onTestID)).tap(); |
| 69 | + throw new Error('Does not match'); |
| 70 | + } catch (err) { |
| 71 | + jestExpect(err.message.message).toEqual( |
| 72 | + jestExpect.stringContaining( |
| 73 | + 'Cannot perform action due to constraint(s) failure', |
| 74 | + ), |
| 75 | + ); |
| 76 | + } |
| 77 | + await expect(element(by.id(onTestID))).toHaveValue('1'); |
| 78 | + await expect(element(by.id(onIndicatorID))).toHaveText('On'); |
65 | 79 |
|
66 | | - await expect(element(by.id(offTestID))).toHaveValue('0'); |
67 | | - await expect(element(by.id(offIndicatorID))).toHaveText('Off'); |
68 | | - try { |
69 | | - await element(by.id(offTestID)).tap(); |
70 | | - throw new Error('Does not match'); |
71 | | - } catch (err) { |
72 | | - jestExpect(err.message.message).toEqual( |
73 | | - jestExpect.stringContaining( |
74 | | - 'Cannot perform action due to constraint(s) failure', |
75 | | - ), |
76 | | - ); |
77 | | - } |
78 | | - await expect(element(by.id(offTestID))).toHaveValue('0'); |
79 | | - await expect(element(by.id(offIndicatorID))).toHaveText('Off'); |
| 80 | + await expect(element(by.id(offTestID))).toHaveValue('0'); |
| 81 | + await expect(element(by.id(offIndicatorID))).toHaveText('Off'); |
| 82 | + try { |
| 83 | + await element(by.id(offTestID)).tap(); |
| 84 | + throw new Error('Does not match'); |
| 85 | + } catch (err) { |
| 86 | + jestExpect(err.message.message).toEqual( |
| 87 | + jestExpect.stringContaining( |
| 88 | + 'Cannot perform action due to constraint(s) failure', |
| 89 | + ), |
| 90 | + ); |
| 91 | + } |
| 92 | + await expect(element(by.id(offTestID))).toHaveValue('0'); |
| 93 | + await expect(element(by.id(offIndicatorID))).toHaveText('Off'); |
| 94 | + }); |
80 | 95 | }); |
81 | 96 | }); |
0 commit comments