Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress: Fix cy.clock not freezing time #4060

Merged
merged 1 commit into from
Aug 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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