Skip to content

Commit

Permalink
chore(demo-cypress): mock fonts to fix flaky Cypress tests (#9765)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsbarsukov authored Nov 20, 2024
1 parent e5aa261 commit 432a486
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
Binary file not shown.
16 changes: 14 additions & 2 deletions projects/demo-cypress/src/support/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ declare global {
}
}

export const stableMount: typeof mount = (component, config) =>
mount(component, {
export const stableMount: typeof mount = (component, config) => {
cy.intercept(
{method: 'GET', resourceType: 'font', url: 'https://fonts.gstatic.com/**'},
{
// Specify `null` as the encoding in order to read the file as a `Buffer` https://docs.cypress.io/api/commands/fixture#Encoding
fixture: 'manrope-fonts.ttf,null',
headers: {
devNotes: 'Mocked by Cypress',
},
},
);

return mount(component, {
...config,
providers: [...(config?.providers || []), NG_EVENT_PLUGINS],
}).then((mountResponse) =>
Expand All @@ -29,5 +40,6 @@ export const stableMount: typeof mount = (component, config) =>
return mountResponse.fixture.whenStable().then(() => mountResponse);
}),
);
};

Cypress.Commands.add('mount', stableMount);
31 changes: 10 additions & 21 deletions projects/demo-cypress/src/tests/input-phone-international.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export class Test implements OnInit {
}

describe('InputPhoneInternational', () => {
beforeEach(() => {
cy.viewport(400, 300);
});

describe('Count form control updates', () => {
let control!: FormControl<string>;

Expand Down Expand Up @@ -151,6 +155,8 @@ describe('InputPhoneInternational', () => {
it('Initially empty textfield => select new country => no form control emits', () => {
cy.get('tui-input-phone-international').click('left');

cy.compareSnapshot('phone-18n-dropdown');

selectCountry('Kazakhstan');

cy.get('@textfield').should('be.focused').should('have.value', '+7 ');
Expand Down Expand Up @@ -249,30 +255,13 @@ describe('InputPhoneInternational', () => {
cy.wait(1);

cy.get('@textfield').should('have.value', '+7 777 777-7777');
cy.get('tui-input-phone-international').compareSnapshot({
name: 'phone-18n-formatted-value',
cypressScreenshotOptions: {padding: 8},
});
});
});
});

describe('debug screenshot testing', () => {
beforeEach(() => {
cy.viewport(400, 300);

cy.mount(Test, {
componentProperties: {
countryIsoCode: 'US',
},
});
});

it('entire page', () => {
cy.get('tui-input-phone-international').click('left');
cy.compareSnapshot('entire-page');
});

it('only textfield', () => {
cy.get('tui-input-phone-international').compareSnapshot('only-textfield');
});
});
});

function initAliases(wrapperSelector: string): void {
Expand Down

0 comments on commit 432a486

Please sign in to comment.