{"size": 2350, "ext": "js", "max_stars_repo_path": "integration/specs/Modal/modal-1.spec.js", "max_stars_repo_name": "ahmadawais/react-rainbow", "max_stars_repo_stars_event_min_datetime": "2019-10-25T04:12:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-25T04:12:39.000Z", "max_issues_repo_path": "integration/specs/Modal/modal-1.spec.js", "max_issues_repo_name": "ahmadawais/react-rainbow", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "integration/specs/Modal/modal-1.spec.js", "max_forks_repo_name": "ahmadawais/react-rainbow", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 35.0746268657, "max_line_length": 96, "alphanum_fraction": 0.5923404255}
const PageModal = require('../../../src/components/Modal/pageObject');
const { ESCAPE_KEY, TAB_KEY } = require('../../constants');

const BUTTON = '#button-1';
const MODAL = '#modal-1';

describe('Modal base example', () => {
    beforeAll(() => {
        browser.url('/#!/Modal/1');
    });
    beforeEach(() => {
        browser.refresh();
        const component = $(BUTTON);
        component.waitForExist();
    });

    it('should open the modal', () => {
        const modal = new PageModal(MODAL);
        const triggerButton = $(BUTTON);
        triggerButton.click();
        modal.waitUntilOpen();
        expect(modal.isOpen()).toBe(true);
    });
    it('should close the modal when is opened and press ESC', () => {
        const modal = new PageModal(MODAL);
        const triggerButton = $(BUTTON);
        triggerButton.click();
        modal.waitUntilOpen();
        browser.keys(ESCAPE_KEY);
        modal.waitUntilClose();
        expect(modal.isOpen()).toBe(false);
    });
    it.skip('should close the modal when is opened and click the closeButton', () => {
        const modal = new PageModal(MODAL);
        const triggerButton = $(BUTTON);
        triggerButton.click();
        modal.waitUntilOpen();
        modal.clickCloseButton();
        modal.waitUntilClose();
        expect(modal.isOpen()).toBe(false);
    });
    it('should return focus to trigger element when close modal with ESC key', () => {
        const modal = new PageModal(MODAL);
        const triggerButton = $(BUTTON);
        triggerButton.click();
        modal.waitUntilOpen();
        browser.keys(ESCAPE_KEY);
        expect(triggerButton.isFocused()).toBe(true);
    });
    it.skip('should return focus to trigger element when close modal with close button', () => {
        const modal = new PageModal(MODAL);
        const triggerButton = $(BUTTON);
        triggerButton.click();
        modal.waitUntilOpen();
        modal.clickCloseButton();
        expect(triggerButton.isFocused()).toBe(true);
    });
    it('should focus the close button when the modal is opened and press TAB', () => {
        const modal = new PageModal(MODAL);
        const triggerButton = $(BUTTON);
        triggerButton.click();
        modal.waitUntilOpen();
        browser.keys(TAB_KEY);
        expect(modal.hasFocusCloseButton()).toBe(true);
    });
});
