Skip to content

Commit

Permalink
chore: selector tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelpashkovsky committed May 24, 2022
1 parent 90f04f0 commit 7833dcc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
51 changes: 51 additions & 0 deletions cypress/integration/webapp/timezone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
describe('timezone', () => {
describe('selector', () => {
it('disabled if local time = UTC', () => {
const diff = new Date().getTimezoneOffset();
cy.visit('/');

cy.findByTestId('time-dropdown-button').click();

if (diff === 0) {
cy.get('#select-timezone').should('be.disabled');
} else {
cy.get('#select-timezone').should('not.be.disabled');
}
});

it('has correct values', () => {
cy.visit('/');

cy.findByTestId('time-dropdown-button').click();

cy.get('#select-timezone')
.select(0, { force: true })
.should('have.value', String(new Date().getTimezoneOffset()));

cy.get('#select-timezone')
.select(1, { force: true })
.should('have.value', '0');
});

it('changes what "until"-input renders on setting UTC/local time', () => {
cy.visit('/');
cy.findByTestId('time-dropdown-button').click();
cy.get('#datepicker-until')
.invoke('val')
.then((value) => {
const diff = new Date().getTimezoneOffset();
cy.get('#select-timezone').select(1, { force: true });

if (diff !== 0) {
cy.get('#datepicker-until').should('not.have.value', value);
} else {
cy.get('#datepicker-until').should('have.value', value);
}

cy.get('#select-timezone').select(0, { force: true });

cy.get('#datepicker-until').should('have.value', value);
});
});
});
});
6 changes: 5 additions & 1 deletion webapp/javascript/components/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ function DateRangePicker() {
return (
<div className={opened ? 'drp-container opened' : 'drp-container'}>
<OutsideClickHandler onOutsideClick={hideDropdown}>
<Button icon={faClock} onClick={toggleDropdown}>
<Button
data-testid="time-dropdown-button"
icon={faClock}
onClick={toggleDropdown}
>
{dateToLabel(from, until, offset === 0)}
</Button>
<div className="drp-dropdown">
Expand Down

0 comments on commit 7833dcc

Please sign in to comment.