|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 LabKey Corporation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.labkey.test.tests.targetedms; |
| 17 | + |
| 18 | +import org.jetbrains.annotations.Nullable; |
| 19 | +import org.junit.BeforeClass; |
| 20 | +import org.junit.Test; |
| 21 | +import org.junit.experimental.categories.Category; |
| 22 | +import org.labkey.remoteapi.CommandException; |
| 23 | +import org.labkey.remoteapi.query.Filter; |
| 24 | +import org.labkey.remoteapi.query.SelectRowsCommand; |
| 25 | +import org.labkey.remoteapi.query.SelectRowsResponse; |
| 26 | +import org.labkey.test.BaseWebDriverTest; |
| 27 | +import org.labkey.test.Locator; |
| 28 | +import org.labkey.test.WebTestHelper; |
| 29 | +import org.labkey.test.components.targetedms.InstrumentUtilizationWebPart; |
| 30 | +import org.labkey.test.util.DataRegionTable; |
| 31 | + |
| 32 | +import java.io.IOException; |
| 33 | +import java.util.List; |
| 34 | +import java.util.Map; |
| 35 | + |
| 36 | +import static org.junit.Assert.assertEquals; |
| 37 | +import static org.junit.Assert.assertFalse; |
| 38 | +import static org.junit.Assert.assertTrue; |
| 39 | + |
| 40 | +/** |
| 41 | + * Verifies the instrument-scoped, cross-folder utilization views on the Show Instrument page: the |
| 42 | + * "Utilization Calendar" web part and the "Runs Acquired" by-day/by-month grids. The same Skyline |
| 43 | + * document is imported into two folders so we can assert that the views aggregate across every folder |
| 44 | + * the user can read, not just the current one. |
| 45 | + */ |
| 46 | +@Category({}) |
| 47 | +@BaseWebDriverTest.ClassTimeout(minutes = 5) |
| 48 | +public class TargetedMSInstrumentUtilizationTest extends TargetedMSTest |
| 49 | +{ |
| 50 | + private static final String QC_SUBFOLDER = "QC Subfolder"; |
| 51 | + |
| 52 | + private String _instrumentName; |
| 53 | + |
| 54 | + @Override |
| 55 | + protected @Nullable String getProjectName() |
| 56 | + { |
| 57 | + return getClass().getSimpleName() + " Project"; |
| 58 | + } |
| 59 | + |
| 60 | + @BeforeClass |
| 61 | + public static void initProject() |
| 62 | + { |
| 63 | + TargetedMSInstrumentUtilizationTest init = getCurrentTest(); |
| 64 | + init.doInit(); |
| 65 | + } |
| 66 | + |
| 67 | + private void doInit() |
| 68 | + { |
| 69 | + setupFolder(FolderType.QC); |
| 70 | + setupSubfolder(getProjectName(), QC_SUBFOLDER, FolderType.QC); |
| 71 | + |
| 72 | + // Import the same document into two folders so the same instrument has data in both |
| 73 | + goToProjectHome(); |
| 74 | + importData(SProCoP_FILE); |
| 75 | + |
| 76 | + clickFolder(QC_SUBFOLDER); |
| 77 | + importData(SProCoP_FILE); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testCrossFolderInstrumentUtilization() throws IOException, CommandException |
| 82 | + { |
| 83 | + _instrumentName = getInstrumentNickname(); |
| 84 | + |
| 85 | + // The two folders hold identical imports, so the cross-folder total should be exactly double |
| 86 | + // the count in a single folder. |
| 87 | + int singleFolderFileCount = getFileCount(getProjectName()); |
| 88 | + int expectedCrossFolderFileCount = singleFolderFileCount * 2; |
| 89 | + assertTrue("Expected the single folder to contain sample files with acquisition times", singleFolderFileCount > 0); |
| 90 | + |
| 91 | + beginAt(WebTestHelper.buildURL("targetedms", getProjectName(), "showInstrument", Map.of("name", _instrumentName))); |
| 92 | + |
| 93 | + verifyCalendar(); |
| 94 | + verifyRunsAcquiredGrids(expectedCrossFolderFileCount); |
| 95 | + } |
| 96 | + |
| 97 | + private void verifyCalendar() |
| 98 | + { |
| 99 | + log("Verifying the cross-folder Utilization Calendar renders"); |
| 100 | + assertElementPresent(Locator.tagWithClass("span", "labkey-wp-title-text").withText("Utilization Calendar")); |
| 101 | + |
| 102 | + // Wait for the async selectRows call to populate the calendar with day cells |
| 103 | + waitForElement(Locator.tagWithClassContaining("div", "day-content")); |
| 104 | + assertEquals("Calendar should default to a single month", |
| 105 | + "1 month", getSelectedOptionText(Locator.id("utilizationMonthNumberSelect"))); |
| 106 | + } |
| 107 | + |
| 108 | + private void verifyRunsAcquiredGrids(int expectedCrossFolderFileCount) |
| 109 | + { |
| 110 | + InstrumentUtilizationWebPart utilization = new InstrumentUtilizationWebPart(getDriver()); |
| 111 | + |
| 112 | + log("Verifying the By Day grid is shown by default and aggregates across folders"); |
| 113 | + assertTrue("By Day grid should be visible by default", utilization.isByDayVisible()); |
| 114 | + assertFalse("By Month grid should be hidden by default", utilization.isByMonthVisible()); |
| 115 | + |
| 116 | + DataRegionTable byDay = utilization.getByDayTable(); |
| 117 | + assertTrue("By Day grid is missing expected columns", |
| 118 | + byDay.getColumnLabels().containsAll(List.of("Date", "Runs", "Files"))); |
| 119 | + assertEquals("By Day grid should sum files across both folders", |
| 120 | + expectedCrossFolderFileCount, utilization.getTotalFiles(byDay)); |
| 121 | + |
| 122 | + log("Toggling to the By Month summary"); |
| 123 | + utilization.showByMonth(); |
| 124 | + assertTrue("By Month grid should be visible after toggling", utilization.isByMonthVisible()); |
| 125 | + assertFalse("By Day grid should be hidden after toggling", utilization.isByDayVisible()); |
| 126 | + |
| 127 | + DataRegionTable byMonth = utilization.getByMonthTable(); |
| 128 | + assertTrue("By Month grid is missing expected columns", |
| 129 | + byMonth.getColumnLabels().containsAll(List.of("Month", "Runs", "Files"))); |
| 130 | + // Grouping by month rather than day changes the row count but not the overall file total |
| 131 | + assertEquals("By Month grid should sum to the same cross-folder file total", |
| 132 | + expectedCrossFolderFileCount, utilization.getTotalFiles(byMonth)); |
| 133 | + |
| 134 | + log("Toggling back to the By Day grid"); |
| 135 | + utilization.showByDay(); |
| 136 | + assertTrue("By Day grid should be visible after toggling back", utilization.isByDayVisible()); |
| 137 | + assertFalse("By Month grid should be hidden after toggling back", utilization.isByMonthVisible()); |
| 138 | + } |
| 139 | + |
| 140 | + /** @return the default nickname (model - serial number) for the instrument that acquired the imported data */ |
| 141 | + private String getInstrumentNickname() throws IOException, CommandException |
| 142 | + { |
| 143 | + SelectRowsCommand command = new SelectRowsCommand("targetedms", "SampleFile"); |
| 144 | + command.setColumns(List.of("InstrumentNickname")); |
| 145 | + command.setMaxRows(1); |
| 146 | + SelectRowsResponse response = command.execute(createDefaultConnection(), getProjectName()); |
| 147 | + assertFalse("No sample files were imported", response.getRows().isEmpty()); |
| 148 | + return (String) response.getRows().get(0).get("InstrumentNickname"); |
| 149 | + } |
| 150 | + |
| 151 | + /** @return the number of sample files (with an acquisition time) for the instrument in a single container */ |
| 152 | + private int getFileCount(String containerPath) throws IOException, CommandException |
| 153 | + { |
| 154 | + SelectRowsCommand command = new SelectRowsCommand("targetedms", "SampleFile"); |
| 155 | + command.setColumns(List.of("Id")); |
| 156 | + command.setFilters(List.of( |
| 157 | + new Filter("InstrumentNickname", _instrumentName), |
| 158 | + new Filter("AcquiredTime", null, Filter.Operator.NONBLANK))); |
| 159 | + SelectRowsResponse response = command.execute(createDefaultConnection(), containerPath); |
| 160 | + return response.getRowCount().intValue(); |
| 161 | + } |
| 162 | +} |
0 commit comments