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

fix: [M3-6627] - Fix cy.defer() TypeScript errors #9349

Merged
merged 7 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
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
204 changes: 103 additions & 101 deletions packages/manager/cypress/e2e/core/account/service-transfer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('Account service transfers', () => {
cy.wait(['@getTransfers', '@getTransfers', '@getTransfers']);

// Confirm that pending transfers are displayed in "Pending Service Transfers" panel.
cy.defer(getProfile()).then((profile: Profile) => {
cy.defer(getProfile(), 'getting profile').then((profile: Profile) => {
const dateFormatOptions = { timezone: profile.timezone };
cy.get('[data-qa-panel="Pending Service Transfers"]')
.should('be.visible')
Expand Down Expand Up @@ -248,116 +248,118 @@ describe('Account service transfers', () => {
return linode;
};

cy.defer(setupLinode()).then((linode: Linode) => {
interceptInitiateEntityTransfer().as('initiateTransfer');
cy.defer(setupLinode(), 'creating and booting Linode').then(
(linode: Linode) => {
interceptInitiateEntityTransfer().as('initiateTransfer');

// Navigate to Service Transfer landing page, initiate transfer.
cy.visitWithLogin(serviceTransferLandingUrl);
ui.button
.findByTitle('Make a Service Transfer')
.should('be.visible')
.should('be.enabled')
.click();

cy.findByText('Make a Service Transfer').should('be.visible');
cy.url().should('endWith', serviceTransferCreateUrl);
initiateLinodeTransfer(linode.label);

cy.wait('@initiateTransfer').then((response) => {
const token = response?.response?.body.token;
if (!token) {
throw new Error(
'Failed to retrieve generated transfer token from API response.'
);
}

ui.dialog
.findByTitle('Service Transfer Token')
.should('be.visible')
.within(() => {
// Confirm that user is advised to transfer token using a secure means,
// and that they are informed that the transfer may take up to an hour.
cy.findByText('secure delivery method', { exact: false }).should(
'be.visible'
);
cy.findByText('may take up to an hour', { exact: false }).should(
'be.visible'
);

cy.findByDisplayValue(token).should('be.visible');

// Close dialog.
cy.findByLabelText('Close').should('be.visible').click();
});

// Confirm token is listed on landing page and that correct information
// is shown in modal when token is clicked.
cy.findByText(token)
.should('be.visible')
.closest('tr')
.within(() => {
cy.findByText(token).should('be.visible').click();
});

ui.dialog
.findByTitle('Service Transfer Details')
.should('be.visible')
.within(() => {
cy.findByText(token).should('be.visible');
cy.findByText(linode.id).should('be.visible');
cy.get('[data-qa-close-drawer]').should('be.visible').click();
});

// Attempt to receive the an invalid token.
redeemToken(randomUuid());
assertReceiptError('Not found');

// Attempt to receive previously generated token.
redeemToken(token);
assertReceiptError(
'You cannot initiate a transfer to another user on your account.'
);

// Attempt to generate a new token for the same Linode.
// Navigate to Service Transfer landing page, initiate transfer.
cy.visitWithLogin(serviceTransferLandingUrl);
ui.button
.findByTitle('Make a Service Transfer')
.should('be.visible')
.should('be.enabled')
.click();

cy.findByText('Make a Service Transfer').should('be.visible');
cy.url().should('endWith', serviceTransferCreateUrl);
initiateLinodeTransfer(linode.label);
const errorMessage = `Cannot transfer Linode(s) with ID(s) ${linode.id}: Already pending another transfer request.`;
cy.findByText(errorMessage).should('be.visible');

// Navigate back to landing page and cancel transfer.
cy.contains('a', 'Service Transfers').should('be.visible').click();
cy.url().should('endWith', serviceTransferLandingUrl);

cy.findByText(token)
.should('be.visible')
.closest('tr')
.within(() => {
ui.button
.findByTitle('Cancel')
.should('be.visible')
.should('be.enabled')
.click();
});

ui.dialog
.findByTitle('Cancel this Service Transfer?')
.should('be.visible')
.within(() => {
ui.buttonGroup
.findButtonByTitle('Cancel Service Transfer')
.should('be.visible')
.should('be.enabled')
.click();
});
cy.wait('@initiateTransfer').then((response) => {
const token = response?.response?.body.token;
if (!token) {
throw new Error(
'Failed to retrieve generated transfer token from API response.'
);
}

ui.dialog
.findByTitle('Service Transfer Token')
.should('be.visible')
.within(() => {
// Confirm that user is advised to transfer token using a secure means,
// and that they are informed that the transfer may take up to an hour.
cy.findByText('secure delivery method', { exact: false }).should(
'be.visible'
);
cy.findByText('may take up to an hour', { exact: false }).should(
'be.visible'
);

cy.findByDisplayValue(token).should('be.visible');

// Close dialog.
cy.findByLabelText('Close').should('be.visible').click();
});

// Confirm token is listed on landing page and that correct information
// is shown in modal when token is clicked.
cy.findByText(token)
.should('be.visible')
.closest('tr')
.within(() => {
cy.findByText(token).should('be.visible').click();
});

ui.dialog
.findByTitle('Service Transfer Details')
.should('be.visible')
.within(() => {
cy.findByText(token).should('be.visible');
cy.findByText(linode.id).should('be.visible');
cy.get('[data-qa-close-drawer]').should('be.visible').click();
});

// Attempt to receive the an invalid token.
redeemToken(randomUuid());
assertReceiptError('Not found');

// Attempt to receive previously generated token.
redeemToken(token);
assertReceiptError(
'You cannot initiate a transfer to another user on your account.'
);

ui.toast.assertMessage('Service transfer canceled successfully.');
});
});
// Attempt to generate a new token for the same Linode.
ui.button
.findByTitle('Make a Service Transfer')
.should('be.visible')
.should('be.enabled')
.click();

initiateLinodeTransfer(linode.label);
const errorMessage = `Cannot transfer Linode(s) with ID(s) ${linode.id}: Already pending another transfer request.`;
cy.findByText(errorMessage).should('be.visible');

// Navigate back to landing page and cancel transfer.
cy.contains('a', 'Service Transfers').should('be.visible').click();
cy.url().should('endWith', serviceTransferLandingUrl);

cy.findByText(token)
.should('be.visible')
.closest('tr')
.within(() => {
ui.button
.findByTitle('Cancel')
.should('be.visible')
.should('be.enabled')
.click();
});

ui.dialog
.findByTitle('Cancel this Service Transfer?')
.should('be.visible')
.within(() => {
ui.buttonGroup
.findButtonByTitle('Cancel Service Transfer')
.should('be.visible')
.should('be.enabled')
.click();
});

ui.toast.assertMessage('Service transfer canceled successfully.');
});
}
);
});

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ let cachedGetProfile = {};

// Fetch and cache real profile object.
beforeEach(() => {
cy.defer(getProfile()).then((profile: Profile) => {
cy.defer(getProfile(), 'getting profile').then((profile: Profile) => {
cachedGetProfile = profile;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const createRecords = () => [
authenticate();
describe('Creates Domains record with Form', () => {
beforeEach(() => {
cy.wrap(deleteAllTestDomains());
cy.defer(deleteAllTestDomains(), 'cleaning up test domains');
});

createRecords().forEach((rec) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,69 @@ describe('Delete a Domain', () => {
group: 'test-group',
});

cy.defer(createDomain(domainRequest)).then((domain: Domain) => {
cy.visitWithLogin('/domains');
cy.defer(createDomain(domainRequest), 'creating domain').then(
(domain: Domain) => {
cy.visitWithLogin('/domains');

// Confirm that domain is listed and initiate deletion.
cy.findByText(domain.domain)
.should('be.visible')
.closest('tr')
.within(() => {
ui.actionMenu
.findByTitle(`Action menu for Domain ${domain}`)
.should('be.visible')
.click();
});
ui.actionMenuItem.findByTitle('Delete').should('be.visible').click();
// Confirm that domain is listed and initiate deletion.
cy.findByText(domain.domain)
.should('be.visible')
.closest('tr')
.within(() => {
ui.actionMenu
.findByTitle(`Action menu for Domain ${domain}`)
.should('be.visible')
.click();
});
ui.actionMenuItem.findByTitle('Delete').should('be.visible').click();

// Cancel deletion when prompted to confirm.
ui.dialog
.findByTitle(`Delete Domain ${domain.domain}?`)
.should('be.visible')
.within(() => {
ui.buttonGroup
.findButtonByTitle('Cancel')
.should('be.visible')
.should('be.enabled')
.click();
});
// Cancel deletion when prompted to confirm.
ui.dialog
.findByTitle(`Delete Domain ${domain.domain}?`)
.should('be.visible')
.within(() => {
ui.buttonGroup
.findButtonByTitle('Cancel')
.should('be.visible')
.should('be.enabled')
.click();
});

// Confirm that domain is still listed and initiate deletion again.
cy.findByText(domain.domain)
.should('be.visible')
.closest('tr')
.within(() => {
ui.actionMenu
.findByTitle(`Action menu for Domain ${domain}`)
.should('be.visible')
.click();
});
ui.actionMenuItem.findByTitle('Delete').should('be.visible').click();
// Confirm that domain is still listed and initiate deletion again.
cy.findByText(domain.domain)
.should('be.visible')
.closest('tr')
.within(() => {
ui.actionMenu
.findByTitle(`Action menu for Domain ${domain}`)
.should('be.visible')
.click();
});
ui.actionMenuItem.findByTitle('Delete').should('be.visible').click();

// Confirm deletion.
ui.dialog
.findByTitle(`Delete Domain ${domain.domain}?`)
.should('be.visible')
.within(() => {
// The button should be disabled before confirming the correct domain
ui.buttonGroup
.findButtonByTitle('Delete Domain')
.should('be.visible')
.should('be.disabled');
// Confirm deletion.
ui.dialog
.findByTitle(`Delete Domain ${domain.domain}?`)
.should('be.visible')
.within(() => {
// The button should be disabled before confirming the correct domain
ui.buttonGroup
.findButtonByTitle('Delete Domain')
.should('be.visible')
.should('be.disabled');

containsClick('Domain Name').type(domain.domain);
ui.buttonGroup
.findButtonByTitle('Delete Domain')
.should('be.visible')
.should('be.enabled')
.click();
});
containsClick('Domain Name').type(domain.domain);
ui.buttonGroup
.findButtonByTitle('Delete Domain')
.should('be.visible')
.should('be.enabled')
.click();
});

// Confirm that domain is deleted.
cy.visitWithLogin('/domains');
cy.findByText(domain.domain).should('not.exist');
});
// Confirm that domain is deleted.
cy.visitWithLogin('/domains');
cy.findByText(domain.domain).should('not.exist');
}
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('create firewall', () => {
label: randomLabel(),
};

cy.defer(createLinode(linodeRequest)).then((linode) => {
cy.defer(createLinode(linodeRequest), 'creating Linode').then((linode) => {
interceptCreateFirewall().as('createFirewall');
cy.visitWithLogin('/firewalls/create');

Expand Down
Loading