Fix touch state not being activated in iOS Safari

This commit resolves the issue with the `:active` pseudo-class not
activating in mobile Safari on iOS devices. It introduces a workaround
specifically for mobile Safari on iOS/iPadOS to enable the `:active`
pseudo-class. This ensures a consistent and responsive user interface
in response to touch states on mobile Safari.

Other supporting changes:

- Introduce new test utility functions such as `createWindowEventSpies`
  and `formatAssertionMessage` to improve code reusability and
  maintainability.
- Improve browser detection:
  - Add detection for iPadOS and Windows 10 Mobile.
  - Add touch support detection to correctly determine iPadOS vs macOS.
  - Fix misidentification of some Windows 10 Mobile platforms as Windows
    Phone.
  - Improve test coverage and refactor tests.
This commit is contained in:
undergroundwires
2023-12-11 05:24:27 +01:00
parent 916c9d62d9
commit a9851272ae
43 changed files with 1719 additions and 672 deletions

View File

@@ -1,4 +1,5 @@
import { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
import { formatAssertionMessage } from '@tests/shared/FormatAssertionMessage';
export function expectEqualSelectedScripts(
actual: readonly SelectedScript[],
@@ -14,11 +15,11 @@ function expectSameScriptIds(
) {
const existingScriptIds = expected.map((script) => script.id).sort();
const expectedScriptIds = actual.map((script) => script.id).sort();
expect(existingScriptIds).to.deep.equal(expectedScriptIds, [
expect(existingScriptIds).to.deep.equal(expectedScriptIds, formatAssertionMessage([
'Unexpected script IDs.',
`Expected: ${expectedScriptIds.join(', ')}`,
`Actual: ${existingScriptIds.join(', ')}`,
].join('\n'));
]));
}
function expectSameRevertStates(
@@ -33,7 +34,7 @@ function expectSameRevertStates(
}
return script.revert !== other.revert;
});
expect(scriptsWithDifferentRevertStates).to.have.lengthOf(0, [
expect(scriptsWithDifferentRevertStates).to.have.lengthOf(0, formatAssertionMessage([
'Scripts with different revert states:',
scriptsWithDifferentRevertStates
.map((s) => [
@@ -42,5 +43,5 @@ function expectSameRevertStates(
`Expected revert state: "${expected.find((existing) => existing.id === s.id)?.revert ?? 'unknown'}"`,
].map((line) => `\t${line}`).join('\n'))
.join('\n---\n'),
].join('\n'));
]));
}

View File

@@ -12,6 +12,7 @@ import { IReadOnlyFunctionParameterCollection } from '@/application/Parser/Scrip
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
import { IExpressionEvaluationContext } from '@/application/Parser/Script/Compiler/Expressions/Expression/ExpressionEvaluationContext';
import { expectExists } from '@tests/shared/Assertions/ExpectExists';
import { formatAssertionMessage } from '@tests/shared/FormatAssertionMessage';
describe('Expression', () => {
describe('ctor', () => {
@@ -116,11 +117,10 @@ describe('Expression', () => {
// arrange
const actual = sut.evaluate(context);
// assert
expect(expected).to.equal(actual, printMessage());
function printMessage(): string {
return `\nGiven arguments: ${JSON.stringify(givenArguments)}\n`
+ `\nExpected parameter names: ${JSON.stringify(expectedParameterNames)}\n`;
}
expect(expected).to.equal(actual, formatAssertionMessage([
`Given arguments: ${JSON.stringify(givenArguments)}`,
`Expected parameter names: ${JSON.stringify(expectedParameterNames)}`,
]));
});
it('sends pipeline compiler as it is', () => {
// arrange

View File

@@ -1,6 +1,7 @@
import {
CallFunctionBody, CodeFunctionBody, FunctionBodyType, SharedFunctionBody,
} from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
import { formatAssertionMessage } from '@tests/shared/FormatAssertionMessage';
export function expectCodeFunctionBody(
body: SharedFunctionBody,
@@ -16,14 +17,9 @@ export function expectCallsFunctionBody(
function expectBodyType(body: SharedFunctionBody, expectedType: FunctionBodyType) {
const actualType = body.type;
expect(actualType).to.equal(
expectedType,
[
'\n---',
`Actual: ${FunctionBodyType[actualType]}`,
`Expected: ${FunctionBodyType[expectedType]}`,
`Body: ${JSON.stringify(body)}`,
'---\n\n',
].join('\n'),
);
expect(actualType).to.equal(expectedType, formatAssertionMessage([
`Actual: ${FunctionBodyType[actualType]}`,
`Expected: ${FunctionBodyType[expectedType]}`,
`Body: ${JSON.stringify(body)}`,
]));
}

View File

@@ -1,6 +1,7 @@
import { readdirSync, readFileSync } from 'fs';
import { resolve, join, basename } from 'path';
import { describe, it, expect } from 'vitest';
import { formatAssertionMessage } from '@tests/shared/FormatAssertionMessage';
/*
A common mistake when working with yaml files to forget mentioning that a value should
@@ -24,11 +25,10 @@ describe('collection files to have no unintended inlining', () => {
// act
const lines = await findBadLineNumbers(testCase.content);
// assert
expect(lines).to.be.have.lengthOf(0, printMessage());
function printMessage(): string {
return 'Did you intend to have multi-lined string in lines: ' // eslint-disable-line prefer-template
+ lines.map(((line) => line.toString())).join(', ');
}
expect(lines).to.be.have.lengthOf(0, formatAssertionMessage([
'Did you intend to have multi-lined string in lines: ',
lines.map(((line) => line.toString())).join(', '),
]));
});
}
});