123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- /**
- * SearchPanelPage - 搜索面板的 Page Object Model
- * 用于 Worklist 和 History 页面的搜索功能
- */
- class SearchPanelPage {
- /**
- * 获取患者名称输入框
- */
- getPatientNameInput() {
- return cy.get('input[placeholder*="患者姓名"], input[placeholder*="Patient Name"]');
- }
- /**
- * 获取患者ID输入框
- */
- getPatientIdInput() {
- return cy.get('input[placeholder*="患者ID"], input[placeholder*="Patient ID"]');
- }
- /**
- * 获取登记号输入框
- */
- getAccessionNumberInput() {
- return cy.get('input[placeholder*="登记号"], input[placeholder*="Registration"], input[placeholder*="Accession"]');
- }
- /**
- * 输入患者名称
- * @param name 患者名称
- */
- typePatientName(name: string) {
- this.getPatientNameInput().clear().type(name);
- }
- /**
- * 输入患者ID
- * @param id 患者ID
- */
- typePatientId(id: string) {
- this.getPatientIdInput().clear().type(id);
- }
- /**
- * 输入登记号
- * @param accNo 登记号
- */
- typeAccessionNumber(accNo: string) {
- this.getAccessionNumberInput().clear().type(accNo);
- }
- /**
- * 清空患者名称
- */
- clearPatientName() {
- this.getPatientNameInput().clear();
- }
- /**
- * 清空患者ID
- */
- clearPatientId() {
- this.getPatientIdInput().clear();
- }
- /**
- * 清空登记号
- */
- clearAccessionNumber() {
- this.getAccessionNumberInput().clear();
- }
- // ============ 时间范围选择器操作 ============
- /**
- * 选择"今天"时间范围
- */
- selectTimeRangeToday() {
- cy.contains('label', '今天').click();
- }
- /**
- * 选择"7天"时间范围
- */
- selectTimeRange7Days() {
- cy.contains('label', '7天').click();
- }
- /**
- * 选择"所有"时间范围
- */
- selectTimeRangeAll() {
- cy.contains('label', '所有').click();
- }
- /**
- * 验证时间范围选中状态
- * @param type 时间范围类型
- */
- verifyTimeRangeSelected(type: 'today' | '7days' | 'all') {
- const labelText = {
- today: '今天',
- '7days': '7天',
- all: '所有',
- };
- cy.contains('label', labelText[type])
- .find('input[type="radio"]')
- .should('be.checked');
- }
- /**
- * 获取时间范围选择器组
- */
- getTimeRangeSelector() {
- return cy.get('.ant-radio-group');
- }
- // ============ 自定义日期范围操作 ============
- /**
- * 选择自定义日期范围
- * @param startDate 开始日期,格式:YYYY-MM-DD
- * @param endDate 结束日期,格式:YYYY-MM-DD
- */
- selectCustomDateRange(startDate: string, endDate: string) {
- // 点击日期范围选择器
- cy.get('.ant-picker-range').click();
- // 选择开始日期
- this.selectDateInPicker(startDate, 'start');
- // 选择结束日期
- this.selectDateInPicker(endDate, 'end');
- }
- /**
- * 在日期选择器中选择日期
- * @param date 日期字符串,格式:YYYY-MM-DD
- * @param type 'start' 或 'end'
- */
- private selectDateInPicker(date: string, type: 'start' | 'end') {
- const [year, month, day] = date.split('-').map(Number);
- // 等待日期选择器面板显示
- cy.get('.ant-picker-dropdown').should('be.visible');
- // 选择年份
- if (type === 'start') {
- cy.get('.ant-picker-dropdown')
- .first()
- .find('.ant-picker-header-year-btn')
- .click();
- cy.get('.ant-picker-year-panel').contains('.ant-picker-cell', year.toString()).click();
- }
- // 选择月份
- if (type === 'start') {
- cy.get('.ant-picker-dropdown')
- .first()
- .find('.ant-picker-header-month-btn')
- .click();
- cy.get('.ant-picker-month-panel')
- .contains('.ant-picker-cell', new RegExp(`^${month}月?$`))
- .click();
- }
- // 选择日期
- cy.get('.ant-picker-dropdown')
- .find('.ant-picker-cell')
- .not('.ant-picker-cell-disabled')
- .contains(new RegExp(`^${day}$`))
- .click();
- }
- /**
- * 清空自定义日期范围
- */
- clearCustomDateRange() {
- cy.get('.ant-picker-range').within(() => {
- cy.get('.ant-picker-clear').click({ force: true });
- });
- }
- /**
- * 获取日期范围选择器
- */
- getDateRangePicker() {
- return cy.get('.ant-picker-range');
- }
- /**
- * 验证日期范围选择器中的值
- * @param startDate 开始日期,格式:YYYY-MM-DD
- * @param endDate 结束日期,格式:YYYY-MM-DD
- */
- verifyDateRangeValue(startDate: string, endDate: string) {
- cy.get('.ant-picker-range input').first().should('have.value', startDate);
- cy.get('.ant-picker-range input').last().should('have.value', endDate);
- }
- /**
- * 验证日期范围选择器为空
- */
- verifyDateRangeEmpty() {
- cy.get('.ant-picker-range input').first().should('have.value', '');
- cy.get('.ant-picker-range input').last().should('have.value', '');
- }
- // ============ 搜索按钮 ============
- /**
- * 点击搜索按钮
- */
- clickSearchButton() {
- cy.contains('button', '搜索').click();
- }
- /**
- * 获取搜索按钮
- */
- getSearchButton() {
- return cy.contains('button', '搜索');
- }
- /**
- * 验证搜索按钮可点击
- */
- verifySearchButtonEnabled() {
- this.getSearchButton().should('not.be.disabled');
- }
- /**
- * 验证搜索按钮禁用
- */
- verifySearchButtonDisabled() {
- this.getSearchButton().should('be.disabled');
- }
- // ============ 整体验证 ============
- /**
- * 验证搜索面板可见
- */
- verifySearchPanelVisible() {
- this.getPatientNameInput().should('be.visible');
- this.getPatientIdInput().should('be.visible');
- this.getAccessionNumberInput().should('be.visible');
- this.getTimeRangeSelector().should('be.visible');
- this.getDateRangePicker().should('be.visible');
- this.getSearchButton().should('be.visible');
- }
- /**
- * 清空所有搜索条件
- */
- clearAllFilters() {
- this.clearPatientName();
- this.clearPatientId();
- this.clearAccessionNumber();
- this.selectTimeRangeAll();
- }
- /**
- * 填写完整的搜索条件并搜索
- * @param options 搜索选项
- */
- searchWithFilters(options: {
- patientName?: string;
- patientId?: string;
- accessionNumber?: string;
- timeRange?: 'today' | '7days' | 'all';
- customDateRange?: { start: string; end: string };
- }) {
- // 清空现有条件
- this.clearAllFilters();
- // 填写患者名称
- if (options.patientName) {
- this.typePatientName(options.patientName);
- }
- // 填写患者ID
- if (options.patientId) {
- this.typePatientId(options.patientId);
- }
- // 填写登记号
- if (options.accessionNumber) {
- this.typeAccessionNumber(options.accessionNumber);
- }
- // 选择预设时间范围
- if (options.timeRange) {
- switch (options.timeRange) {
- case 'today':
- this.selectTimeRangeToday();
- break;
- case '7days':
- this.selectTimeRange7Days();
- break;
- case 'all':
- this.selectTimeRangeAll();
- break;
- }
- }
- // 选择自定义日期范围
- if (options.customDateRange) {
- this.selectCustomDateRange(
- options.customDateRange.start,
- options.customDateRange.end
- );
- }
- // 点击搜索
- this.clickSearchButton();
- }
- }
- export default SearchPanelPage;
|