File size: 4,484 Bytes
ecb2a3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import test from 'node:test';
import assert from 'node:assert/strict';
import {createRequire} from 'node:module';
import {build} from 'esbuild';
import {fileURLToPath} from 'node:url';
import {normalizeBatchName,batchNameTaken,storageDescription,personalSaveAccess} from '../src/inspectionUX.mjs';
import {inspectionReadiness} from '../src/inspectionReadiness.mjs';

test('batch names reject case/spacing/compatibility variants without blocking retries',()=>{
 assert.equal(normalizeBatchName('  QA  Batch '),'qa batch');
 assert.ok(batchNameTaken('qa batch',[{batch:' QA  BATCH '}]));
 const base={health:{status:'ok',mode:'local_single_user'},files:[{name:'x.jpg',size:4,type:'image/jpeg'}],multiple:true,batch:'qa batch',knownBatches:[{batch:'QA BATCH'}]};
 assert.equal(inspectionReadiness(base).code,'duplicate_batch');
 assert.equal(inspectionReadiness({...base,retry:true}).disabled,false);
 assert.equal(inspectionReadiness({...base,batch:'new'}).disabled,false);
 assert.equal(inspectionReadiness({...base,multiple:false}).disabled,false,'Individual label grouping is unchanged');
});

test('durable private storage is gated by approved account assurance, not signup alone',()=>{
 for(const state of ['guest','checking','pending','rejected','revoked','mfa','unavailable']){
  const result=personalSaveAccess(state);assert.equal(result.allowed,false);assert.ok(result.reason.length>20);
 }
 assert.equal(personalSaveAccess('authorized').allowed,true);
 assert.match(storageDescription('browser_session'),/Temporary/);
 assert.match(storageDescription('browser_session',true),/Saved only on this computer/);
 assert.match(storageDescription('local_account'),/confirm it has also reached the online account/);
 assert.match(storageDescription('supabase_personal'),/Saved online in Personal Workspace/);
 assert.match(storageDescription(undefined),/not automatically/);
});

async function component(path,name='default'){
 const result=await build({entryPoints:[fileURLToPath(new URL(path,import.meta.url))],bundle:true,platform:'node',format:'cjs',write:false,external:['react','react-dom']});
 const require=createRequire(new URL('../package.json',import.meta.url)),module={exports:{}};
 new Function('require','module','exports',result.outputFiles[0].text)(require,module,module.exports);
 return {Component:module.exports[name]||module.exports,React:require('react'),render:require('react-dom/server').renderToStaticMarkup};
}

test('upload guidance distinguishes unprocessed selections from historical identity',async()=>{
 const {Component,React,render}=await component('../src/InspectionDraft.jsx');
 const markup=render(React.createElement(Component,{multiple:true,files:[{}]}));
 assert.match(markup,/Check up to 20 photos at once/);assert.match(markup,/1 photo ready/);assert.match(markup,/Press Inspect batch/);
 // A single-photo page never calls several selected photos "ready".
 assert.doesNotMatch(render(React.createElement(Component,{multiple:false,files:[{},{}]})),/ready/);
});

test('guest storage controls are disabled with explanation, while approved saving remains available',async()=>{
 const {Component,React,render}=await component('../src/WorkspaceShare.jsx');
 const props={record:{id:'x',storage:'browser_session'},enabled:true,messages:[]};
 const guest=render(React.createElement(Component,{...props,access:{state:'guest'}}));
 assert.match(guest,/disabled=""[^>]*>Save to Personal/);assert.match(guest,/approved Staff account and its security code/);
 const staff=render(React.createElement(Component,{...props,access:{state:'authorized'}}));
 assert.doesNotMatch(staff,/disabled=""[^>]*>Save to Personal/);
});

test('an unconfigured local gallery offers public browsing without implying automatic publication',async()=>{
 const {Component,React,render}=await component('../src/CommunityGallery.jsx','GalleryUnavailableNotice');
 const local=render(React.createElement(Component,{local:true}));
 assert.match(local,/class="note"/);assert.match(local,/Public sharing is not available from this computer yet/);
 assert.match(local,/href="https:\/\/wizzas-defectrag\.hf\.space\/#gallery"/);
 assert.match(local,/target="_blank" rel="noreferrer"/);assert.match(local,/does not publish a local inspection/);
 const cloud=render(React.createElement(Component,{local:false}));
 assert.match(cloud,/public gallery is not available yet/);assert.doesNotMatch(cloud,/<a |this device/);
});