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

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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.
11 changes: 9 additions & 2 deletions projects/demo-cypress/src/support/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ declare global {
}
}

export const stableMount: typeof mount = (component, config) =>
mount(component, {
export const stableMount: typeof mount = (component, config) => {
cy.intercept('GET', 'https://fonts.gstatic.com/**', {
fixture: 'manrope-fonts.ttf',
}).as('fonts');

cy.wait('@fonts');

return mount(component, {
...config,
providers: [...(config?.providers || []), NG_EVENT_PLUGINS],
}).then((mountResponse) =>
Expand All @@ -27,5 +33,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