diff --git a/app/frontend/entrypoints/pages/bed_verification.js b/app/frontend/entrypoints/pages/bed_verification.js
index d2d97d82f3..76497ff902 100644
--- a/app/frontend/entrypoints/pages/bed_verification.js
+++ b/app/frontend/entrypoints/pages/bed_verification.js
@@ -129,10 +129,17 @@ const fail = function () {
}
$('#plate_scan').on('change', function () {
- let plate_barcode, bed_barcode, robot_barcode
- plate_barcode = this.value
- bed_barcode = $('#bed_scan').val()
- robot_barcode = $('#robot_scan').val()
+ let bed_barcode = $('#bed_scan').val()
+ if (!bed_barcode) {
+ SCAPE.message('Scan the bed before the plate please!', 'warning')
+ $('#bed_scan').focus()
+ this.value = ''
+ return
+ }
+ // clear the message field if we have a bed barcode
+ SCAPE.message('', '')
+ let plate_barcode = this.value
+ let robot_barcode = $('#robot_scan').val()
SCAPE.robot_scan = robot_barcode
this.value = ''
$('#bed_scan').val('')
diff --git a/app/frontend/entrypoints/pages/bed_verification.spec.js b/app/frontend/entrypoints/pages/bed_verification.spec.js
new file mode 100644
index 0000000000..b818111cdf
--- /dev/null
+++ b/app/frontend/entrypoints/pages/bed_verification.spec.js
@@ -0,0 +1,46 @@
+import $ from 'jquery'
+import SCAPE from '@/javascript/lib/global_message_system.js'
+
+describe('bed_verification plate scan handler', () => {
+ let plateScan, bedScan, robotScan
+
+ // NB. use of beforeAll is not ideal but could not get beforeEach to work.
+ // Deemed acceptable in this case as the two tests could mimic a sequence that could happen in
+ // real life.
+ beforeAll(async () => {
+ // Set up DOM elements
+ document.body.innerHTML = `
+
+
+
+ `
+ plateScan = $('#plate_scan')
+ bedScan = $('#bed_scan')
+ robotScan = $('#robot_scan')
+
+ // Mock SCAPE.message
+ SCAPE.message = vi.fn()
+
+ // Import and attach the handler
+ await import('./bed_verification.js')
+ })
+
+ it('shows warning and does not scan plate if bed_scan is empty', () => {
+ bedScan.val('')
+ plateScan.val('PLATE123')
+ plateScan.trigger('change')
+
+ // We expect a message on screen requesting user scan the bed first
+ expect(SCAPE.message).toHaveBeenCalledWith('Scan the bed before the plate please!', 'warning')
+ })
+
+ it('clears warning and scans plate if bed_scan has value', () => {
+ robotScan.val('ROBOT123')
+ bedScan.val('BED123')
+ plateScan.val('PLATE123')
+ plateScan.trigger('change')
+
+ // We clear the message field if we have a bed barcode, so we expect an empty message to be sent
+ expect(SCAPE.message).toHaveBeenCalledWith('', '')
+ })
+})