@@ -278,10 +278,94 @@ module('Route | crate.settings', hooks => {
278278 } ) ;
279279
280280 module ( 'trustpub_only checkbox' , function ( ) {
281+ test ( 'hidden when no configs and flag is false' , async function ( assert ) {
282+ const { crate, user } = prepare ( this ) ;
283+ this . authenticateAs ( user ) ;
284+
285+ await visit ( `/crates/${ crate . name } /settings` ) ;
286+
287+ assert . dom ( '[data-test-trustpub-only-checkbox]' ) . doesNotExist ( ) ;
288+ } ) ;
289+
290+ test ( 'visible when GitHub configs exist' , async function ( assert ) {
291+ const { crate, user } = prepare ( this ) ;
292+ this . authenticateAs ( user ) ;
293+
294+ this . db . trustpubGithubConfig . create ( {
295+ crate,
296+ repository_owner : 'rust-lang' ,
297+ repository_name : 'crates.io' ,
298+ workflow_filename : 'ci.yml' ,
299+ } ) ;
300+
301+ await visit ( `/crates/${ crate . name } /settings` ) ;
302+
303+ assert . dom ( '[data-test-trustpub-only-checkbox]' ) . exists ( ) ;
304+ assert . dom ( '[data-test-trustpub-only-checkbox] [data-test-checkbox]' ) . isNotChecked ( ) ;
305+ } ) ;
306+
307+ test ( 'visible when GitLab configs exist' , async function ( assert ) {
308+ const { crate, user } = prepare ( this ) ;
309+ this . authenticateAs ( user ) ;
310+
311+ this . db . trustpubGitlabConfig . create ( {
312+ crate,
313+ namespace : 'rust-lang' ,
314+ project : 'crates.io' ,
315+ workflow_filepath : '.gitlab-ci.yml' ,
316+ } ) ;
317+
318+ await visit ( `/crates/${ crate . name } /settings` ) ;
319+
320+ assert . dom ( '[data-test-trustpub-only-checkbox]' ) . exists ( ) ;
321+ assert . dom ( '[data-test-trustpub-only-checkbox] [data-test-checkbox]' ) . isNotChecked ( ) ;
322+ } ) ;
323+
324+ test ( 'visible when flag is true but no configs' , async function ( assert ) {
325+ const { crate, user } = prepare ( this ) ;
326+ this . db . crate . update ( { where : { id : { equals : crate . id } } , data : { trustpubOnly : true } } ) ;
327+ this . authenticateAs ( user ) ;
328+
329+ await visit ( `/crates/${ crate . name } /settings` ) ;
330+
331+ assert . dom ( '[data-test-trustpub-only-checkbox]' ) . exists ( ) ;
332+ assert . dom ( '[data-test-trustpub-only-checkbox] [data-test-checkbox]' ) . isChecked ( ) ;
333+ } ) ;
334+
335+ test ( 'stays visible after disabling when no configs exist' , async function ( assert ) {
336+ const { crate, user } = prepare ( this ) ;
337+ this . db . crate . update ( { where : { id : { equals : crate . id } } , data : { trustpubOnly : true } } ) ;
338+ this . authenticateAs ( user ) ;
339+
340+ await visit ( `/crates/${ crate . name } /settings` ) ;
341+
342+ assert . dom ( '[data-test-trustpub-only-checkbox]' ) . exists ( ) ;
343+ assert . dom ( '[data-test-trustpub-only-checkbox] [data-test-checkbox]' ) . isChecked ( ) ;
344+
345+ await click ( '[data-test-trustpub-only-checkbox] [data-test-checkbox]' ) ;
346+
347+ // Checkbox stays visible after disabling (within same page visit)
348+ assert . dom ( '[data-test-trustpub-only-checkbox]' ) . exists ( ) ;
349+ assert . dom ( '[data-test-trustpub-only-checkbox] [data-test-checkbox]' ) . isNotChecked ( ) ;
350+
351+ // After navigating away and back, checkbox should be hidden
352+ await visit ( `/crates/${ crate . name } ` ) ;
353+ await visit ( `/crates/${ crate . name } /settings` ) ;
354+
355+ assert . dom ( '[data-test-trustpub-only-checkbox]' ) . doesNotExist ( ) ;
356+ } ) ;
357+
281358 test ( 'enabling trustpub_only' , async function ( assert ) {
282359 const { crate, user } = prepare ( this ) ;
283360 this . authenticateAs ( user ) ;
284361
362+ this . db . trustpubGithubConfig . create ( {
363+ crate,
364+ repository_owner : 'rust-lang' ,
365+ repository_name : 'crates.io' ,
366+ workflow_filename : 'ci.yml' ,
367+ } ) ;
368+
285369 await visit ( `/crates/${ crate . name } /settings` ) ;
286370
287371 assert . dom ( '[data-test-trustpub-only-checkbox] [data-test-checkbox]' ) . isNotChecked ( ) ;
@@ -298,6 +382,13 @@ module('Route | crate.settings', hooks => {
298382 this . db . crate . update ( { where : { id : { equals : crate . id } } , data : { trustpubOnly : true } } ) ;
299383 this . authenticateAs ( user ) ;
300384
385+ this . db . trustpubGithubConfig . create ( {
386+ crate,
387+ repository_owner : 'rust-lang' ,
388+ repository_name : 'crates.io' ,
389+ workflow_filename : 'ci.yml' ,
390+ } ) ;
391+
301392 await visit ( `/crates/${ crate . name } /settings` ) ;
302393
303394 assert . dom ( '[data-test-trustpub-only-checkbox] [data-test-checkbox]' ) . isChecked ( ) ;
@@ -313,6 +404,13 @@ module('Route | crate.settings', hooks => {
313404 const { crate, user } = prepare ( this ) ;
314405 this . authenticateAs ( user ) ;
315406
407+ this . db . trustpubGithubConfig . create ( {
408+ crate,
409+ repository_owner : 'rust-lang' ,
410+ repository_name : 'crates.io' ,
411+ workflow_filename : 'ci.yml' ,
412+ } ) ;
413+
316414 let deferred = defer ( ) ;
317415 this . worker . use ( http . patch ( '/api/v1/crates/:name' , ( ) => deferred . promise ) ) ;
318416
0 commit comments