mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Compare commits
24 commits
2853f8191d
...
6c82458ba4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c82458ba4 | ||
|
|
c16868da13 | ||
|
|
f76a41a2e1 | ||
|
|
0afc64c5e9 | ||
|
|
7c8adea941 | ||
|
|
a232a1b49d | ||
|
|
559e47c8fa | ||
|
|
de1843c2bf | ||
|
|
411df75c52 | ||
|
|
87a7688947 | ||
|
|
48be5593d3 | ||
|
|
bff6fd4494 | ||
|
|
ae62aacbd6 | ||
|
|
07ae854dbb | ||
|
|
754f6b3920 | ||
|
|
bafb8717b2 | ||
|
|
2f488ee25c | ||
|
|
fddfa9d5a4 | ||
|
|
44d7393039 | ||
|
|
0a6038e316 | ||
|
|
f3ec9104f8 | ||
|
|
11ebfbad9b | ||
|
|
c8c1d5a911 | ||
|
|
d3c4f667fd |
12 changed files with 9551 additions and 6774 deletions
129
.cursorrules
Normal file
129
.cursorrules
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/**
|
||||
* Does It ARM Project Rules
|
||||
* Customized AI behavior for maintaining app compatibility database
|
||||
*/
|
||||
module.exports = {
|
||||
// Core project settings
|
||||
project: {
|
||||
name: 'doesitarm',
|
||||
type: 'astro',
|
||||
packageManager: 'pnpm',
|
||||
nodeVersion: '>=22'
|
||||
},
|
||||
|
||||
// Code style preferences
|
||||
style: {
|
||||
indentSize: 4,
|
||||
maxLineLength: 72,
|
||||
quotes: 'single',
|
||||
semicolons: false
|
||||
},
|
||||
|
||||
// Testing configuration
|
||||
testing: {
|
||||
framework: 'vitest',
|
||||
pattern: 'test/**/*.test.js',
|
||||
coverage: true
|
||||
},
|
||||
|
||||
// Documentation rules
|
||||
docs: {
|
||||
// Write comments as user stories instead of implementation details
|
||||
commentStyle: 'userStory',
|
||||
jsdoc: {
|
||||
required: true,
|
||||
params: true,
|
||||
returns: true
|
||||
}
|
||||
},
|
||||
|
||||
// Function patterns
|
||||
functions: {
|
||||
// Prefer options object for 2+ params
|
||||
preferOptionsObject: true,
|
||||
|
||||
// Always use named exports except for pages
|
||||
exports: 'named',
|
||||
|
||||
// Functional components only
|
||||
reactComponents: 'functional'
|
||||
},
|
||||
|
||||
// Variable naming
|
||||
naming: {
|
||||
// Avoid generic names
|
||||
forbidden: [
|
||||
'base64',
|
||||
'text',
|
||||
'data',
|
||||
'item',
|
||||
'content'
|
||||
],
|
||||
|
||||
// Prefer descriptive names
|
||||
preferred: {
|
||||
'base64': '*Base64',
|
||||
'text': '*Text',
|
||||
'data': '*Data',
|
||||
'content': '*Content'
|
||||
}
|
||||
},
|
||||
|
||||
// Search functionality rules
|
||||
search: {
|
||||
// Stork search configuration
|
||||
stork: {
|
||||
version: '1.6.0',
|
||||
indexPath: 'static/search-index.st',
|
||||
tomlPath: 'static/stork.toml'
|
||||
}
|
||||
},
|
||||
|
||||
// Build process
|
||||
build: {
|
||||
// Files to ignore
|
||||
ignore: [
|
||||
'node_modules',
|
||||
'dist',
|
||||
'.cache',
|
||||
'.DS_Store'
|
||||
],
|
||||
|
||||
// Required environment variables
|
||||
requiredEnv: [
|
||||
'PUBLIC_URL',
|
||||
'PUBLIC_API_DOMAIN',
|
||||
'COMMITS_SOURCE',
|
||||
'GAMES_SOURCE'
|
||||
]
|
||||
},
|
||||
|
||||
// Deployment configurations
|
||||
deployment: {
|
||||
platforms: ['netlify', 'vercel'],
|
||||
netlify: {
|
||||
buildCommand: 'pnpm run netlify-build',
|
||||
publishDir: 'dist/',
|
||||
functions: {
|
||||
directory: 'dist/functions',
|
||||
bundler: 'esbuild'
|
||||
},
|
||||
environment: {
|
||||
NPM_FLAGS: '--no-optional',
|
||||
CI: '1'
|
||||
}
|
||||
},
|
||||
vercel: {
|
||||
buildCommand: 'pnpm run vercel-build',
|
||||
distDir: 'static',
|
||||
buildSteps: [
|
||||
'test-prebuild',
|
||||
'build-lists-and-api',
|
||||
'test-postbuild-api'
|
||||
],
|
||||
github: {
|
||||
silent: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
package.json
24
package.json
|
|
@ -4,18 +4,18 @@
|
|||
"description": "Find out the latest app support for Apple Silicon and the Apple M3 Max and M2 Ultra Processors",
|
||||
"author": "Sam Carlton",
|
||||
"private": true,
|
||||
"packageManager": "pnpm@8.6.12",
|
||||
"packageManager": "pnpm@9.15.1",
|
||||
"engines": {
|
||||
"pnpm": "^8.6.*",
|
||||
"node": ">=18",
|
||||
"pnpm": "^9.*",
|
||||
"node": ">=22",
|
||||
"yarn": "forbidden, this project uses pnpm",
|
||||
"npm": "forbidden, this project uses pnpm"
|
||||
},
|
||||
"config": {
|
||||
"verbiage": {
|
||||
"processors": "Apple M3 Max and M2 Ultra",
|
||||
"macs": "Apple M3 Max or M2 Ultra Mac",
|
||||
"description": "Find out the latest app support for Apple Silicon and the Apple M3 Max and M2 Ultra Processors"
|
||||
"processors": "Apple M4 Max and M3 Ultra",
|
||||
"macs": "Apple M4 Max or M3 Ultra Mac",
|
||||
"description": "Find out the latest app support for Apple Silicon and the Apple M4 Max and M3 Ultra Processors"
|
||||
},
|
||||
"stork": {
|
||||
"executable": "stork-executable",
|
||||
|
|
@ -24,9 +24,9 @@
|
|||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test-prebuild": "ava ./test/prebuild/**/*.js --verbose",
|
||||
"test-api-client": "ava ./test/api/client.js --verbose",
|
||||
"test-listings": "ava ./test/listings/**/*.js --verbose",
|
||||
"test-prebuild": "pnpm run with-env vitest ./test/prebuild",
|
||||
"test-api-client": "pnpm run with-env vitest ./test/api",
|
||||
"test-listings": "pnpm run with-env vitest ./test/listings",
|
||||
"test-postbuild-api": "pnpm test-listings",
|
||||
"test-vitest": "vitest",
|
||||
"test": "ava --timeout=1m --verbose",
|
||||
|
|
@ -51,6 +51,7 @@
|
|||
"precommit": "pnpm run lint",
|
||||
"clone-readme": "cp ./README.md README-temp.md",
|
||||
"scan-new-apps": "pnpm exec vite-node scripts/scan-new-apps.js",
|
||||
"with-env": "dotenv -e .env -- ",
|
||||
"cloudflare-deploy": "pnpm run build-api",
|
||||
"vercel-build": "npx vite-node scripts/vercel-build.js",
|
||||
"netlify-prebuild:download-sitemaps": "npx vite-node scripts/download-sitemaps.js",
|
||||
|
|
@ -125,10 +126,11 @@
|
|||
"@astrojs/tailwind": "^4.0.0",
|
||||
"@vitest/web-worker": "^0.20.3",
|
||||
"autoprefixer": "^10.0.2",
|
||||
"ava": "^3.15.0",
|
||||
"ava": "^6.2.0",
|
||||
"babel-eslint": "^8.2.1",
|
||||
"cssnano": "^4.1.10",
|
||||
"dotenv": "^8.2.0",
|
||||
"dotenv-cli": "^8.0.0",
|
||||
"eslint": "^8.14.0",
|
||||
"eslint-plugin-vue": "^8.7.1",
|
||||
"esm": "^3.2.25",
|
||||
|
|
@ -145,6 +147,6 @@
|
|||
"tailwindcss": "^3.2.6",
|
||||
"tsconfig-paths": "^3.14.1",
|
||||
"vite-tsconfig-paths": "^3.5.0",
|
||||
"vitest": "^0.18.1"
|
||||
"vitest": "^2.1.8"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15105
pnpm-lock.yaml
generated
15105
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,4 +1,4 @@
|
|||
import test from 'ava'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
import {
|
||||
generateAPI
|
||||
|
|
@ -76,19 +76,34 @@ test( 'API has valid responses', async t => {
|
|||
const apiMethod = listingCase.method( DoesItAPI )
|
||||
|
||||
// Assert that the apiMethod url is correct
|
||||
t.is( (new URL(apiMethod.url)).pathname, caseEndpoint, `API endpoint '${ caseEndpoint }'` )
|
||||
// t.is( (new URL(apiMethod.url)).pathname, caseEndpoint, `API endpoint '${ caseEndpoint }'` )
|
||||
expect(
|
||||
(new URL(apiMethod.url)).pathname,
|
||||
`API endpoint '${ caseEndpoint }'`
|
||||
).toBe(caseEndpoint)
|
||||
|
||||
// Run get request to fetch our data
|
||||
const result = await apiMethod.get()
|
||||
|
||||
// If expected is a function then call it
|
||||
// Otherwise, compare the result to the expected
|
||||
if ( typeof listingCase.expected === 'function' ) {
|
||||
t.assert( listingCase.expected( result ), `API case method check for '${ caseEndpoint }'` )
|
||||
// t.assert( listingCase.expected( result ), `API case method check for '${ caseEndpoint }'` )
|
||||
expect(
|
||||
listingCase.expected(result),
|
||||
`API case method check for '${ caseEndpoint }'`
|
||||
).toBeTruthy()
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
t.like( result, listingCase.expected, `${ caseEndpoint } has a valid api endpoint` )
|
||||
|
||||
|
||||
// t.like( result, listingCase.expected, `${ caseEndpoint } has a valid api endpoint` )
|
||||
expect(
|
||||
result,
|
||||
`${ caseEndpoint } has a valid api endpoint`
|
||||
).toEqual(
|
||||
expect.objectContaining(listingCase.expected)
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
@ -1,248 +0,0 @@
|
|||
import fs from 'fs-extra'
|
||||
import has from 'just-has'
|
||||
import test from 'ava'
|
||||
import axios from 'axios'
|
||||
import { JSDOM } from 'jsdom'
|
||||
import { structuredDataTestHtml } from 'structured-data-testing-tool'
|
||||
import { Google } from 'structured-data-testing-tool/presets'
|
||||
|
||||
|
||||
import {
|
||||
makeApiPathFromEndpoint,
|
||||
getVideoImages,
|
||||
ListingDetails
|
||||
} from '~/helpers/listing-page.js'
|
||||
import { headPropertyTypes } from '~/test/helpers/head.js'
|
||||
import { PageHead } from '~/helpers/config-node.js'
|
||||
|
||||
|
||||
|
||||
const listingsCases = {
|
||||
|
||||
// Spotify
|
||||
'/app/spotify': {
|
||||
endpoint: '/app/spotify',
|
||||
apiEndpointPath: '/api/app/spotify.json',
|
||||
expectInitialVideo: true,
|
||||
shouldHaveVideoStucturedData: false,
|
||||
},
|
||||
|
||||
// Electron
|
||||
'/app/electron-framework': {
|
||||
endpoint: '/app/electron-framework',
|
||||
apiEndpointPath: '/api/app/electron-framework.json',
|
||||
expectInitialVideo: false,
|
||||
shouldHaveVideoStucturedData: false,
|
||||
},
|
||||
|
||||
// Express VPN Benchmarks
|
||||
'/app/expressvpn/benchmarks/': {
|
||||
endpoint: '/app/expressvpn/benchmarks/',
|
||||
apiEndpointPath: '/api/app/expressvpn.json',
|
||||
expectInitialVideo: true,
|
||||
shouldHaveVideoStucturedData: true
|
||||
},
|
||||
|
||||
// Express VPN Benchmarks
|
||||
'/tv/install-instagram-app-on-m1-macbook-air-apple-silicon-tutorial-i-vfbmworal6i/': {
|
||||
endpoint: '/tv/install-instagram-app-on-m1-macbook-air-apple-silicon-tutorial-i-vfbmworal6i/',
|
||||
apiEndpointPath: '/api/tv/install-instagram-app-on-m1-macbook-air-apple-silicon-tutorial-i-vfbmworal6i.json',
|
||||
expectInitialVideo: true,
|
||||
shouldHaveVideoStucturedData: true
|
||||
}
|
||||
}
|
||||
|
||||
const listingCaseEntries = Object.entries( listingsCases )
|
||||
|
||||
test.before(async t => {
|
||||
|
||||
t.context.listings = {}
|
||||
|
||||
for ( const [ caseEndpoint, listingCase ] of listingCaseEntries ) {
|
||||
const { endpoint } = listingCase
|
||||
|
||||
const apiPath = makeApiPathFromEndpoint( caseEndpoint )
|
||||
const localPath = `./static${ apiPath }`
|
||||
|
||||
// Check if the endpoint exists locally
|
||||
// so we don't have to wait for the API
|
||||
if ( await fs.pathExists( localPath ) ) {
|
||||
console.log('Using local endpoint data for', endpoint)
|
||||
t.context.listings[ caseEndpoint ] = await fs.readJson( localPath )
|
||||
continue
|
||||
}
|
||||
|
||||
const { data } = await axios.get(`${ process.env.PUBLIC_API_DOMAIN }${ apiPath }`)
|
||||
|
||||
t.context.listings[ caseEndpoint ] = data
|
||||
}
|
||||
|
||||
t.context.listingsDetails = {}
|
||||
|
||||
for ( const [ caseEndpoint ] of listingCaseEntries ) {
|
||||
t.context.listingsDetails[ caseEndpoint ] = new ListingDetails( t.context.listings[ caseEndpoint ] )
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
function parseHTML ( htmlString ) {
|
||||
const dom = new JSDOM( htmlString )
|
||||
|
||||
return {
|
||||
dom,
|
||||
window: dom.window,
|
||||
document: dom.window.document
|
||||
}
|
||||
}
|
||||
|
||||
test( 'Listings have valid api endpoints', async t => {
|
||||
const { listingsDetails } = t.context
|
||||
|
||||
for ( const [ caseEndpoint, listingCase ] of listingCaseEntries ) {
|
||||
|
||||
const apiPath = listingsDetails[ caseEndpoint ].apiEndpointPath
|
||||
|
||||
t.assert( listingCase.apiEndpointPath === apiPath, `${ caseEndpoint } has a valid api endpoint` )
|
||||
}
|
||||
})
|
||||
|
||||
test( 'Listings with videos have preload data for initialVideo', async t => {
|
||||
const { listingsDetails } = t.context
|
||||
|
||||
for ( const [ caseEndpoint, listingCase ] of listingCaseEntries ) {
|
||||
|
||||
const listingDetails = listingsDetails[ caseEndpoint ]
|
||||
|
||||
t.assert( listingDetails.hasInitialVideo === listingCase.expectInitialVideo, `${ caseEndpoint } has initial video` )
|
||||
|
||||
// Stop here if we don't have an initial video
|
||||
if ( !listingDetails.hasInitialVideo ) continue
|
||||
|
||||
// t.log('listingDetails.initialVideo', listingDetails.initialVideo)
|
||||
|
||||
// Get headProperties for image preloading
|
||||
const preloadHeadChecks = headPropertyTypes[ 'link[rel="preload"]' ]
|
||||
|
||||
const images = getVideoImages( listingDetails.initialVideo )
|
||||
|
||||
// Check if the head object properties are correct
|
||||
for ( const preload of images.preloads ) {
|
||||
for ( const [ propertyName, checkMethod ] of Object.entries( preloadHeadChecks ) ) {
|
||||
// Skip count property
|
||||
if ( propertyName === 'count' ) continue
|
||||
|
||||
const value = preload[ propertyName ]
|
||||
|
||||
t.assert( checkMethod( value ), `${ propertyName } failed. Value is '${ value }' for '${ images.imgSrc }'` )
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
test('Listings have valid headings', async t => {
|
||||
const { listingsDetails } = t.context
|
||||
|
||||
for ( const [ caseEndpoint, listingCase ] of listingCaseEntries ) {
|
||||
|
||||
|
||||
// Build listing details
|
||||
const listingDetails = listingsDetails[ caseEndpoint ]
|
||||
const listingPageHead = new PageHead( listingDetails.headOptions )
|
||||
|
||||
// console.log( 'pageMeta', listingPageHead.metaMarkup )
|
||||
|
||||
// Parse into dom
|
||||
// so we can get data via selectors
|
||||
const { document } = parseHTML( listingPageHead.metaAndLinkMarkup )
|
||||
|
||||
for ( const [ selector, checks ] of Object.entries( headPropertyTypes ) ) {
|
||||
const elements = document.querySelectorAll( selector )
|
||||
|
||||
let count = 1
|
||||
|
||||
if ( has( checks, 'count' ) ) {
|
||||
count = checks.count
|
||||
// delete checks.count
|
||||
}
|
||||
|
||||
if ( count !== false ) {
|
||||
// Fail if there's more or less than one element
|
||||
t.is( elements.length, count, `${ selector } count is ${ elements.length } but should be ${ count }` )
|
||||
}
|
||||
|
||||
for( const element of elements ) {
|
||||
for ( const [ check, checkMethod ] of Object.entries( checks ) ) {
|
||||
// console.log( `Ckecking ${ selector } ${ check }` )
|
||||
|
||||
const value = element.getAttribute( check )
|
||||
|
||||
t.assert( checkMethod( value ), `${ check } on ${ selector } failed. Value is '${ value }'` )
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
test( 'Listings with videos have structured data', async t => {
|
||||
const { listingsDetails } = t.context
|
||||
|
||||
for ( const [ caseEndpoint, listingCase ] of listingCaseEntries ) {
|
||||
|
||||
const listingDetails = listingsDetails[ caseEndpoint ]
|
||||
const listingPageHead = new PageHead( {
|
||||
...listingDetails.headOptions,
|
||||
pathname: caseEndpoint
|
||||
})
|
||||
|
||||
// Stop here if we're not expecting Video Structured Data
|
||||
if ( !listingCase.shouldHaveVideoStucturedData ) {
|
||||
|
||||
// Check that the non-video listing doesn't have video structured data
|
||||
t.assert( !listingPageHead.structuredDataMarkup.includes('VideoObject'), `${ caseEndpoint } has video structured data` )
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
|
||||
// t.log('listingDetails.initialVideo', listingDetails.initialVideo)
|
||||
// t.log( 'caseEndpoint', caseEndpoint )
|
||||
|
||||
// Assert that the structured data is not empty
|
||||
t.assert( listingPageHead.structuredDataMarkup.trim() !== '', `${ caseEndpoint } has structured data` )
|
||||
|
||||
// https://github.com/glitchdigital/structured-data-testing-tool#api
|
||||
const testResult = await structuredDataTestHtml( listingPageHead.allHeadMarkup , {
|
||||
presets: [ Google ],
|
||||
schemas: [ 'VideoObject' ]
|
||||
}).then(res => {
|
||||
return res
|
||||
}).catch(err => {
|
||||
// console.warn( 'Structured Data error', err.error )
|
||||
|
||||
if (err.type === 'VALIDATION_FAILED') {
|
||||
|
||||
// t.fail( 'Some structured data tests failed.' )
|
||||
const validationError = new Error( 'Some structured data tests failed.' )
|
||||
|
||||
validationError.failed = err.res.failed
|
||||
validationError.errors = Array.from( err.res.failed ).map( fail => fail.error )
|
||||
|
||||
throw validationError
|
||||
|
||||
// return
|
||||
}
|
||||
|
||||
throw new Error( 'Structured data testing error.', err.error )
|
||||
})
|
||||
|
||||
// t.log( 'testResult', testResult )
|
||||
|
||||
// Assert that no Structured Data tests failed
|
||||
t.assert( testResult.failed.length === 0, `${ caseEndpoint } has valid structured data` )
|
||||
}
|
||||
})
|
||||
229
test/listings/index.test.ts
Normal file
229
test/listings/index.test.ts
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
import fs from 'fs-extra'
|
||||
import has from 'just-has'
|
||||
import { test, expect, beforeAll } from 'vitest'
|
||||
import axios from 'axios'
|
||||
import { JSDOM } from 'jsdom'
|
||||
import { structuredDataTestHtml } from 'structured-data-testing-tool'
|
||||
import { Google } from 'structured-data-testing-tool/presets'
|
||||
|
||||
import {
|
||||
makeApiPathFromEndpoint,
|
||||
getVideoImages,
|
||||
ListingDetails
|
||||
} from '~/helpers/listing-page.js'
|
||||
import { headPropertyTypes } from '~/test/helpers/head.js'
|
||||
import { PageHead } from '~/helpers/config-node.js'
|
||||
|
||||
const listingsCases = {
|
||||
// Spotify
|
||||
'/app/spotify': {
|
||||
endpoint: '/app/spotify',
|
||||
apiEndpointPath: '/api/app/spotify.json',
|
||||
expectInitialVideo: true,
|
||||
shouldHaveVideoStructuredData: false,
|
||||
},
|
||||
|
||||
// Electron
|
||||
'/app/electron-framework': {
|
||||
endpoint: '/app/electron-framework',
|
||||
apiEndpointPath: '/api/app/electron-framework.json',
|
||||
expectInitialVideo: false,
|
||||
shouldHaveVideoStructuredData: false,
|
||||
},
|
||||
|
||||
// Express VPN Benchmarks
|
||||
'/app/expressvpn/benchmarks/': {
|
||||
endpoint: '/app/expressvpn/benchmarks/',
|
||||
apiEndpointPath: '/api/app/expressvpn.json',
|
||||
expectInitialVideo: true,
|
||||
shouldHaveVideoStructuredData: true
|
||||
},
|
||||
|
||||
// Express VPN Benchmarks
|
||||
'/tv/install-instagram-app-on-m1-macbook-air-apple-silicon-tutorial-i-vfbmworal6i/': {
|
||||
endpoint: '/tv/install-instagram-app-on-m1-macbook-air-apple-silicon-tutorial-i-vfbmworal6i/',
|
||||
apiEndpointPath: '/api/tv/install-instagram-app-on-m1-macbook-air-apple-silicon-tutorial-i-vfbmworal6i.json',
|
||||
expectInitialVideo: true,
|
||||
shouldHaveVideoStructuredData: true
|
||||
}
|
||||
}
|
||||
|
||||
const listingCaseEntries = Object.entries(listingsCases)
|
||||
|
||||
interface TestContext {
|
||||
listings: Record<string, any>;
|
||||
listingsDetails: Record<string, ListingDetails>;
|
||||
}
|
||||
|
||||
let context: TestContext = {
|
||||
listings: {},
|
||||
listingsDetails: {}
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
for (const [caseEndpoint, listingCase] of listingCaseEntries) {
|
||||
const { endpoint } = listingCase
|
||||
const apiPath = makeApiPathFromEndpoint(caseEndpoint)
|
||||
const localPath = `./static${apiPath}`
|
||||
|
||||
// Check if endpoint exists locally to avoid API calls
|
||||
if (await fs.pathExists(localPath)) {
|
||||
console.log('Using local endpoint data for', endpoint)
|
||||
context.listings[caseEndpoint] = await fs.readJson(localPath)
|
||||
continue
|
||||
}
|
||||
|
||||
const { data } = await axios.get(`${process.env.PUBLIC_API_DOMAIN}${apiPath}`)
|
||||
context.listings[caseEndpoint] = data
|
||||
}
|
||||
|
||||
// Initialize listing details
|
||||
for (const [caseEndpoint] of listingCaseEntries) {
|
||||
context.listingsDetails[caseEndpoint] = new ListingDetails(context.listings[caseEndpoint])
|
||||
}
|
||||
})
|
||||
|
||||
function parseHTML(htmlString: string) {
|
||||
const dom = new JSDOM(htmlString)
|
||||
return {
|
||||
dom,
|
||||
window: dom.window,
|
||||
document: dom.window.document
|
||||
}
|
||||
}
|
||||
|
||||
test('Listings have valid api endpoints', async () => {
|
||||
const { listingsDetails } = context
|
||||
|
||||
for (const [caseEndpoint, listingCase] of listingCaseEntries) {
|
||||
const apiPath = listingsDetails[caseEndpoint].apiEndpointPath
|
||||
expect(listingCase.apiEndpointPath).toBe(apiPath)
|
||||
}
|
||||
})
|
||||
|
||||
test.todo('Listings with videos have preload data for initialVideo', async () => {
|
||||
const { listingsDetails } = context
|
||||
|
||||
for (const [caseEndpoint, listingCase] of listingCaseEntries) {
|
||||
const listingDetails = listingsDetails[caseEndpoint]
|
||||
|
||||
expect(
|
||||
listingDetails.hasInitialVideo === listingCase.expectInitialVideo,
|
||||
`${caseEndpoint} has initial video`
|
||||
).toBeTruthy()
|
||||
|
||||
// Stop here if we don't have an initial video
|
||||
if (!listingDetails.hasInitialVideo) continue
|
||||
|
||||
// Get headProperties for image preloading
|
||||
const preloadHeadChecks = headPropertyTypes['link[rel="preload"]']
|
||||
const images = getVideoImages(listingDetails.initialVideo)
|
||||
|
||||
// Check if the head object properties are correct
|
||||
for (const preload of images.preloads) {
|
||||
for (const [propertyName, checkMethod] of Object.entries(preloadHeadChecks)) {
|
||||
// Skip count property
|
||||
if (propertyName === 'count') continue
|
||||
|
||||
const value = preload[propertyName]
|
||||
expect(
|
||||
checkMethod,
|
||||
`${propertyName} failed. Value is '${value}' for '${images.imgSrc}'`
|
||||
).toBeTruthy()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test.todo('Listings have valid headings', async () => {
|
||||
const { listingsDetails } = context
|
||||
|
||||
for (const [caseEndpoint] of listingCaseEntries) {
|
||||
// Build listing details
|
||||
const listingDetails = listingsDetails[caseEndpoint]
|
||||
const listingPageHead = new PageHead(listingDetails.headOptions)
|
||||
|
||||
// Parse into dom so we can get data via selectors
|
||||
const { document } = parseHTML(listingPageHead.metaAndLinkMarkup)
|
||||
|
||||
for (const [selector, checks] of Object.entries(headPropertyTypes)) {
|
||||
const elements = document.querySelectorAll(selector)
|
||||
|
||||
let count = 1
|
||||
if (has(checks, 'count')) {
|
||||
count = checks.count
|
||||
}
|
||||
|
||||
if ( count !== 0 ) {
|
||||
// Fail if there's more or less than one element
|
||||
expect(
|
||||
elements.length,
|
||||
`${selector} count is ${elements.length} but should be ${count}`
|
||||
).toBe(count)
|
||||
}
|
||||
|
||||
for (const element of elements) {
|
||||
for (const [check, checkMethod] of Object.entries(checks)) {
|
||||
const value = element.getAttribute(check)
|
||||
expect(
|
||||
checkMethod,
|
||||
`${check} on ${selector} failed. Value is '${value}'`
|
||||
).toBeTruthy()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test.todo('Listings with videos have structured data', async () => {
|
||||
const { listingsDetails } = context
|
||||
|
||||
for (const [caseEndpoint, listingCase] of listingCaseEntries) {
|
||||
const listingDetails = listingsDetails[caseEndpoint]
|
||||
const listingPageHead = new PageHead({
|
||||
...listingDetails.headOptions,
|
||||
pathname: caseEndpoint
|
||||
})
|
||||
|
||||
// Stop here if we're not expecting Video Structured Data
|
||||
if (!listingCase.shouldHaveVideoStructuredData) {
|
||||
// Check that the non-video listing doesn't have video structured data
|
||||
expect(
|
||||
!listingPageHead.structuredDataMarkup.includes('VideoObject'),
|
||||
`${caseEndpoint} has video structured data`
|
||||
).toBeTruthy()
|
||||
continue
|
||||
}
|
||||
|
||||
// Assert that the structured data is not empty
|
||||
expect(
|
||||
listingPageHead.structuredDataMarkup.trim() !== '',
|
||||
`${caseEndpoint} has structured data`
|
||||
).toBeTruthy()
|
||||
|
||||
try {
|
||||
const testResult = await structuredDataTestHtml(
|
||||
listingPageHead.allHeadMarkup,
|
||||
{
|
||||
presets: [Google],
|
||||
schemas: ['VideoObject']
|
||||
}
|
||||
)
|
||||
|
||||
// Assert that no Structured Data tests failed
|
||||
expect(
|
||||
testResult.failed.length,
|
||||
`${caseEndpoint} has valid structured data`
|
||||
).toBe(0)
|
||||
} catch (err) {
|
||||
if (err.type === 'VALIDATION_FAILED') {
|
||||
console.error({
|
||||
failed: err.res.failed,
|
||||
// errors: Array.from(err.res.failed).map(fail => fail?.error!)
|
||||
})
|
||||
throw new Error('Some structured data tests failed. ')
|
||||
}
|
||||
throw new Error('Structured data testing error.', err.error)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
import test from 'ava'
|
||||
// import MarkdownIt from 'markdown-it'
|
||||
|
||||
// import { isValidHttpUrl } from '~/helpers/check-types.js'
|
||||
import { StorkFilters } from '~/helpers/stork/browser.js'
|
||||
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
|
||||
test('Can Toggle off existing filter' , async t => {
|
||||
const filters = new StorkFilters({
|
||||
initialFilters: {
|
||||
'test': 'yes'
|
||||
}
|
||||
})
|
||||
|
||||
filters.toggleFilter('test')
|
||||
|
||||
t.deepEqual(filters.has('test'), false)
|
||||
|
||||
filters.toggleFilter('test', 'yes')
|
||||
filters.toggleFilter('status', 'native')
|
||||
|
||||
t.deepEqual(filters.has('test'), true, 'Has test filter')
|
||||
|
||||
t.deepEqual(filters.asQuery, 'test_yes status_native', 'Has correct filters for query')
|
||||
|
||||
filters.toggleFilter('status_native')
|
||||
|
||||
t.deepEqual(filters.asQuery, 'test_yes', 'Has only test filter')
|
||||
})
|
||||
|
||||
|
||||
test('Can handle query values with multiple underscores', async t => {
|
||||
const filters = new StorkFilters({
|
||||
initialFilters: {
|
||||
'test': 'value_with_multiple_underscores'
|
||||
}
|
||||
})
|
||||
|
||||
t.log( 'filters.asQuery', filters.asQuery )
|
||||
|
||||
t.assert( filters.has( 'test_value_with_multiple_underscores' ) , 'Has correct filters for query' )
|
||||
})
|
||||
|
||||
|
||||
test( 'Can update existing filter', async t => {
|
||||
const filters = new StorkFilters({
|
||||
initialFilters: {
|
||||
'test': 'works_no'
|
||||
}
|
||||
})
|
||||
|
||||
filters.toggleFilter('test_works_yes')
|
||||
|
||||
t.deepEqual( filters.asQuery, 'test_works_yes', 'Has updated filter')
|
||||
})
|
||||
|
||||
|
||||
test( 'Can set filters from string', async t => {
|
||||
const filters = new StorkFilters()
|
||||
|
||||
filters.setFromString( 'test_works_yes' )
|
||||
|
||||
t.deepEqual( filters.asQuery, 'test_works_yes', 'Has updated filter')
|
||||
})
|
||||
88
test/prebuild/filters.test.js
Normal file
88
test/prebuild/filters.test.js
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { StorkFilters } from '~/helpers/stork/browser.js'
|
||||
|
||||
/**
|
||||
* Tests for StorkFilters class which handles filter management and query string
|
||||
* generation for Stork search
|
||||
*/
|
||||
describe('StorkFilters', () => {
|
||||
// let filters
|
||||
|
||||
// beforeEach(() => {
|
||||
// filters = new StorkFilters()
|
||||
// })
|
||||
|
||||
// User Story: As a user, I want to toggle filters on/off so I can refine my search
|
||||
describe('filter toggling', () => {
|
||||
it('should toggle off an existing filter', () => {
|
||||
const filters = new StorkFilters({
|
||||
initialFilters: { test: 'yes' }
|
||||
})
|
||||
|
||||
filters.toggleFilter('test')
|
||||
expect(filters.has('test')).toBe(false)
|
||||
})
|
||||
|
||||
it('should toggle on multiple filters', () => {
|
||||
const filters = new StorkFilters({
|
||||
initialFilters: { test: 'yes' }
|
||||
})
|
||||
|
||||
// filters.toggleFilter('test', 'yes')
|
||||
filters.toggleFilter('status', 'native')
|
||||
|
||||
expect(filters.has('test')).toBe( true )
|
||||
expect(filters.asQuery).toBe('test_yes status_native')
|
||||
})
|
||||
|
||||
it('should remove a specific filter', () => {
|
||||
const filters = new StorkFilters({
|
||||
initialFilters: {
|
||||
test: 'yes',
|
||||
status: 'native'
|
||||
}
|
||||
})
|
||||
|
||||
filters.toggleFilter('status_native')
|
||||
expect(filters.asQuery).toBe('test_yes')
|
||||
})
|
||||
})
|
||||
|
||||
// User Story: As a user, I want to use complex filter values to enable detailed searching
|
||||
describe('complex filter values', () => {
|
||||
it('should handle values with multiple underscores', () => {
|
||||
const filters = new StorkFilters({
|
||||
initialFilters: {
|
||||
test: 'value_with_multiple_underscores'
|
||||
}
|
||||
})
|
||||
|
||||
expect(filters.has('test_value_with_multiple_underscores')).toBe(true)
|
||||
})
|
||||
|
||||
it('should update existing filter value', () => {
|
||||
const filters = new StorkFilters({
|
||||
initialFilters: {
|
||||
test: 'works_no'
|
||||
}
|
||||
})
|
||||
|
||||
filters.toggleFilter('test_works_yes')
|
||||
expect(filters.asQuery).toBe('test_works_yes')
|
||||
})
|
||||
})
|
||||
|
||||
// User Story: As a user, I want to set filters from a query string to restore search state
|
||||
describe('filter initialization', () => {
|
||||
it('should set filters from query string', () => {
|
||||
const filters = new StorkFilters({
|
||||
initialFilters: {
|
||||
test: 'works_no'
|
||||
}
|
||||
})
|
||||
|
||||
filters.setFromString('test_works_yes')
|
||||
expect(filters.asQuery).toBe('test_works_yes')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -1,238 +0,0 @@
|
|||
import fs from 'fs-extra'
|
||||
import test from 'ava'
|
||||
// import MarkdownIt from 'markdown-it'
|
||||
|
||||
import { isValidHttpUrl } from '~/helpers/check-types.js'
|
||||
import { buildReadmeAppList } from '~/helpers/build-app-list.js'
|
||||
import {
|
||||
matchesWholeWord,
|
||||
fuzzyMatchesWholeWord,
|
||||
eitherMatches
|
||||
} from '~/helpers/matching.js'
|
||||
import {
|
||||
PaginatedList
|
||||
} from '~/helpers/api/pagination.js'
|
||||
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
const allowedTitleCharacters = new Set( 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 -+:_.®/\()音乐体验版'.split('') )
|
||||
|
||||
// Detect Emojis(Extended Pictograph) in string
|
||||
// https://stackoverflow.com/a/64007175/1397641
|
||||
function hasEmoji ( string ) {
|
||||
return /\p{Extended_Pictographic}/u.test( string )
|
||||
}
|
||||
|
||||
test.before(async t => {
|
||||
const readmeFileContent = await fs.readFile('./README.md', 'utf-8')
|
||||
|
||||
|
||||
// Store sitemap urls to context
|
||||
t.context.readmeFileContent = readmeFileContent
|
||||
t.context.readmeAppList = buildReadmeAppList({
|
||||
readmeContent: t.context.readmeFileContent,
|
||||
scanListMap: new Map(),
|
||||
commits: []
|
||||
})
|
||||
})
|
||||
|
||||
test('README Apps are formated correctly', (t) => {
|
||||
// console.log('t.context.sitemapUrls', t.context.sitemapUrls)
|
||||
|
||||
const {
|
||||
readmeAppList
|
||||
} = t.context
|
||||
|
||||
// Store found apps so we can check for duplicates
|
||||
const foundApps = new Set()
|
||||
|
||||
// Store found invalid apps so we can count and report them
|
||||
const invalidApps = new Set()
|
||||
|
||||
|
||||
for (const readmeApp of readmeAppList) {
|
||||
const cleanedAppName = readmeApp.name//.toLowerCase()
|
||||
|
||||
// Check that app has not already been found
|
||||
if (foundApps.has(cleanedAppName)) {
|
||||
t.fail(`Duplicate app found: ${readmeApp.name}`)
|
||||
invalidApps.add(cleanedAppName)
|
||||
}
|
||||
// Store this app so we can check for future duplicates
|
||||
foundApps.add(cleanedAppName)
|
||||
|
||||
// Check that all related links urls are valid
|
||||
for (const relatedLink of readmeApp.relatedLinks) {
|
||||
if ( !isValidHttpUrl( relatedLink.href ) ) {
|
||||
t.log('relatedLink.href', readmeApp.name, relatedLink.href)
|
||||
|
||||
t.fail(`README App ${readmeApp.name} does not have valid url`, readmeApp.url)
|
||||
invalidApps.add(cleanedAppName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check that status text is free of markdown
|
||||
if ( readmeApp.text.includes('](') ) {
|
||||
t.fail(`README App ${readmeApp.name} markdown in status text`)
|
||||
invalidApps.add(cleanedAppName)
|
||||
}
|
||||
|
||||
// Check that status has an emoji
|
||||
if ( hasEmoji( readmeApp.text ) === false ) {
|
||||
t.fail(`README App ${readmeApp.name} does not have emoji`)
|
||||
invalidApps.add(cleanedAppName)
|
||||
}
|
||||
|
||||
// Check for not allowed characters in app name
|
||||
for ( const character of cleanedAppName ) {
|
||||
if ( !allowedTitleCharacters.has( character ) ) {
|
||||
|
||||
// badCharacter = readmeApp.name[firstBadCharacterIndex]
|
||||
|
||||
// t.log( readmeApp )
|
||||
t.fail(`README App Title ${readmeApp.name} has non-alphanumeric character ${character}(charCode ${character.charCodeAt(0)})`)
|
||||
invalidApps.add(cleanedAppName)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
t.log( readmeAppList.length - invalidApps.size, 'valid apps found' )
|
||||
t.log( readmeAppList.length, 'apps found in README' )
|
||||
|
||||
t.pass()
|
||||
})
|
||||
|
||||
|
||||
function sortAppsAlphabetically ( a, b ) {
|
||||
return a.name.localeCompare(b.name)
|
||||
}
|
||||
|
||||
|
||||
test('README Apps are in alphbetical order', (t) => {
|
||||
|
||||
const {
|
||||
readmeAppList
|
||||
} = t.context
|
||||
|
||||
const appsByCategory = new Map()
|
||||
|
||||
|
||||
|
||||
// Group apps by category
|
||||
for ( const readmeApp of readmeAppList ) {
|
||||
const category = readmeApp.category.slug
|
||||
|
||||
if ( !appsByCategory.has(category) ) {
|
||||
appsByCategory.set(category, [])
|
||||
}
|
||||
|
||||
appsByCategory.get( category ).push(readmeApp)
|
||||
}
|
||||
|
||||
// Sort apps in groups alphabetically
|
||||
for ( const [ category, apps ] of appsByCategory ) {
|
||||
|
||||
const unsortedApps = apps.slice()
|
||||
|
||||
// Sort apps in category in place
|
||||
apps.sort(sortAppsAlphabetically)
|
||||
|
||||
// Check sorted sorted apps against unsorted apps
|
||||
for ( const [ index, unsortedApp ] of unsortedApps.entries() ) {
|
||||
const sortedApp = apps[index]
|
||||
|
||||
if ( sortedApp.slug !== unsortedApp.slug ) {
|
||||
t.fail(`README App at index ${index} of ${category} is ${unsortedApp.name} but should be ${sortedApp.name}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.pass()
|
||||
})
|
||||
|
||||
|
||||
|
||||
const namesWithPlusses = [
|
||||
'Xournal++',
|
||||
'Notepad++'
|
||||
]
|
||||
|
||||
test('Can match names with pluses', (t) => {
|
||||
|
||||
|
||||
|
||||
// Sort apps in groups alphabetically
|
||||
for ( const nameWithPluses of namesWithPlusses ) {
|
||||
|
||||
const haystack = `FDKLS:KF ${nameWithPluses}NDFLSKFLSJDK`
|
||||
|
||||
t.assert( matchesWholeWord( nameWithPluses, haystack ) )
|
||||
|
||||
t.assert( fuzzyMatchesWholeWord( nameWithPluses, haystack ) )
|
||||
|
||||
t.assert( eitherMatches( nameWithPluses, haystack ) )
|
||||
t.assert( eitherMatches( haystack, nameWithPluses ) )
|
||||
}
|
||||
|
||||
t.pass()
|
||||
})
|
||||
|
||||
|
||||
test('Can paginate', async (t) => {
|
||||
const cases = [
|
||||
{
|
||||
from: {
|
||||
list: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
|
||||
perPage: 2
|
||||
},
|
||||
expect: {
|
||||
pageCount: 5,
|
||||
pages: [
|
||||
{
|
||||
number: 1,
|
||||
hasNextPage: true,
|
||||
hasPreviousPage: false,
|
||||
items: [1, 2],
|
||||
json: '[1,2]'
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
hasNextPage: true,
|
||||
hasPreviousPage: true,
|
||||
items: [3, 4],
|
||||
json: '[3,4]'
|
||||
},
|
||||
|
||||
// Last page should have less than perPage items
|
||||
{
|
||||
number: 5,
|
||||
hasNextPage: false,
|
||||
hasPreviousPage: true,
|
||||
items: [9],
|
||||
json: '[9]'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
for ( const { from, expect } of cases ) {
|
||||
|
||||
const paginatedList = new PaginatedList( from )
|
||||
|
||||
// Assert that page count is correct
|
||||
t.is( paginatedList.pageCount, expect.pageCount, 'pageCount is incorrect' )
|
||||
|
||||
// Assert that the pages we're expecting are there
|
||||
for ( const expectedPage of expect.pages ) {
|
||||
// Get respective output page
|
||||
const outputPage = paginatedList.pages[ expectedPage.number - 1 ]
|
||||
|
||||
t.deepEqual( outputPage, expectedPage, `Page ${ expectedPage.number } is an unexpected structure` )
|
||||
}
|
||||
}
|
||||
|
||||
} )
|
||||
172
test/prebuild/index.test.js
Normal file
172
test/prebuild/index.test.js
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
import fs from 'fs-extra'
|
||||
import { describe, it, expect, beforeAll } from 'vitest'
|
||||
import { isValidHttpUrl } from '~/helpers/check-types.js'
|
||||
import { buildReadmeAppList } from '~/helpers/build-app-list.js'
|
||||
import {
|
||||
matchesWholeWord,
|
||||
fuzzyMatchesWholeWord,
|
||||
eitherMatches
|
||||
} from '~/helpers/matching.js'
|
||||
import { PaginatedList } from '~/helpers/api/pagination.js'
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
const allowedTitleCharacters = new Set(
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 -+:_.®/\()音乐体验版'.split('')
|
||||
)
|
||||
|
||||
/**
|
||||
* Detect Emojis(Extended Pictograph) in string
|
||||
* https://stackoverflow.com/a/64007175/1397641
|
||||
*/
|
||||
function hasEmoji(string) {
|
||||
return /\p{Extended_Pictographic}/u.test(string)
|
||||
}
|
||||
|
||||
describe('README Validation', () => {
|
||||
let readmeFileContent
|
||||
let readmeAppList
|
||||
|
||||
beforeAll(async () => {
|
||||
readmeFileContent = await fs.readFile('./README.md', 'utf-8')
|
||||
readmeAppList = buildReadmeAppList({
|
||||
readmeContent: readmeFileContent,
|
||||
scanListMap: new Map(),
|
||||
commits: []
|
||||
})
|
||||
})
|
||||
|
||||
// User Story: As a maintainer, I want to ensure README apps are properly formatted
|
||||
describe('app formatting', () => {
|
||||
it('should have correctly formatted apps', () => {
|
||||
const foundApps = new Set()
|
||||
const invalidApps = new Set()
|
||||
|
||||
for (const readmeApp of readmeAppList) {
|
||||
const cleanedAppName = readmeApp.name
|
||||
|
||||
// Check for duplicates
|
||||
if (foundApps.has(cleanedAppName)) {
|
||||
expect.fail(`Duplicate app found: ${readmeApp.name}`)
|
||||
invalidApps.add(cleanedAppName)
|
||||
}
|
||||
foundApps.add(cleanedAppName)
|
||||
|
||||
// Validate related links
|
||||
for (const relatedLink of readmeApp.relatedLinks) {
|
||||
expect(isValidHttpUrl(relatedLink.href))
|
||||
.toBe(true, `README App ${readmeApp.name} has invalid URL: ${relatedLink.href}`)
|
||||
}
|
||||
|
||||
// Check status text formatting
|
||||
expect(readmeApp.text.includes(']('))
|
||||
.toBe(false, `README App ${readmeApp.name} has markdown in status text`)
|
||||
|
||||
// Verify emoji presence
|
||||
expect(hasEmoji(readmeApp.text))
|
||||
.toBe(true, `README App ${readmeApp.name} does not have emoji`)
|
||||
|
||||
// Validate app name characters
|
||||
for (const character of cleanedAppName) {
|
||||
expect(allowedTitleCharacters.has(character))
|
||||
.toBe(true, `README App Title ${readmeApp.name} has invalid character ${character}`)
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`${readmeAppList.length - invalidApps.size} valid apps found`)
|
||||
console.log(`${readmeAppList.length} total apps found in README`)
|
||||
})
|
||||
})
|
||||
|
||||
// User Story: As a maintainer, I want apps sorted alphabetically within categories
|
||||
describe('app sorting', () => {
|
||||
it('should have apps in alphabetical order within categories', () => {
|
||||
const appsByCategory = new Map()
|
||||
|
||||
// Group apps by category
|
||||
for (const readmeApp of readmeAppList) {
|
||||
const category = readmeApp.category.slug
|
||||
if (!appsByCategory.has(category)) {
|
||||
appsByCategory.set(category, [])
|
||||
}
|
||||
appsByCategory.get(category).push(readmeApp)
|
||||
}
|
||||
|
||||
// Verify sorting within categories
|
||||
for (const [category, apps] of appsByCategory) {
|
||||
const unsortedApps = [...apps]
|
||||
const sortedApps = [...apps].sort((a, b) => a.name.localeCompare(b.name))
|
||||
|
||||
sortedApps.forEach((sortedApp, index) => {
|
||||
expect(sortedApp.slug)
|
||||
.toBe(unsortedApps[index].slug,
|
||||
`App at index ${index} of ${category} is out of order`)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// User Story: As a developer, I want to ensure special characters in names are handled correctly
|
||||
describe('Name Matching', () => {
|
||||
const namesWithPlusses = ['Xournal++', 'Notepad++']
|
||||
|
||||
it('should match names containing plus symbols', () => {
|
||||
for (const nameWithPlusses of namesWithPlusses) {
|
||||
const haystack = `FDKLS:KF ${nameWithPlusses}NDFLSKFLSJDK`
|
||||
|
||||
expect(matchesWholeWord(nameWithPlusses, haystack)).toBe(true)
|
||||
expect(fuzzyMatchesWholeWord(nameWithPlusses, haystack)).toBe(true)
|
||||
expect(eitherMatches(nameWithPlusses, haystack)).toBe(true)
|
||||
expect(eitherMatches(haystack, nameWithPlusses)).toBe(true)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// User Story: As a developer, I want to ensure pagination works correctly
|
||||
describe('Pagination', () => {
|
||||
it('should paginate lists correctly', () => {
|
||||
const testCase = {
|
||||
list: [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
perPage: 2,
|
||||
expectedPageCount: 5,
|
||||
expectedPages: [
|
||||
{
|
||||
number: 1,
|
||||
hasNextPage: true,
|
||||
hasPreviousPage: false,
|
||||
items: [1, 2],
|
||||
json: '[1,2]'
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
hasNextPage: true,
|
||||
hasPreviousPage: true,
|
||||
items: [3, 4],
|
||||
json: '[3,4]'
|
||||
},
|
||||
{
|
||||
number: 5,
|
||||
hasNextPage: false,
|
||||
hasPreviousPage: true,
|
||||
items: [9],
|
||||
json: '[9]'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const paginatedList = new PaginatedList({
|
||||
list: testCase.list,
|
||||
perPage: testCase.perPage
|
||||
})
|
||||
|
||||
expect(paginatedList.pageCount)
|
||||
.toBe(testCase.expectedPageCount, 'Incorrect page count')
|
||||
|
||||
testCase.expectedPages.forEach(expectedPage => {
|
||||
const actualPage = paginatedList.pages[expectedPage.number - 1]
|
||||
expect(actualPage)
|
||||
.toEqual(expectedPage, `Page ${expectedPage.number} has unexpected structure`)
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue