@taiga-ui/testing 3.59.0 → 3.60.0-canary.799e7d6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/taiga-ui-testing-core.umd.js +78 -78
- package/bundles/taiga-ui-testing-core.umd.js.map +1 -1
- package/bundles/taiga-ui-testing-cypress.umd.js +19 -19
- package/bundles/taiga-ui-testing-cypress.umd.js.map +1 -1
- package/bundles/taiga-ui-testing-setup-jest.umd.js +19 -19
- package/bundles/taiga-ui-testing-setup-jest.umd.js.map +1 -1
- package/bundles/taiga-ui-testing-utils.umd.js +67 -67
- package/bundles/taiga-ui-testing-utils.umd.js.map +1 -1
- package/esm2015/core/accordion-item.harness.js +8 -8
- package/esm2015/core/accordion.harness.js +3 -3
- package/esm2015/core/action.harness.js +2 -2
- package/esm2015/core/avatar.harness.js +2 -2
- package/esm2015/core/badge.harness.js +3 -3
- package/esm2015/core/button.harness.js +2 -2
- package/esm2015/core/calendar.harness.js +3 -3
- package/esm2015/core/card.harness.js +5 -5
- package/esm2015/core/dialog.harness.js +3 -3
- package/esm2015/core/hosted-dropdown.harness.js +3 -3
- package/esm2015/core/island.harness.js +13 -13
- package/esm2015/core/loader.harness.js +4 -4
- package/esm2015/core/marker-icon.harness.js +2 -2
- package/esm2015/core/primitive-calender.harness.js +7 -7
- package/esm2015/core/primitive-spin-button.harness.js +4 -4
- package/esm2015/core/primitive-textfield.harness.js +4 -4
- package/esm2015/core/primitive-year-month-pagination.harness.js +7 -7
- package/esm2015/core/primitive-year-picker.harness.js +5 -5
- package/esm2015/core/select.harness.js +2 -2
- package/esm2015/core/svg.harness.js +4 -4
- package/esm2015/core/tag.harness.js +6 -6
- package/esm2015/core/textfield.harness.js +3 -3
- package/esm2015/core/toggle.harness.js +3 -3
- package/esm2015/cypress/assertions/be-in-viewport.js +4 -4
- package/esm2015/cypress/commands/wait-all-img-inside.command.js +9 -9
- package/esm2015/cypress/snapshot/command.js +5 -5
- package/esm2015/cypress/snapshot/plugin.js +6 -6
- package/esm2015/setup-jest/index.js +20 -20
- package/esm2015/utils/active-element.js +3 -3
- package/esm2015/utils/helpers.js +2 -2
- package/esm2015/utils/input/cleaner.unit-common.js +12 -12
- package/esm2015/utils/input/filler.unit-common.js +9 -9
- package/esm2015/utils/input/form-control-state.unit-common.js +9 -9
- package/esm2015/utils/input/placeholder.unit-common.js +17 -17
- package/esm2015/utils/input/tooltip.unit-common.js +8 -8
- package/esm2015/utils/keyboard-event.js +4 -4
- package/esm2015/utils/native-input.page-object.js +4 -4
- package/esm2015/utils/page-object.js +3 -3
- package/esm2015/utils/replace-nbsp.js +2 -2
- package/esm2015/utils/viewport.js +5 -5
- package/fesm2015/taiga-ui-testing-core.js +75 -75
- package/fesm2015/taiga-ui-testing-core.js.map +1 -1
- package/fesm2015/taiga-ui-testing-cypress.js +19 -19
- package/fesm2015/taiga-ui-testing-cypress.js.map +1 -1
- package/fesm2015/taiga-ui-testing-setup-jest.js +19 -19
- package/fesm2015/taiga-ui-testing-setup-jest.js.map +1 -1
- package/fesm2015/taiga-ui-testing-utils.js +66 -66
- package/fesm2015/taiga-ui-testing-utils.js.map +1 -1
- package/package.json +17 -17
@@ -18,16 +18,16 @@ import fs from 'fs';
|
|
18
18
|
```
|
19
19
|
* */
|
20
20
|
const tuiBeInViewportAssertion = _chai => {
|
21
|
-
chai.Assertion.addMethod(
|
21
|
+
chai.Assertion.addMethod('inViewport', function () {
|
22
22
|
const subject = this._obj;
|
23
23
|
const { top, bottom } = subject[0].getBoundingClientRect();
|
24
24
|
const viewportHeight =
|
25
25
|
// @ts-ignore TS2339: Property 'state' does not exist on type 'cy & CyEventEmitter'.
|
26
|
-
Cypress.$(cy.state(
|
26
|
+
Cypress.$(cy.state('window')).height() || 0;
|
27
27
|
const subjectOverlapsAllViewport = top < 0 && bottom > viewportHeight;
|
28
28
|
const topBorderIsVisible = top >= 0 && top < viewportHeight;
|
29
29
|
const bottomBorderIsVisible = bottom >= 0 && bottom < viewportHeight;
|
30
|
-
this.assert(subjectOverlapsAllViewport || topBorderIsVisible || bottomBorderIsVisible,
|
30
|
+
this.assert(subjectOverlapsAllViewport || topBorderIsVisible || bottomBorderIsVisible, 'expected #{this} to be in viewport', 'expected #{this} to not be in viewport', subject);
|
31
31
|
});
|
32
32
|
};
|
33
33
|
|
@@ -35,14 +35,14 @@ const tuiBeInViewportAssertion = _chai => {
|
|
35
35
|
const tuiWaitAllImgInside = (prevSubject, enabled = true) => {
|
36
36
|
const target = prevSubject && Cypress.dom.isJquery(prevSubject)
|
37
37
|
? cy.wrap(prevSubject, { log: false })
|
38
|
-
: cy.get(
|
38
|
+
: cy.get('body', { log: false });
|
39
39
|
target.then($target => {
|
40
|
-
const img = $target.find(
|
40
|
+
const img = $target.find('img');
|
41
41
|
if (img.length && enabled) {
|
42
42
|
const log = Cypress.log({
|
43
|
-
displayName:
|
44
|
-
message:
|
45
|
-
name:
|
43
|
+
displayName: 'Wait all images',
|
44
|
+
message: 'naturalWidth greaterThan 0',
|
45
|
+
name: 'tuiWaitAllImgInside',
|
46
46
|
autoEnd: false,
|
47
47
|
consoleProps: () => ({
|
48
48
|
prevSubject,
|
@@ -50,14 +50,14 @@ const tuiWaitAllImgInside = (prevSubject, enabled = true) => {
|
|
50
50
|
}),
|
51
51
|
});
|
52
52
|
cy.wrap($target, { log: false })
|
53
|
-
.get(
|
53
|
+
.get('img', { log: false })
|
54
54
|
.each((img) => {
|
55
55
|
const nativeImage = img.get(0);
|
56
56
|
const url = (nativeImage === null || nativeImage === void 0 ? void 0 : nativeImage.src) || (nativeImage === null || nativeImage === void 0 ? void 0 : nativeImage.srcset);
|
57
57
|
if (!url) {
|
58
58
|
return;
|
59
59
|
}
|
60
|
-
const offsetParent = img.prop(
|
60
|
+
const offsetParent = img.prop('offsetParent');
|
61
61
|
return cy.window({ log: false }).then((win) => {
|
62
62
|
const rect = nativeImage.getBoundingClientRect();
|
63
63
|
const isInViewport = offsetParent &&
|
@@ -70,7 +70,7 @@ const tuiWaitAllImgInside = (prevSubject, enabled = true) => {
|
|
70
70
|
(win.innerWidth ||
|
71
71
|
win.document.documentElement.clientWidth);
|
72
72
|
if (isInViewport) {
|
73
|
-
if (url.includes(
|
73
|
+
if (url.includes('base64')) {
|
74
74
|
expect(nativeImage.naturalWidth).to.be.greaterThan(0);
|
75
75
|
}
|
76
76
|
else {
|
@@ -96,14 +96,14 @@ const tuiWaitAllImgInside = (prevSubject, enabled = true) => {
|
|
96
96
|
/// <reference types="cypress" />
|
97
97
|
function makeScreenshotName(name) {
|
98
98
|
return (name !== null && name !== void 0 ? name : Cypress.currentTest.titlePath
|
99
|
-
.join(
|
100
|
-
.replace(/\s|-/g,
|
101
|
-
.replace(/['[\]`()]/g,
|
99
|
+
.join('-')
|
100
|
+
.replace(/\s|-/g, '.')
|
101
|
+
.replace(/['[\]`()]/g, '')
|
102
102
|
.toLowerCase());
|
103
103
|
}
|
104
104
|
function tuiAddMatchImageSnapshotCommand(options) {
|
105
105
|
const matchSnapshotFn = matchImageSnapshotCommand(options);
|
106
|
-
Cypress.Commands.add(
|
106
|
+
Cypress.Commands.add('matchImageSnapshot', { prevSubject: ['optional', 'element', 'window', 'document'] }, (prevSubject, nameOrOptions, options) => {
|
107
107
|
var _a;
|
108
108
|
const name = tuiIsString(nameOrOptions) ? nameOrOptions : undefined;
|
109
109
|
const overloadedOptions = tuiIsObject(nameOrOptions)
|
@@ -119,17 +119,17 @@ function tuiAddSnapshotPlugin(on, config, { newSnapshotMarkEnabled, newSnapshotM
|
|
119
119
|
return __awaiter(this, void 0, void 0, function* () {
|
120
120
|
const { addMatchImageSnapshotPlugin, matchImageSnapshotPlugin } = yield import('cypress-image-snapshot/plugin');
|
121
121
|
addMatchImageSnapshotPlugin(on, config);
|
122
|
-
on(
|
122
|
+
on('after:screenshot', (details) => {
|
123
123
|
const { name, path, testFailure } = details;
|
124
124
|
const possibleSnapshotPath = path
|
125
|
-
.replace(
|
126
|
-
.replace(/\.(\w+)$/g,
|
125
|
+
.replace('screenshots', 'snapshots')
|
126
|
+
.replace(/\.(\w+)$/g, '.snap.$1');
|
127
127
|
const snapshotAlreadyExists = fs.existsSync(possibleSnapshotPath);
|
128
128
|
if (newSnapshotMarkEnabled && !testFailure && !snapshotAlreadyExists) {
|
129
129
|
const newName = newSnapshotMarkFn(name);
|
130
130
|
const newPath = path.replace(name, newName);
|
131
131
|
fs.renameSync(path, newPath);
|
132
|
-
console.info(
|
132
|
+
console.info('\x1B[32m%s\x1B[0m', '\t[tuiAddSnapshotPlugin]:', `${name} => ${newName}`);
|
133
133
|
return matchImageSnapshotPlugin(Object.assign(Object.assign({}, details), { path: newPath }));
|
134
134
|
}
|
135
135
|
return matchImageSnapshotPlugin(details);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"taiga-ui-testing-cypress.js","sources":["../../../projects/testing/cypress/assertions/be-in-viewport.ts","../../../projects/testing/cypress/commands/wait-all-img-inside.command.ts","../../../projects/testing/cypress/snapshot/command.ts","../../../projects/testing/cypress/snapshot/plugin.ts","../../../projects/testing/cypress/taiga-ui-testing-cypress.ts"],"sourcesContent":["/// <reference types=\"cypress\" />\n/// <reference types=\"node\" />\n\n/**\n * Check if element is inside viewport\n *\n * @note WARNING! `.should('be.visible')` doesn't not check if element is inside viewport\n * @see https://github.com/cypress-io/cypress/issues/17483\n * @see https://github.com/cypress-io/cypress/issues/877#issuecomment-342187174\n * @see https://github.com/cypress-io/cypress/issues/877#issuecomment-657583222\n * @example\n ```ts\n cy.get('#test').should('be.inViewport');\n ```\n * */\nexport const tuiBeInViewportAssertion: Chai.ChaiPlugin = _chai => {\n chai.Assertion.addMethod(`inViewport`, function () {\n const subject = this._obj;\n const {top, bottom} = subject[0].getBoundingClientRect();\n\n const viewportHeight: number =\n // @ts-ignore TS2339: Property 'state' does not exist on type 'cy & CyEventEmitter'.\n Cypress.$(cy.state(`window`)).height() || 0;\n\n const subjectOverlapsAllViewport = top < 0 && bottom > viewportHeight;\n const topBorderIsVisible = top >= 0 && top < viewportHeight;\n const bottomBorderIsVisible = bottom >= 0 && bottom < viewportHeight;\n\n this.assert(\n subjectOverlapsAllViewport || topBorderIsVisible || bottomBorderIsVisible,\n `expected #{this} to be in viewport`,\n `expected #{this} to not be in viewport`,\n subject,\n );\n });\n};\n","/// <reference types=\"cypress\" />\n\nexport const tuiWaitAllImgInside = (\n prevSubject: Cypress.PrevSubjectMap<void>[Cypress.PrevSubject],\n enabled: boolean = true,\n): Cypress.Chainable<JQuery<HTMLBodyElement>> | Cypress.Chainable<JQuery> => {\n const target =\n prevSubject && Cypress.dom.isJquery(prevSubject)\n ? cy.wrap(prevSubject, {log: false})\n : cy.get(`body`, {log: false});\n\n target.then($target => {\n const img = $target.find(`img`);\n\n if (img.length && enabled) {\n const log = Cypress.log({\n displayName: `Wait all images`,\n message: `naturalWidth greaterThan 0`,\n name: `tuiWaitAllImgInside`,\n autoEnd: false,\n consoleProps: () => ({\n prevSubject,\n img,\n }),\n });\n\n cy.wrap($target, {log: false})\n .get(`img`, {log: false})\n .each((img: JQuery<HTMLImageElement>) => {\n const nativeImage = img.get(0);\n const url = nativeImage?.src || nativeImage?.srcset;\n\n if (!url) {\n return;\n }\n\n const offsetParent = img.prop(`offsetParent`);\n\n return cy.window({log: false}).then((win: Window) => {\n const rect = nativeImage.getBoundingClientRect();\n const isInViewport =\n offsetParent &&\n rect.top >= 0 &&\n rect.left >= 0 &&\n rect.bottom <=\n (win.innerHeight ||\n win.document.documentElement.clientHeight) &&\n rect.right <=\n (win.innerWidth ||\n win.document.documentElement.clientWidth);\n\n if (isInViewport) {\n if (url.includes(`base64`)) {\n (expect as any)(\n nativeImage.naturalWidth,\n ).to.be.greaterThan(0);\n } else {\n cy.request({\n url,\n failOnStatusCode: false,\n log: false,\n }).then(resp => {\n if (resp.status === 200) {\n cy.get(img as any, {log: false}).should(\n (el: JQuery<HTMLImageElement>) =>\n (expect as any)(\n el[0].naturalWidth,\n ).to.be.greaterThan(0),\n );\n }\n });\n }\n }\n });\n })\n .then(() => log.end());\n }\n });\n\n return target;\n};\n","/// <reference types=\"cypress\" />\n// eslint-disable-next-line @taiga-ui/experience/no-deep-imports\nimport {tuiIsObject, tuiIsString} from '@taiga-ui/cdk/utils/miscellaneous';\nimport {Options} from 'cypress-image-snapshot';\nimport {matchImageSnapshotCommand} from 'cypress-image-snapshot/command';\n\nimport {tuiWaitAllImgInside} from '../commands/wait-all-img-inside.command';\n\ndeclare module 'cypress-image-snapshot/command' {\n function matchImageSnapshotCommand(options: Options): (...args: unknown[]) => void;\n}\n\ninterface TuiSnapshotCommandOptions {\n waitAllImages?: boolean;\n}\n\ndeclare global {\n namespace Cypress {\n interface Chainable {\n matchImageSnapshot(\n name: string,\n options?: Options & TuiSnapshotCommandOptions,\n ): void;\n }\n }\n}\n\nfunction makeScreenshotName(name?: string): string {\n return (\n name ??\n Cypress.currentTest.titlePath\n .join(`-`)\n .replace(/\\s|-/g, `.`)\n .replace(/['[\\]`()]/g, ``)\n .toLowerCase()\n );\n}\n\nexport function tuiAddMatchImageSnapshotCommand(\n options: Options & TuiSnapshotCommandOptions,\n): void {\n const matchSnapshotFn = matchImageSnapshotCommand(options);\n\n Cypress.Commands.add(\n `matchImageSnapshot`,\n {prevSubject: [`optional`, `element`, `window`, `document`]},\n (\n prevSubject,\n nameOrOptions: string | (Options & TuiSnapshotCommandOptions),\n options?: Options & TuiSnapshotCommandOptions,\n ) => {\n const name = tuiIsString(nameOrOptions) ? nameOrOptions : undefined;\n const overloadedOptions = tuiIsObject(nameOrOptions)\n ? nameOrOptions\n : options;\n\n tuiWaitAllImgInside(prevSubject, overloadedOptions?.waitAllImages ?? true);\n\n matchSnapshotFn(prevSubject, makeScreenshotName(name), overloadedOptions);\n },\n );\n}\n","/// <reference types=\"cypress\" />\n/// <reference types=\"node\" />\n\nimport fs from 'fs';\n\ndeclare module 'cypress-image-snapshot/plugin' {\n function matchImageSnapshotPlugin(\n details: Cypress.ScreenshotDetails,\n ): Cypress.AfterScreenshotReturnObject | void;\n}\n\nexport interface TuiSnapshotPluginOptions {\n newSnapshotMarkEnabled: boolean;\n newSnapshotMarkFn: (oldSnapshotFileName: string) => string;\n}\n\nexport async function tuiAddSnapshotPlugin(\n on: Cypress.PluginEvents,\n config: Cypress.PluginConfigOptions,\n {newSnapshotMarkEnabled, newSnapshotMarkFn}: TuiSnapshotPluginOptions,\n): Promise<void> {\n const {addMatchImageSnapshotPlugin, matchImageSnapshotPlugin} = await import(\n `cypress-image-snapshot/plugin`\n );\n\n addMatchImageSnapshotPlugin(on, config);\n\n on(`after:screenshot`, (details: Cypress.ScreenshotDetails) => {\n const {name, path, testFailure} = details;\n const possibleSnapshotPath = path\n .replace(`screenshots`, `snapshots`)\n .replace(/\\.(\\w+)$/g, `.snap.$1`);\n const snapshotAlreadyExists = fs.existsSync(possibleSnapshotPath);\n\n if (newSnapshotMarkEnabled && !testFailure && !snapshotAlreadyExists) {\n const newName = newSnapshotMarkFn(name);\n const newPath = path.replace(name, newName);\n\n fs.renameSync(path, newPath);\n\n console.info(\n `\\x1B[32m%s\\x1B[0m`,\n `\\t[tuiAddSnapshotPlugin]:`,\n `${name} => ${newName}`,\n );\n\n return matchImageSnapshotPlugin({...details, path: newPath});\n }\n\n return matchImageSnapshotPlugin(details);\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAEA;;;;;;;;;;;AAWK;AACQ,MAAA,wBAAwB,GAAoB,KAAK,IAAG;AAC7D,IAAA,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,YAAY,EAAE,YAAA;AACnC,QAAA,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;AAC1B,QAAA,MAAM,EAAC,GAAG,EAAE,MAAM,EAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,qBAAqB,EAAE,CAAC;AAEzD,QAAA,MAAM,cAAc;;AAEhB,QAAA,OAAO,CAAC,CAAC,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AC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAC,GAAG,OAAO,CAAC;YAC1C,MAAM,oBAAoB,GAAG,IAAI;AAC5B,iBAAA,OAAO,CAAC,CAAA,WAAA,CAAa,EAAE,CAAA,SAAA,CAAW,CAAC;AACnC,iBAAA,OAAO,CAAC,WAAW,EAAE,CAAA,QAAA,CAAU,CAAC,CAAC;YACtC,MAAM,qBAAqB,GAAG,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;AAElE,YAAA,IAAI,sBAAsB,IAAI,CAAC,WAAW,IAAI,CAAC,qBAAqB,EAAE;AAClE,gBAAA,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACxC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAE5C,gBAAA,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAE7B,gBAAA,OAAO,CAAC,IAAI,CACR,CAAA,iBAAA,CAAmB,EACnB,CAAA,yBAAA,CAA2B,EAC3B,CAAA,EAAG,IAAI,CAAA,IAAA,EAAO,OAAO,CAAA,CAAE,CAC1B,CAAC;gBAEF,OAAO,wBAAwB,iCAAK,OAAO,CAAA,EAAA,EAAE,IAAI,EAAE,OAAO,IAAE,CAAC;AAChE,aAAA;AAED,YAAA,OAAO,wBAAwB,CAAC,OAAO,CAAC,CAAC;AAC7C,SAAC,CAAC,CAAC;KACN,CAAA,CAAA;AAAA;;ACnDD;;AAEG;;;;"}
|
1
|
+
{"version":3,"file":"taiga-ui-testing-cypress.js","sources":["../../../projects/testing/cypress/assertions/be-in-viewport.ts","../../../projects/testing/cypress/commands/wait-all-img-inside.command.ts","../../../projects/testing/cypress/snapshot/command.ts","../../../projects/testing/cypress/snapshot/plugin.ts","../../../projects/testing/cypress/taiga-ui-testing-cypress.ts"],"sourcesContent":["/// <reference types=\"cypress\" />\n/// <reference types=\"node\" />\n\n/**\n * Check if element is inside viewport\n *\n * @note WARNING! `.should('be.visible')` doesn't not check if element is inside viewport\n * @see https://github.com/cypress-io/cypress/issues/17483\n * @see https://github.com/cypress-io/cypress/issues/877#issuecomment-342187174\n * @see https://github.com/cypress-io/cypress/issues/877#issuecomment-657583222\n * @example\n ```ts\n cy.get('#test').should('be.inViewport');\n ```\n * */\nexport const tuiBeInViewportAssertion: Chai.ChaiPlugin = _chai => {\n chai.Assertion.addMethod('inViewport', function () {\n const subject = this._obj;\n const {top, bottom} = subject[0].getBoundingClientRect();\n\n const viewportHeight: number =\n // @ts-ignore TS2339: Property 'state' does not exist on type 'cy & CyEventEmitter'.\n Cypress.$(cy.state('window')).height() || 0;\n\n const subjectOverlapsAllViewport = top < 0 && bottom > viewportHeight;\n const topBorderIsVisible = top >= 0 && top < viewportHeight;\n const bottomBorderIsVisible = bottom >= 0 && bottom < viewportHeight;\n\n this.assert(\n subjectOverlapsAllViewport || topBorderIsVisible || bottomBorderIsVisible,\n 'expected #{this} to be in viewport',\n 'expected #{this} to not be in viewport',\n subject,\n );\n });\n};\n","/// <reference types=\"cypress\" />\n\nexport const tuiWaitAllImgInside = (\n prevSubject: Cypress.PrevSubjectMap<void>[Cypress.PrevSubject],\n enabled: boolean = true,\n): Cypress.Chainable<JQuery<HTMLBodyElement>> | Cypress.Chainable<JQuery> => {\n const target =\n prevSubject && Cypress.dom.isJquery(prevSubject)\n ? cy.wrap(prevSubject, {log: false})\n : cy.get('body', {log: false});\n\n target.then($target => {\n const img = $target.find('img');\n\n if (img.length && enabled) {\n const log = Cypress.log({\n displayName: 'Wait all images',\n message: 'naturalWidth greaterThan 0',\n name: 'tuiWaitAllImgInside',\n autoEnd: false,\n consoleProps: () => ({\n prevSubject,\n img,\n }),\n });\n\n cy.wrap($target, {log: false})\n .get('img', {log: false})\n .each((img: JQuery<HTMLImageElement>) => {\n const nativeImage = img.get(0);\n const url = nativeImage?.src || nativeImage?.srcset;\n\n if (!url) {\n return;\n }\n\n const offsetParent = img.prop('offsetParent');\n\n return cy.window({log: false}).then((win: Window) => {\n const rect = nativeImage.getBoundingClientRect();\n const isInViewport =\n offsetParent &&\n rect.top >= 0 &&\n rect.left >= 0 &&\n rect.bottom <=\n (win.innerHeight ||\n win.document.documentElement.clientHeight) &&\n rect.right <=\n (win.innerWidth ||\n win.document.documentElement.clientWidth);\n\n if (isInViewport) {\n if (url.includes('base64')) {\n (expect as any)(\n nativeImage.naturalWidth,\n ).to.be.greaterThan(0);\n } else {\n cy.request({\n url,\n failOnStatusCode: false,\n log: false,\n }).then(resp => {\n if (resp.status === 200) {\n cy.get(img as any, {log: false}).should(\n (el: JQuery<HTMLImageElement>) =>\n (expect as any)(\n el[0].naturalWidth,\n ).to.be.greaterThan(0),\n );\n }\n });\n }\n }\n });\n })\n .then(() => log.end());\n }\n });\n\n return target;\n};\n","/// <reference types=\"cypress\" />\n// eslint-disable-next-line @taiga-ui/experience/no-deep-imports\nimport {tuiIsObject, tuiIsString} from '@taiga-ui/cdk/utils/miscellaneous';\nimport {Options} from 'cypress-image-snapshot';\nimport {matchImageSnapshotCommand} from 'cypress-image-snapshot/command';\n\nimport {tuiWaitAllImgInside} from '../commands/wait-all-img-inside.command';\n\ndeclare module 'cypress-image-snapshot/command' {\n function matchImageSnapshotCommand(options: Options): (...args: unknown[]) => void;\n}\n\ninterface TuiSnapshotCommandOptions {\n waitAllImages?: boolean;\n}\n\ndeclare global {\n namespace Cypress {\n interface Chainable {\n matchImageSnapshot(\n name: string,\n options?: Options & TuiSnapshotCommandOptions,\n ): void;\n }\n }\n}\n\nfunction makeScreenshotName(name?: string): string {\n return (\n name ??\n Cypress.currentTest.titlePath\n .join('-')\n .replace(/\\s|-/g, '.')\n .replace(/['[\\]`()]/g, '')\n .toLowerCase()\n );\n}\n\nexport function tuiAddMatchImageSnapshotCommand(\n options: Options & TuiSnapshotCommandOptions,\n): void {\n const matchSnapshotFn = matchImageSnapshotCommand(options);\n\n Cypress.Commands.add(\n 'matchImageSnapshot',\n {prevSubject: ['optional', 'element', 'window', 'document']},\n (\n prevSubject,\n nameOrOptions: string | (Options & TuiSnapshotCommandOptions),\n options?: Options & TuiSnapshotCommandOptions,\n ) => {\n const name = tuiIsString(nameOrOptions) ? nameOrOptions : undefined;\n const overloadedOptions = tuiIsObject(nameOrOptions)\n ? nameOrOptions\n : options;\n\n tuiWaitAllImgInside(prevSubject, overloadedOptions?.waitAllImages ?? true);\n\n matchSnapshotFn(prevSubject, makeScreenshotName(name), overloadedOptions);\n },\n );\n}\n","/// <reference types=\"cypress\" />\n/// <reference types=\"node\" />\n\nimport fs from 'fs';\n\ndeclare module 'cypress-image-snapshot/plugin' {\n function matchImageSnapshotPlugin(\n details: Cypress.ScreenshotDetails,\n ): Cypress.AfterScreenshotReturnObject | void;\n}\n\nexport interface TuiSnapshotPluginOptions {\n newSnapshotMarkEnabled: boolean;\n newSnapshotMarkFn: (oldSnapshotFileName: string) => string;\n}\n\nexport async function tuiAddSnapshotPlugin(\n on: Cypress.PluginEvents,\n config: Cypress.PluginConfigOptions,\n {newSnapshotMarkEnabled, newSnapshotMarkFn}: TuiSnapshotPluginOptions,\n): Promise<void> {\n const {addMatchImageSnapshotPlugin, matchImageSnapshotPlugin} = await import(\n 'cypress-image-snapshot/plugin'\n );\n\n addMatchImageSnapshotPlugin(on, config);\n\n on('after:screenshot', (details: Cypress.ScreenshotDetails) => {\n const {name, path, testFailure} = details;\n const possibleSnapshotPath = path\n .replace('screenshots', 'snapshots')\n .replace(/\\.(\\w+)$/g, '.snap.$1');\n const snapshotAlreadyExists = fs.existsSync(possibleSnapshotPath);\n\n if (newSnapshotMarkEnabled && !testFailure && !snapshotAlreadyExists) {\n const newName = newSnapshotMarkFn(name);\n const newPath = path.replace(name, newName);\n\n fs.renameSync(path, newPath);\n\n console.info(\n '\\x1B[32m%s\\x1B[0m',\n '\\t[tuiAddSnapshotPlugin]:',\n `${name} => ${newName}`,\n );\n\n return matchImageSnapshotPlugin({...details, path: newPath});\n }\n\n return match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, TextDecoder: TextDecoderMock } = require(
|
2
|
+
const { TextEncoder: TextEncoderMock, TextDecoder: TextDecoderMock } = require('util');
|
3
3
|
global.TextEncoder = TextEncoderMock;
|
4
4
|
global.TextDecoder = TextDecoderMock;
|
5
5
|
// @ts-ignore
|
@@ -12,8 +12,8 @@ global.window.IntersectionObserver = jest.fn(() => ({
|
|
12
12
|
disconnect: jest.fn(),
|
13
13
|
}));
|
14
14
|
// Simulate window resize events
|
15
|
-
const resizeEvent = document.createEvent(
|
16
|
-
resizeEvent.initEvent(
|
15
|
+
const resizeEvent = document.createEvent('Event');
|
16
|
+
resizeEvent.initEvent('resize', true, true);
|
17
17
|
global.window.resizeTo = width => {
|
18
18
|
global.window.innerWidth = width || global.window.innerWidth;
|
19
19
|
global.window.innerHeight = width || global.window.innerHeight;
|
@@ -21,23 +21,23 @@ global.window.resizeTo = width => {
|
|
21
21
|
};
|
22
22
|
global.URL.createObjectURL = jest.fn(blob => `${blob}`);
|
23
23
|
global.URL.revokeObjectURL = jest.fn();
|
24
|
-
Object.defineProperty(global.window,
|
25
|
-
Object.defineProperty(global.window,
|
24
|
+
Object.defineProperty(global.window, 'CSS', { value: null });
|
25
|
+
Object.defineProperty(global.window, 'getComputedStyle', {
|
26
26
|
value: () => ({
|
27
|
-
display:
|
28
|
-
appearance: [
|
27
|
+
display: 'none',
|
28
|
+
appearance: ['-webkit-appearance'],
|
29
29
|
}),
|
30
30
|
});
|
31
|
-
Object.defineProperty(global.document,
|
32
|
-
value:
|
31
|
+
Object.defineProperty(global.document, 'doctype', {
|
32
|
+
value: '<!DOCTYPE html>',
|
33
33
|
});
|
34
|
-
Object.defineProperty(global.document.body.style,
|
34
|
+
Object.defineProperty(global.document.body.style, 'transform', {
|
35
35
|
value: () => ({
|
36
36
|
enumerable: true,
|
37
37
|
configurable: true,
|
38
38
|
}),
|
39
39
|
});
|
40
|
-
Object.defineProperty(global.window,
|
40
|
+
Object.defineProperty(global.window, 'matchMedia', {
|
41
41
|
writable: true,
|
42
42
|
value: jest.fn().mockImplementation(query => ({
|
43
43
|
matches: false,
|
@@ -50,11 +50,11 @@ Object.defineProperty(global.window, `matchMedia`, {
|
|
50
50
|
dispatchEvent: jest.fn(),
|
51
51
|
})),
|
52
52
|
});
|
53
|
-
Object.defineProperty(global.document,
|
53
|
+
Object.defineProperty(global.document, 'elementFromPoint', {
|
54
54
|
writable: true,
|
55
55
|
value: jest.fn().mockImplementation(() => null),
|
56
56
|
});
|
57
|
-
Object.defineProperty(global.document,
|
57
|
+
Object.defineProperty(global.document, 'createRange', {
|
58
58
|
writable: true,
|
59
59
|
value: () => {
|
60
60
|
const range = new Range();
|
@@ -77,10 +77,10 @@ Object.defineProperty(global.document, `createRange`, {
|
|
77
77
|
return range;
|
78
78
|
},
|
79
79
|
});
|
80
|
-
Object.defineProperty(window,
|
81
|
-
Object.defineProperty(global.window,
|
80
|
+
Object.defineProperty(window, 'scrollTo', jest.fn());
|
81
|
+
Object.defineProperty(global.window, 'getComputedStyle', {
|
82
82
|
value: () => ({
|
83
|
-
getPropertyValue: (_prop) =>
|
83
|
+
getPropertyValue: (_prop) => '',
|
84
84
|
}),
|
85
85
|
});
|
86
86
|
global.DataTransfer = class {
|
@@ -111,9 +111,9 @@ global.ClipboardEvent = TransferMockEvent;
|
|
111
111
|
* resulting in duplicate imports
|
112
112
|
* and conflicts resulting in the above error
|
113
113
|
*/
|
114
|
-
if (!(
|
115
|
-
require(
|
116
|
-
require(
|
114
|
+
if (!('Zone' in global)) {
|
115
|
+
require('zone.js');
|
116
|
+
require('zone.js/testing');
|
117
117
|
}
|
118
118
|
|
119
119
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"taiga-ui-testing-setup-jest.js","sources":["../../../projects/testing/setup-jest/index.ts","../../../projects/testing/setup-jest/taiga-ui-testing-setup-jest.ts"],"sourcesContent":["/// <reference types=\"jest\" />\n\nconst {TextEncoder: TextEncoderMock, TextDecoder: TextDecoderMock} = require(
|
1
|
+
{"version":3,"file":"taiga-ui-testing-setup-jest.js","sources":["../../../projects/testing/setup-jest/index.ts","../../../projects/testing/setup-jest/taiga-ui-testing-setup-jest.ts"],"sourcesContent":["/// <reference types=\"jest\" />\n\nconst {TextEncoder: TextEncoderMock, TextDecoder: TextDecoderMock} = require('util');\n\nglobal.TextEncoder = TextEncoderMock;\nglobal.TextDecoder = TextDecoderMock;\n\n// @ts-ignore\nglobal.document.execCommand = () => {};\n\n// you can also pass the mock implementation\n// to jest.fn as an argument\n(global.window as any).IntersectionObserver = jest.fn(() => ({\n observe: jest.fn(),\n unobserve: jest.fn(),\n disconnect: jest.fn(),\n}));\n\n// Simulate window resize events\nconst resizeEvent = document.createEvent('Event');\n\nresizeEvent.initEvent('resize', true, true);\n\nglobal.window.resizeTo = width => {\n (global.window as any).innerWidth = width || global.window.innerWidth;\n (global.window as any).innerHeight = width || global.window.innerHeight;\n global.window.dispatchEvent(resizeEvent);\n};\n\nglobal.URL.createObjectURL = jest.fn(blob => `${blob}`);\nglobal.URL.revokeObjectURL = jest.fn();\n\nObject.defineProperty(global.window, 'CSS', {value: null});\n\nObject.defineProperty(global.window, 'getComputedStyle', {\n value: () => ({\n display: 'none',\n appearance: ['-webkit-appearance'],\n }),\n});\n\nObject.defineProperty(global.document, 'doctype', {\n value: '<!DOCTYPE html>',\n});\n\nObject.defineProperty(global.document.body.style, 'transform', {\n value: () => ({\n enumerable: true,\n configurable: true,\n }),\n});\n\nObject.defineProperty(global.window, 'matchMedia', {\n writable: true,\n value: jest.fn().mockImplementation(query => ({\n matches: false,\n media: query,\n onchange: null,\n addListener: jest.fn(),\n removeListener: jest.fn(),\n addEventListener: jest.fn(),\n removeEventListener: jest.fn(),\n dispatchEvent: jest.fn(),\n })),\n});\n\nObject.defineProperty(global.document, 'elementFromPoint', {\n writable: true,\n value: jest.fn().mockImplementation(() => null),\n});\n\nObject.defineProperty(global.document, 'createRange', {\n writable: true,\n value: () => {\n const range = new Range();\n\n range.getBoundingClientRect = () => ({\n x: 0,\n y: 0,\n bottom: 0,\n height: 0,\n left: 0,\n right: 0,\n top: 0,\n width: 0,\n toJSON: () => {},\n });\n\n range.getClientRects = () => ({\n item: () => null,\n length: 0,\n [Symbol.iterator]: jest.fn(),\n });\n\n return range;\n },\n});\n\nObject.defineProperty(window, 'scrollTo', jest.fn());\n\nObject.defineProperty(global.window, 'getComputedStyle', {\n value: () => ({\n getPropertyValue: (_prop: string) => '',\n }),\n});\n\nglobal.DataTransfer = class {\n private readonly data = new Map();\n\n setData(format: string, data: string): void {\n this.data.set(format, data);\n }\n\n getData(format: string): string {\n return this.data.get(format);\n }\n} as unknown as typeof DataTransfer;\n\nclass TransferMockEvent {\n dataTransfer: DataTransfer;\n relatedTarget: EventTarget;\n\n constructor(\n readonly type: string,\n readonly options: {\n clipboardData: DataTransfer;\n relatedTarget: EventTarget;\n },\n ) {\n this.dataTransfer = options.clipboardData;\n this.relatedTarget = options.relatedTarget;\n }\n}\n\nglobal.DragEvent = TransferMockEvent as unknown as typeof DragEvent;\nglobal.ClipboardEvent = TransferMockEvent as unknown as typeof ClipboardEvent;\n\n/**\n * in our jest setupFilesAfterEnv file,\n * however when running with ng test those\n * imports are already done by angular\n * resulting in duplicate imports\n * and conflicts resulting in the above error\n */\nif (!('Zone' in global)) {\n require('zone.js');\n require('zone.js/testing');\n}\n\n// @note: build empty entry point\nexport {};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAAA;AAEA,MAAM,EAAC,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAErF,MAAM,CAAC,WAAW,GAAG,eAAe,CAAC;AACrC,MAAM,CAAC,WAAW,GAAG,eAAe,CAAC;AAErC;AACA,MAAM,CAAC,QAAQ,CAAC,WAAW,GAAG,MAAO,GAAC,CAAC;AAEvC;AACA;AACC,MAAM,CAAC,MAAc,CAAC,oBAAoB,GAAG,IAAI,CAA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