mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 15:18:10 +00:00
Summary: This PR adds filtering for e2e test examples using the new examples filter introduced in https://github.com/facebook/react-native/pull/22777 To do that we: - Add a `testID` to `RNTesterExampleFilter` to select an example - Refactor a few examples to export multiple examples for filtering - Update all tests to filter by example title Pull Request resolved: https://github.com/facebook/react-native/pull/22828 Reviewed By: TheSavior Differential Revision: D13562664 Pulled By: rickhanlonii fbshipit-source-id: efb0ca8050c1ca5c10d96bd77d35dd1143c3a3b3
97 lines
3.2 KiB
JavaScript
97 lines
3.2 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @emails oncall+react_native
|
|
* @format
|
|
*/
|
|
|
|
/* global device, element, by, expect */
|
|
|
|
const jestExpect = require('expect');
|
|
const {
|
|
openComponentWithLabel,
|
|
openExampleWithTitle,
|
|
} = require('../e2e-helpers');
|
|
|
|
describe('Switch', () => {
|
|
beforeAll(async () => {
|
|
await device.reloadReactNative();
|
|
await openComponentWithLabel('<Switch>', '<Switch> Native boolean input');
|
|
});
|
|
|
|
describe('Switches can be set to true or false', () => {
|
|
beforeAll(async () => {
|
|
await openExampleWithTitle('Switches can be set to true or false');
|
|
});
|
|
|
|
it('Switch that starts off should switch', async () => {
|
|
const testID = 'on-off-initial-off';
|
|
const indicatorID = 'on-off-initial-off-indicator';
|
|
|
|
await expect(element(by.id(testID))).toHaveValue('0');
|
|
await expect(element(by.id(indicatorID))).toHaveText('Off');
|
|
await element(by.id(testID)).tap();
|
|
await expect(element(by.id(testID))).toHaveValue('1');
|
|
await expect(element(by.id(indicatorID))).toHaveText('On');
|
|
});
|
|
|
|
it('Switch that starts on should switch', async () => {
|
|
const testID = 'on-off-initial-on';
|
|
const indicatorID = 'on-off-initial-on-indicator';
|
|
|
|
await expect(element(by.id(testID))).toHaveValue('1');
|
|
await expect(element(by.id(indicatorID))).toHaveText('On');
|
|
await element(by.id(testID)).tap();
|
|
await expect(element(by.id(testID))).toHaveValue('0');
|
|
await expect(element(by.id(indicatorID))).toHaveText('Off');
|
|
});
|
|
});
|
|
|
|
describe('Switches can be disabled', () => {
|
|
beforeAll(async () => {
|
|
await openExampleWithTitle('Switches can be disabled');
|
|
});
|
|
|
|
it('disabled switch should not toggle', async () => {
|
|
const onTestID = 'disabled-initial-on';
|
|
const offTestID = 'disabled-initial-off';
|
|
const onIndicatorID = 'disabled-initial-on-indicator';
|
|
const offIndicatorID = 'disabled-initial-off-indicator';
|
|
|
|
await expect(element(by.id(onTestID))).toHaveValue('1');
|
|
await expect(element(by.id(onIndicatorID))).toHaveText('On');
|
|
|
|
try {
|
|
await element(by.id(onTestID)).tap();
|
|
throw new Error('Does not match');
|
|
} catch (err) {
|
|
jestExpect(err.message.message).toEqual(
|
|
jestExpect.stringContaining(
|
|
'Cannot perform action due to constraint(s) failure',
|
|
),
|
|
);
|
|
}
|
|
await expect(element(by.id(onTestID))).toHaveValue('1');
|
|
await expect(element(by.id(onIndicatorID))).toHaveText('On');
|
|
|
|
await expect(element(by.id(offTestID))).toHaveValue('0');
|
|
await expect(element(by.id(offIndicatorID))).toHaveText('Off');
|
|
try {
|
|
await element(by.id(offTestID)).tap();
|
|
throw new Error('Does not match');
|
|
} catch (err) {
|
|
jestExpect(err.message.message).toEqual(
|
|
jestExpect.stringContaining(
|
|
'Cannot perform action due to constraint(s) failure',
|
|
),
|
|
);
|
|
}
|
|
await expect(element(by.id(offTestID))).toHaveValue('0');
|
|
await expect(element(by.id(offIndicatorID))).toHaveText('Off');
|
|
});
|
|
});
|
|
});
|