TIL

285일차(모험 194일차) - id값 변경, test 코드

haedal-uni 2022. 6. 27. 23:47
728x90

id값 변경

동일한 작성자가 여러개의 댓글을 입력했을 때

2번째 댓글을 수정하려고 하면 제일 첫번째의 댓글이 수정되는것을 확인하고 id값을 변경했다.

 

또한 수정할 때 수정버튼과 삭제버튼이 숨겨지는데 이 또한 맨 처음 댓글의 수정, 삭제 버튼이 숨겨졌다가 나타나기 때문에 id값을 detail하게 적었다.

 

input id 값 : updateCommentInput → updateCommentInput-${commentId}

저장 버튼 id 값 : updateAftersaveBtn  → updateAftersaveBtn-${commentId}  

수정 버튼 id 값 : updateBtn → updateBtn-${commentId}  

삭제 버튼 id 값 : deleteBtn → deleteBtn-${commentId}  

 

 

예시)

function afterUpdateComment(commentId){     // 저장 버튼을 누르면 그 값이 원래 값 대신 들어가야 함
    let updateCommentInput = "#updateCommentInput-"+commentId // 수정 입력 input 창
    let updateAftersaveBtn = "#updateAftersaveBtn-" + commentId // 저장 버튼
    
    //let comment = $("#updateCommentInput").val(); // 수정 댓글
    let comment = $(updateCommentInput).val(); // 수정 댓글

    //$("#updateCommentInput").hide(); // input 숨기기
    $(updateCommentInput).hide(); // input 숨기기

    //$("#updateAftersaveBtn").hide() // 저장 버튼 숨기기
    $(updateAftersaveBtn).hide() // 저장 버튼 숨기기

    let queryNum = "#"+commentId+"-comment" // id 값을 가져옴 + 제이쿼리 이용
    $(queryNum).text("") // 기존 값 초기화
    $(queryNum).text(comment) // 수정 값 추가

    let updateBtn = "#updateBtn-" + commentId // 수정 버튼
    let deleteBtn = "#deleteBtn-"+ commentId // 삭제 버튼

    //$("#updateBtn").show() // 수정 버튼 보여주기
    $(updateBtn).show() // 수정 버튼 보여주기

    //$("#updateBtn").show() // 삭제 버튼 보여주기
    $(deleteBtn).show() // 삭제 버튼 보여주기
    
 }

 

기존에 id값으로 css를 설정했었는데 className으로 변경했다.

 

front : [add] id값 변경 [#79] #89

 


오류

팀원이 동영상 코드를 작성중에 한번 코드를 올렸었는데 pull을 받고  아예 실행이 안된적이 있다.

279일차(모험 188일차) - 에러 모음

 

 

 

이번에 test 코드를 작성하면서 test 코드를 실행할 때 마다 에러가 뜨길래 작성했던 코드를 모두 주석처리하고 기존에 작성했던 test 코드만 실행했는데도 에러가 뜨면서 문제를 발견하게 되었다. issue에도 올렸던 내용인데 build.gradle에서 동영상 작성 관련 코드 중에 아래 코드로 인해 모든 test 코드가 실행이 안되서 주석 처리하고 실행했다. 

// 썸네일 라이브러리 추가
    //implementation group: 'net.coobird', name: 'thumbnailator', version: '0.4.8'

 

그리고 해당 라이브러리를 쓰던 TenSecondsController에서 에러가 떠서 해당 파일을 주석처리하고 commit했다.

 

backend : [update] 오류나는 코드 임시 주석 처리 [#86] #87 

 


CommentServiceTest 코드 작성 (put, delete)

기존에 post와 get에만 test 코드를 작성했는데 이번에는 put과 delete를 작성했다.

UserService에서 registerUser 함수의 return값 없이 void로 설정했는데 test코드를 작성하면서 return 값이 있는 걸로 변경했다.

 

또한 테스트 이전에 실행되는 BeforeEach를 활용해서 작성을 하다보니 기존에 작성했던 post test 코드 외 추가로 post 코드를 작성했다.

* 기존에 작성했던 test 코드는 카테고리 - project 에서 확인하기 or github

@BeforeEach
void beforeEach() {
    SignupRequestDto userDto = new SignupRequestDto("test1", "test1", "d","d","d");
    User user = userService.registerUser(userDto);
    this.nowUser = new UserDetailsImpl(user);

    RegistryDto registryDto = new RegistryDto("닉네임","타이틀","본문");

    Registry saveRegistry = new Registry(registryDto);
    this.registry = registryRepository.save(saveRegistry);

    this.commentDto = new CommentDto();
    int registryIdx = Math.toIntExact(registry.getIdx());
    this.commentDto.setComment("comment");
    this.commentDto.setNickname(nowUser.getUsername());
    this.commentDto.setRegistryId(registryIdx);
}

 

[add] put, delete 코드 작성 [#88] #89

728x90