Skip to content

Commit

Permalink
Cypress: Fix cy.clock not freezing time (#4060)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldutra authored Aug 13, 2019
1 parent be142d6 commit 4698408
Showing 1 changed file with 19 additions and 41 deletions.
60 changes: 19 additions & 41 deletions client/cypress/integration/query/parameter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ describe('Parameter', () => {

cy.get('.ant-calendar-date-panel')
.contains('.ant-calendar-date', date)
.click()
.click(); // workaround for datepicker display bug
.click();
};

beforeEach(() => {
Expand All @@ -198,22 +197,18 @@ describe('Parameter', () => {
query: "SELECT '{{test-parameter}}' AS parameter",
options: {
parameters: [
{ name: 'test-parameter', title: 'Test Parameter', type: 'date' },
{ name: 'test-parameter', title: 'Test Parameter', type: 'date', value: null },
],
},
};

createQuery(queryData, false)
.then(({ id }) => cy.visit(`/queries/${id}`));

// make sure parameter is loaded, otherwise cy.clock won't work
cy.getByTestId('ParameterApplyButton')
.should('exist');

const now = new Date();
now.setDate(1);
cy.wrap(now.getTime()).as('now');
cy.clock(now.getTime());
cy.clock(now.getTime(), ['Date']);

createQuery(queryData, false)
.then(({ id }) => cy.visit(`/queries/${id}`));
});

afterEach(() => {
Expand All @@ -232,8 +227,7 @@ describe('Parameter', () => {

it('allows picking a dynamic date', function () {
cy.getByTestId('DynamicButton')
.click()
.click(); // workaround for datepicker display bug
.click();

cy.getByTestId('DynamicButtonMenu')
.contains('Today/Now')
Expand All @@ -258,22 +252,18 @@ describe('Parameter', () => {
query: "SELECT '{{test-parameter}}' AS parameter",
options: {
parameters: [
{ name: 'test-parameter', title: 'Test Parameter', type: 'datetime-local' },
{ name: 'test-parameter', title: 'Test Parameter', type: 'datetime-local', value: null },
],
},
};

createQuery(queryData, false)
.then(({ id }) => cy.visit(`/queries/${id}`));

// make sure parameter is loaded, otherwise cy.clock won't work
cy.getByTestId('ParameterApplyButton')
.should('exist');

const now = new Date();
now.setDate(1);
cy.wrap(now.getTime()).as('now');
cy.clock(now.getTime());
cy.clock(now.getTime(), ['Date']);

createQuery(queryData, false)
.then(({ id }) => cy.visit(`/queries/${id}`));
});

afterEach(() => {
Expand All @@ -288,15 +278,11 @@ describe('Parameter', () => {

cy.get('.ant-calendar-date-panel')
.contains('.ant-calendar-date', '15')
.as('SelectedDate')
.click();

cy.get('.ant-calendar-ok-btn')
.click();

// workaround for datepicker display bug
cy.get('@SelectedDate').click();

cy.getByTestId('ParameterApplyButton')
.click();

Expand All @@ -312,8 +298,7 @@ describe('Parameter', () => {

cy.get('.ant-calendar-date-panel')
.contains('Now')
.click()
.click(); // workaround for datepicker display bug
.click();

cy.getByTestId('ParameterApplyButton')
.click();
Expand All @@ -324,8 +309,7 @@ describe('Parameter', () => {

it('allows picking a dynamic date', function () {
cy.getByTestId('DynamicButton')
.click()
.click(); // workaround for datepicker display bug
.click();

cy.getByTestId('DynamicButtonMenu')
.contains('Today/Now')
Expand Down Expand Up @@ -364,8 +348,7 @@ describe('Parameter', () => {

cy.get('.ant-calendar-date-panel')
.contains('.ant-calendar-date', endDate)
.click()
.click(); // workaround for datepicker display bug
.click();
};

beforeEach(() => {
Expand All @@ -379,17 +362,13 @@ describe('Parameter', () => {
},
};

createQuery(queryData, false)
.then(({ id }) => cy.visit(`/queries/${id}/source`));

// make sure parameter is loaded, otherwise cy.clock won't work
cy.getByTestId('ParameterName-test-parameter')
.should('exist');

const now = new Date();
now.setDate(1);
cy.wrap(now.getTime()).as('now');
cy.clock(now.getTime());
cy.clock(now.getTime(), ['Date']);

createQuery(queryData, false)
.then(({ id }) => cy.visit(`/queries/${id}/source`));
});

afterEach(() => {
Expand All @@ -409,7 +388,6 @@ describe('Parameter', () => {

it('allows picking a dynamic date range', function () {
cy.getByTestId('DynamicButton')
.click()
.click();

cy.getByTestId('DynamicButtonMenu')
Expand Down

0 comments on commit 4698408

Please sign in to comment.