From 5964e3c66f591d2c06272feffc9448f1950bb055 Mon Sep 17 00:00:00 2001 From: Tangg123 Date: Fri, 21 Nov 2025 17:50:19 +0700 Subject: [PATCH 1/3] notifications cypress testing --- frontend/cypress/e2e/notifications.cy.js | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 frontend/cypress/e2e/notifications.cy.js diff --git a/frontend/cypress/e2e/notifications.cy.js b/frontend/cypress/e2e/notifications.cy.js new file mode 100644 index 0000000..7b8b84f --- /dev/null +++ b/frontend/cypress/e2e/notifications.cy.js @@ -0,0 +1,42 @@ +describe('Admin Notification Page', () => { + + it('can open Notifications from sidebar bottom section', () => { + + // ---- LOGIN ---- + cy.visit('/login'); + + cy.get('#username').type('apartment_admin'); + cy.get('#password').type('Admin@2024!Secure'); + + cy.intercept('POST', '**/api/auth/login').as('login'); + cy.intercept('GET', '**/api/auth/me').as('me'); + + cy.get('button[type="submit"]').click(); + + cy.wait('@login'); + cy.wait('@me'); + + + // ---- OPEN SIDEBAR ---- + cy.get('button') + .filter((i, el) => el.innerHTML.includes('svg')) + .first() + .click({ force: true }); + + + // ---- SCROLL ลงหา Notifications ---- + cy.get('aside nav').scrollTo('bottom', { ensureScrollable: false }); + + + // รองรับทั้งชื่อผิดและชื่อถูก + cy.contains(/Notfications|Notifications/) + .scrollIntoView() + .should('be.visible') + .click({ force: true }); + + + // ---- VERIFY PAGE ---- + cy.url().should('include', '/admin/notifications'); + }); + +}); From 0ef6ccccd74745a3298a9b95f59ab436d7d3ad33 Mon Sep 17 00:00:00 2001 From: Tangg123 Date: Fri, 21 Nov 2025 17:52:39 +0700 Subject: [PATCH 2/3] Log cypress testing --- frontend/cypress/e2e/unit_logs.cy.js | 110 +++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 frontend/cypress/e2e/unit_logs.cy.js diff --git a/frontend/cypress/e2e/unit_logs.cy.js b/frontend/cypress/e2e/unit_logs.cy.js new file mode 100644 index 0000000..7d6d311 --- /dev/null +++ b/frontend/cypress/e2e/unit_logs.cy.js @@ -0,0 +1,110 @@ +describe('Unit Change Logs Page', () => { + + it('can open Logs page and check UI + Restore button + Reset button', () => { + + // ---- LOGIN ---- + cy.visit('/login'); + + cy.get('#username').type('apartment_admin'); + cy.get('#password').type('Admin@2024!Secure'); + + cy.intercept('POST', '**/api/auth/login').as('login'); + cy.intercept('GET', '**/api/auth/me').as('me'); + cy.intercept('GET', '**/api/unit-audit-logs').as('logs'); + + cy.get('button[type="submit"]').click(); + + cy.wait('@login'); + cy.wait('@me'); + + + // ---- OPEN SIDEBAR ---- + cy.get('button') + .filter((i, el) => el.innerHTML.includes('svg')) + .first() + .click({ force: true }); + + + // ---- OPEN LOG PAGE ---- + cy.contains('Log') + .scrollIntoView() + .should('be.visible') + .click({ force: true }); + + cy.url().should('include', '/admin/log'); + + cy.wait('@logs'); + + + // ---- CHECK PAGE TITLE ---- + cy.contains('Unit Change Logs').should('be.visible'); + cy.contains('ประวัติการเปลี่ยนแปลงข้อมูลห้องพัก').should('be.visible'); + + + // ---- CHECK FILTER UI ---- + cy.contains('Filters').should('be.visible'); + cy.contains('Unit').should('be.visible'); + cy.contains('Action Type').should('be.visible'); + + + // ---- TEST UNIT DROPDOWN ---- + cy.get('select').eq(0) + .scrollIntoView() + .should('be.visible') + .select('101', { force: true }); + + cy.contains('Apply Filters').click({ force: true }); + + + + // ==================================================== + // 🔵 NEW: TEST RESET BUTTON + // ==================================================== + cy.contains('Reset') + .scrollIntoView() + .should('be.visible') + .click({ force: true }); + + // wait ให้ค่ามัน reset ก่อน + cy.wait(300); + + // default value → ALL + cy.get('select').eq(0).should('have.value', 'all'); + + + + // ---- CHECK LIST OR SKIP ---- +// ---- CHECK LIST OR SKIP ---- +// ---- CHECK LIST OR SKIP ---- +cy.get('body').then($body => { + + // ไม่มีปุ่ม restore → ข้าม + if ($body.find('button:contains("Restore")').length === 0) { + cy.log('⚠ ไม่มี Restore → ข้าม restore test'); + return; + } + + // มี log ให้ restore + cy.contains('DELETED').should('exist'); + cy.contains('Hard deleted unit').should('exist'); + + // intercept ไว้ แต่เรา "จะไม่ wait" + cy.intercept('POST', '**/api/units/restore*').as('restoreUnit'); + + // คลิก Restore + cy.contains('Restore') + .first() + .scrollIntoView() + .click({ force: true }); + + // ⛔ ห้าม cy.wait() เพราะ FE reload หน้าเร็วเกิน → intercept ไม่ทัน + // แค่ดูว่ามี alert ก็พอ + + cy.on('window:alert', msg => { + cy.log("Alert message:", msg); + }); + +}); + }); + +}); From 635550517cf5cc90988be53eb8460c3b8548abac Mon Sep 17 00:00:00 2001 From: Cherrypattranit Date: Fri, 21 Nov 2025 23:43:29 +0700 Subject: [PATCH 3/3] Tenants cypress testing --- frontend/cypress/e2e/Tenants.cy.js | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 frontend/cypress/e2e/Tenants.cy.js diff --git a/frontend/cypress/e2e/Tenants.cy.js b/frontend/cypress/e2e/Tenants.cy.js new file mode 100644 index 0000000..30d2a0b --- /dev/null +++ b/frontend/cypress/e2e/Tenants.cy.js @@ -0,0 +1,36 @@ +describe('Admin Tenants Page', () => { + + it('opens Tenants page from Dashboard', () => { + + cy.visit('/login'); + + // รอเฉพาะ input – ชัวร์สุด + cy.get('#username', { timeout: 10000 }).should('be.visible'); + + cy.get('#username').type('apartment_admin'); + cy.get('#password').type('Admin@2024!Secure'); + + cy.intercept('POST', '/api/auth/login').as('login'); + cy.intercept('GET', '/api/auth/me').as('me'); + + cy.get('button[type="submit"]').click(); + + cy.wait('@login'); + cy.wait('@me'); + + // เปิด Sidebar + cy.get('button') + .filter((i, el) => el.innerHTML.includes('svg')) + .first() + .click({ force: true }); + + // ไปหน้า Tenants + cy.contains('Tenants') + .scrollIntoView() + .should('be.visible') + .click({ force: true }); + + cy.url().should('include', '/admin/tenants'); + }); + +}); \ No newline at end of file