1
- import { currentURL , visit } from '@ember/test-helpers' ;
1
+ import { currentURL } from '@ember/test-helpers' ;
2
2
import { module , test } from 'qunit' ;
3
3
4
4
import percySnapshot from '@percy/ember' ;
@@ -8,6 +8,7 @@ import { getPageTitle } from 'ember-page-title/test-support';
8
8
import { setupApplicationTest } from 'cargo/tests/helpers' ;
9
9
10
10
import axeConfig from '../axe-config' ;
11
+ import { visit } from '../helpers/visit-ignoring-abort' ;
11
12
12
13
module ( 'Acceptance | crate dependencies page' , function ( hooks ) {
13
14
setupApplicationTest ( hooks ) ;
@@ -39,17 +40,70 @@ module('Acceptance | crate dependencies page', function (hooks) {
39
40
assert . dom ( '[data-test-dev-dependencies] li' ) . doesNotExist ( ) ;
40
41
} ) ;
41
42
43
+ test ( 'shows an error page if crate not found' , async function ( assert ) {
44
+ await visit ( '/crates/foo/1.0.0/dependencies' ) ;
45
+ assert . equal ( currentURL ( ) , '/crates/foo/1.0.0/dependencies' ) ;
46
+ assert . dom ( '[data-test-404-page]' ) . exists ( ) ;
47
+ assert . dom ( '[data-test-title]' ) . hasText ( 'foo: Crate not found' ) ;
48
+ assert . dom ( '[data-test-go-back]' ) . exists ( ) ;
49
+ assert . dom ( '[data-test-try-again]' ) . doesNotExist ( ) ;
50
+ } ) ;
51
+
52
+ test ( 'shows an error page if crate fails to load' , async function ( assert ) {
53
+ this . server . get ( '/api/v1/crates/:crate_name' , { } , 500 ) ;
54
+
55
+ await visit ( '/crates/foo/1.0.0/dependencies' ) ;
56
+ assert . equal ( currentURL ( ) , '/crates/foo/1.0.0/dependencies' ) ;
57
+ assert . dom ( '[data-test-404-page]' ) . exists ( ) ;
58
+ assert . dom ( '[data-test-title]' ) . hasText ( 'foo: Failed to load crate data' ) ;
59
+ assert . dom ( '[data-test-go-back]' ) . doesNotExist ( ) ;
60
+ assert . dom ( '[data-test-try-again]' ) . exists ( ) ;
61
+ } ) ;
62
+
63
+ test ( 'shows an error page if version is not found' , async function ( assert ) {
64
+ let crate = this . server . create ( 'crate' , { name : 'foo' } ) ;
65
+ this . server . create ( 'version' , { crate, num : '2.0.0' } ) ;
66
+
67
+ await visit ( '/crates/foo/1.0.0/dependencies' ) ;
68
+ assert . equal ( currentURL ( ) , '/crates/foo/1.0.0/dependencies' ) ;
69
+ assert . dom ( '[data-test-404-page]' ) . exists ( ) ;
70
+ assert . dom ( '[data-test-title]' ) . hasText ( 'foo: Version 1.0.0 not found' ) ;
71
+ assert . dom ( '[data-test-go-back]' ) . exists ( ) ;
72
+ assert . dom ( '[data-test-try-again]' ) . doesNotExist ( ) ;
73
+ } ) ;
74
+
75
+ test ( 'shows an error page if versions fail to load' , async function ( assert ) {
76
+ let crate = this . server . create ( 'crate' , { name : 'foo' } ) ;
77
+ this . server . create ( 'version' , { crate, num : '2.0.0' } ) ;
78
+
79
+ this . server . get ( '/api/v1/crates/:crate_name/versions' , { } , 500 ) ;
80
+
81
+ // Load `crate` and then explicitly unload the side-loaded `versions`.
82
+ let store = this . owner . lookup ( 'service:store' ) ;
83
+ let crateRecord = await store . findRecord ( 'crate' , 'foo' ) ;
84
+ let versions = crateRecord . hasMany ( 'versions' ) . value ( ) ;
85
+ versions . forEach ( record => record . unloadRecord ( ) ) ;
86
+
87
+ await visit ( '/crates/foo/1.0.0/dependencies' ) ;
88
+ assert . equal ( currentURL ( ) , '/crates/foo/1.0.0/dependencies' ) ;
89
+ assert . dom ( '[data-test-404-page]' ) . exists ( ) ;
90
+ assert . dom ( '[data-test-title]' ) . hasText ( 'foo: Failed to load version data' ) ;
91
+ assert . dom ( '[data-test-go-back]' ) . doesNotExist ( ) ;
92
+ assert . dom ( '[data-test-try-again]' ) . exists ( ) ;
93
+ } ) ;
94
+
42
95
test ( 'shows error message if loading of dependencies fails' , async function ( assert ) {
43
- this . server . loadFixtures ( ) ;
96
+ let crate = this . server . create ( 'crate' , { name : 'foo' } ) ;
97
+ this . server . create ( 'version' , { crate, num : '1.0.0' } ) ;
44
98
45
99
this . server . get ( '/api/v1/crates/:crate_name/:version_num/dependencies' , { } , 500 ) ;
46
100
47
- await visit ( '/crates/nanomsg /dependencies' ) ;
48
- assert . equal ( currentURL ( ) , '/crates/nanomsg ' ) ;
49
-
50
- assert
51
- . dom ( '[data-test-notification-message="error" ]' )
52
- . hasText ( "Failed to load the list of dependencies for the 'nanomsg' crate. Please try again later!" ) ;
101
+ await visit ( '/crates/foo/1.0.0 /dependencies' ) ;
102
+ assert . equal ( currentURL ( ) , '/crates/foo/1.0.0/dependencies ' ) ;
103
+ assert . dom ( '[data-test-404-page]' ) . exists ( ) ;
104
+ assert . dom ( '[data-test-title]' ) . hasText ( 'foo: Failed to load dependencies' ) ;
105
+ assert . dom ( '[data-test-go-back ]' ) . doesNotExist ( ) ;
106
+ assert . dom ( '[data-test- try- again]' ) . exists ( ) ;
53
107
} ) ;
54
108
55
109
test ( 'hides description if loading of dependency details fails' , async function ( assert ) {
0 commit comments