Skip to content

Commit

Permalink
refactor: Adjust code according to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LironMShemen committed Oct 30, 2024
1 parent 487aa33 commit f753ed8
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 181 deletions.
39 changes: 38 additions & 1 deletion detox/test/detox_copilot_cache.json

Large diffs are not rendered by default.

107 changes: 69 additions & 38 deletions detox/test/e2e/copilot/07.copilot.assertions.test.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,85 @@
const {describeForCopilotEnv} = require("../utils/custom-describes");
const { describeForCopilotEnv } = require('../utils/custom-describes');
const jestExpect = require('expect').default;

const driver = {
get toggleElement() { return element(by.id('toggle')) },
}

describeForCopilotEnv('Assertions', () => {
beforeAll(async () => {
await copilot.perform('Start the app');
});

beforeEach(async () => {
beforeAll(async () => {
await copilot.perform('Start the app');
});

beforeEach(async () => {
await copilot.perform(
'Restart the React Native state',
'Navigate to the Assertions screen'
);
});

describe('Assertion Tests', () => {
it('should assert an element is visible (by text)', async () => {
await copilot.perform(
'Restart the React Native state',
'Navigate to the Assertions screen'
'Verify there is an element with the text "i contain some text"'
);
});

describe('Assertion Tests', () => {
it('should not assert an element is not visible (by text)', async () => {
await jestExpect(async () =>
await copilot.perform('Verify there is element with the text "Text does not exist" in the Assertions')
).rejects.toThrowError();
});

it('should assert an element is visible', async () => {
it('should assert an element is visible (by id)', async () => {
await copilot.perform(
'Find an element with ID "main-text" in the Assertions',
'Verify that the text of this element is "i contain some text"',
);
'Verify there is an element with ID "subtext-root"'
);
});

it('should assert an element does not exist', async () => {
await jestExpect(async () =>
await copilot.perform('Find an element with ID "RandomJunk959" in the Assertions')
).rejects.toThrowError();
it('should not assert an element that does not exist (by id)', async () => {
await jestExpect(async () =>
await copilot.perform('Find an element with ID "RandomJunk959" in the Assertions')
).rejects.toThrowError();
});

it('should assert an element has (accessibility) label', async () => {
await copilot.perform(
'Find an element with ID "main-text" in the Assertions',
'Verify that the element has an accessibility label "I contain some text"',
);
});

it('assert toggle-switch widget', async () => {
await copilot.perform(
'Find an element with ID "toggle" (call it "the toggle") in the Assertions',
'Verify that the toggle has false value',
'Tap the toggle',
'Verify that the toggle has true value',
);
await expect(driver.toggleElement).toHaveToggleValue(true);
await expect(driver.toggleElement).not.toHaveToggleValue(false);
});
await copilot.perform(
'Verify there is an element with the accessibility label "I contain some text"'
);
});

it('should not assert an element that does not exist (by label)', async () => {
await jestExpect(async () =>
await copilot.perform('Find an element with label "Does not exist" in the Assertions')
).rejects.toThrowError();
});

it('assert toggle exist by element type', async () => {
await copilot.perform(
'Verify that the toggle type element is exist in the Assertions',
);
});

//Note: The checkbox was defined by copilot as toggle at first. Changed it to Check-box type
it('shouldn`t assert an element that does not exist (by type)', async () => {
await jestExpect(async () =>
await copilot.perform('Find a Check-box type element in the Assertions')
).rejects.toThrowError();
});

it('assert toggle-switch widget false', async () => {
await copilot.perform(
'Verify that the toggle has false value',
);

await expect(element(by.id('toggle'))).toHaveToggleValue(false);
await expect(element(by.id('toggle'))).not.toHaveToggleValue(true);
});

it('assert toggle-switch widget true ', async () => {
await copilot.perform(
'Tap the toggle',
'Verify that the toggle has true value'
);

await expect(element(by.id('toggle'))).toHaveToggleValue(true);
await expect(element(by.id('toggle'))).not.toHaveToggleValue(false);
});
});
});
});
117 changes: 48 additions & 69 deletions detox/test/e2e/copilot/08.copilot.location.test.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,57 @@
const {describeForCopilotEnv} = require("../utils/custom-describes");
const { describeForCopilotEnv } = require('../utils/custom-describes');
const DUMMY_COORDINATE1 = '(-80.125, 66.5)';
const DUMMY_COORDINATE2 = '(66.5, -80.125)';

describeForCopilotEnv('Location', () => {
beforeEach(async () => {
await copilot.perform(
'Restart the React Native state',
'Navigate to the Location screen'
);
});

beforeEach(async () => {
describe('Location Tests', () => {
it('should show error when permission defined as `never`', async () => {
await copilot.perform(
'Restart the React Native state',
'Navigate to the Location screen'
'Launch the app with location permission denied',
'Verify there is an element with the text "Get location"',
'Tap the get location element',
'Verify there is an element with the text "User denied access to location services."'
);
});

const tapGetLocationBtn = async () => {
await copilot.perform(
'Verify there is an element with the text "Get location"',
'Tap the get location element',
);
};

const setLocation = async() => {
await copilot.perform(
'Set the device location to (-80.125, 66.5)'
);
}

const setLocation2 = async() => {
await copilot.perform(
'Set the device location to (66.5, -80.125)'
);
}

describe('Location Tests', () => {
it('should show error when permission defined as `never`', async () => {
await copilot.perform(
'Launch the app with location permission denied',
);
await tapGetLocationBtn()
await copilot.perform(
'Verify there is an element with the text "User denied access to location services."',
);
});

it('should show location when permission is `always`', async () => {
await copilot.perform(
'Launch the app with location permission always',
);
await tapGetLocationBtn()
await setLocation()
await copilot.perform(
'Verify that "Latitude: -80.125" is displayed',
'Verify that "Longitude: 66.5" is displayed'
);
});
it('should show location when permission is `always`', async () => {
await copilot.perform(
'Launch the app with location permission always',
'Verify there is an element with the text "Get location"',
'Tap the get location element',
`Set the device location to ${DUMMY_COORDINATE1}`,
'Verify that "Latitude: -80.125" is displayed',
'Verify that "Longitude: 66.5" is displayed'
);
});

it('should show location when permission is `inuse`', async () => {
await copilot.perform(
'Launch the app with location permission just once',
);
await tapGetLocationBtn()
await setLocation()
await copilot.perform(
'Verify that "Latitude: -80.125" is displayed',
'Verify that "Longitude: 66.5" is displayed'
);
});
it('should show location when permission is `inuse`', async () => {
await copilot.perform(
'Launch the app with location permission just once',
'Verify there is an element with the text "Get location"',
'Tap the get location element',
`Set the device location to ${DUMMY_COORDINATE1}`,
'Verify that "Latitude: -80.125" is displayed',
'Verify that "Longitude: 66.5" is displayed'
);
});

it('should set location multiple times', async () => {
await copilot.perform(
'Launch the app with location permission just once',
);
await tapGetLocationBtn()
await setLocation()
await setLocation2()
await copilot.perform(
'Verify that "Latitude: 66.5" is displayed',
'Verify that "Longitude: -80.125" is displayed'
);
});
it('should set location multiple times', async () => {
await copilot.perform(
'Launch the app with location permission just once',
'Verify there is an element with the text "Get location"',
'Tap the get location element',
`Set the device location to ${DUMMY_COORDINATE1}`,
`Set the device location to ${DUMMY_COORDINATE2}`,
'Verify that "Latitude: 66.5" is displayed',
'Verify that "Longitude: -80.125" is displayed'
);
});
});
});
});
120 changes: 49 additions & 71 deletions detox/test/e2e/copilot/09.copilot.datepicker.test.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,62 @@
const {describeForCopilotEnv} = require("../utils/custom-describes");
const { describeForCopilotEnv } = require('../utils/custom-describes');
const { default: jestExpect } = require('expect');

describeForCopilotEnv('DatePicker', () => {
beforeAll(async () => {
await copilot.perform('Start the app');
});
beforeAll(async () => {
await copilot.perform('Start the app');
});

beforeEach(async () => {
await copilot.perform(
'Restart the React Native state',
'Navigate to the DatePicker screen'
);
});

describe('DatePicker Tests', () => {

beforeEach(async () => {
// Note: when writing "Date (UTC):" instead of "Date (UTC): " copilot failed the test
it('correct date and time', async () => {
await copilot.perform(
'Restart the React Native state',
'Navigate to the DatePicker screen'
'Verify there is element with the text "Date (UTC): "',
'Verify the element value of current date UTC July 1st 2023',
'Verify there is element with the text "Time (UTC): "',
'Verify there is element with the text "Time Local: "',
'Verify "Time Local: " value is 7:30 pm'
);
});

describe('DatePicker Tests', () => {

// Note: when writing "Date (UTC):" instead of "Date (UTC): " copilot failed the test
it('correct date and time', async () => {
await copilot.perform(
'Verify there is element with the text "Date (UTC): "',
'Verify the element value of current date UTC July 1st 2023',
'Verify there is element with the text "Time (UTC): "',
'Verify there is element with the text "Time Local: "',
'Verify "Time Local: " value is 7:30 pm',
);
});

// it('compact date picker', async () => {
// await copilot.perform(
// 'Verify there is an element with the text "Compact Date Picker"',
// 'Verify there is an element with today`s date at the bottom of the screen',
// 'Tap the element with today`s date at the bottom of the screen',
// 'Verify that a compact date picker is now display',
// // 'Tap the number 8 inside the compact date picker' - failed
// 'Verify there are numbers from 1 to 28 on the compact date picker screen',
// // 'Set the day to 8'
// );
// console.log('View hierarchy: ', await device.generateViewHierarchyXml());
//
// await copilot.perform(
// 'Tap the element with the text "8"',
// );
// // await web.element(by.web.label('8')).tap();
// });

it('compact date picker', async () => {
await copilot.perform(
'Verify there is an element with the text "Compact Date Picker"',
'Verify there is an element with today`s date at the bottom of the screen',
'Set the date picker to September 9th, 2023',
);
});


it('inline date picker', async () => {
await copilot.perform(
'Verify there is an element with the text "Compact Date Picker"',
'Tap the element with the text "Compact Date Picker"',
'Verify there is an element with the text "Inline Date Picker"',
'Verify there is an element with today`s date at the bottom of the screen',
'Set the date picker to September 9th, 2023',
);
});


it('switch to spinner date picker', async () => {
await copilot.perform(
'Verify there is an element with the text "Compact Date Picker"',
'Tap the element with the text "Compact Date Picker"',
'Verify there is an element with the text "Inline Date Picker"',
'Tap the element with the text "Inline Date Picker"',
'Verify that there is slider element at the bottom of the screen',
'Set the date picker to September 9th, 2023'
);
it('compact date picker', async () => {
await copilot.perform(
'Verify there is an element with the text "Compact Date Picker"',
'Verify there is an element with today`s date at the bottom of the screen',
'Set the date picker to September 9th, 2023'
);
});

await jestExpect(async () =>
await copilot.perform( 'Set the date picker`s first column to 10th, so the date will be September 10th, 2023')
).rejects.toThrowError();
it('inline date picker', async () => {
await copilot.perform(
'Verify there is an element with the text "Compact Date Picker"',
'Tap the element with the text "Compact Date Picker"',
'Verify there is an element with the text "Inline Date Picker"',
'Verify there is an element with today`s date at the bottom of the screen',
'Set the date picker to September 9th, 2023'
);
});

});
it('switch to spinner date picker', async () => {
await copilot.perform(
'Verify there is an element with the text "Compact Date Picker"',
'Tap the element with the text "Compact Date Picker"',
'Verify there is an element with the text "Inline Date Picker"',
'Tap the element with the text "Inline Date Picker"',
'Verify that there is slider element at the bottom of the screen',
'Set the date picker to September 9th, 2023'
);

await jestExpect(async () =>
await copilot.perform('Set the date picker`s first column to 10th, so the date will be September 10th, 2023')
).rejects.toThrowError();
});
});
});
1 change: 0 additions & 1 deletion detox/test/e2e/copilot/10.copilot.visibility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ describeForCopilotEnv('Visibility', () => {
await copilot.perform('Verify the purple rectangle is exactly 26% visible')
).rejects.toThrowError();
});

});
});
});
Loading

0 comments on commit f753ed8

Please sign in to comment.