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

chore(demo-cypress): mock fonts to fix flaky Cypress tests #9765

Merged
merged 2 commits into from
Nov 20, 2024
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
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',
nsbarsukov marked this conversation as resolved.
Show resolved Hide resolved
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
Loading