@@ -374,4 +374,92 @@ mutation SignupUser($user: UserInput!, $captchaToken: String!) {
374374 ` . trim ( ) + "\n" ) ;
375375 } ) ;
376376 } ) ;
377+
378+ describe ( '$isDirty' , ( ) => {
379+ it ( 'is false for newly created records' , async ( ) => {
380+ const user = store . dispatch ( 'entities/users/create' , { name : 'Snoopy' } ) ;
381+ expect ( user . $isDirty ) . toBeFalsy ( ) ;
382+ } ) ;
383+
384+ it ( 'is true for changed but unsaved records' , async ( ) => {
385+ const user = store . dispatch ( 'entities/users/create' , { name : 'Snoopy' } ) ;
386+ user . name = 'Snoop Dog' ;
387+ expect ( user . $isDirty ) . toBeTruthy ( ) ;
388+ } ) ;
389+
390+ it ( 'is false for changed and saved records' , async ( ) => {
391+ const user = store . dispatch ( 'entities/users/create' , { name : 'Snoopy' } ) ;
392+ user . name = 'Snoop Dog' ;
393+ store . dispatch ( 'entities/users/update' , { where : user . id , data : user } ) ;
394+ expect ( user . $isDirty ) . toBeFalsy ( ) ;
395+ } ) ;
396+ } ) ;
397+
398+ describe ( '$isPersisted' , ( ) => {
399+ it ( 'is false for newly created records' , async ( ) => {
400+ const user = store . dispatch ( 'entities/users/create' , { name : 'Snoopy' } ) ;
401+ expect ( user . $isPersisted ) . toBeFalsy ( ) ;
402+ } ) ;
403+
404+ it ( 'is true for persisted records' , async ( ) => {
405+ const response = {
406+ data : {
407+ createUser : {
408+ __typename : 'user' ,
409+ id : 1 ,
410+ name : 'Charlie Brown' ,
411+ posts : {
412+ __typename : 'post' ,
413+ nodes : [ ]
414+ }
415+ }
416+ }
417+ } ;
418+
419+ await sendWithMockFetch ( response , async ( ) => {
420+ await store . dispatch ( 'entities/users/persist' , { id : 1 } ) ;
421+ } ) ;
422+
423+ const user = store . getters [ 'entities/users/find' ] ( 1 ) ;
424+ expect ( user . $isPersisted ) . toBeTruthy ( ) ;
425+ } ) ;
426+
427+ it ( 'is true for fetched records' , async ( ) => {
428+ const response = {
429+ data : {
430+ user : {
431+ __typename : 'user' ,
432+ id : 1 ,
433+ name : 'Johnny Imba' ,
434+ posts : {
435+ __typename : 'post' ,
436+ nodes : [
437+ {
438+ __typename : 'post' ,
439+ id : 1 ,
440+ userId : 1 ,
441+ title : 'Example Post 1' ,
442+ content : 'Foo'
443+ } ,
444+ {
445+ __typename : 'post' ,
446+ id : 2 ,
447+ userId : 1 ,
448+ title : 'Example Post 2' ,
449+ content : 'Bar'
450+ }
451+ ]
452+ }
453+ }
454+ }
455+ } ;
456+
457+ await sendWithMockFetch ( response , async ( ) => {
458+ await store . dispatch ( 'entities/users/fetch' , { filter : { id : 1 } } ) ;
459+ } ) ;
460+
461+ const user = store . getters [ 'entities/users/find' ] ( 1 ) ;
462+ expect ( user . $isPersisted ) . toBeTruthy ( ) ;
463+ } ) ;
464+ } ) ;
377465} ) ;
0 commit comments