Class: CypressViewportUpdater::ViewportPresetJsFile

Inherits:
ExistingGithubFile show all
Defined in:
app/sidekiq/cypress_viewport_updater/viewport_preset_js_file.rb

Instance Attribute Summary

Attributes inherited from ExistingGithubFile

#github_path, #name, #raw_content, #sha, #updated_content

Instance Method Summary collapse

Constructor Details

#initializeViewportPresetJsFile

Returns a new instance of ViewportPresetJsFile.



5
6
7
8
# File 'app/sidekiq/cypress_viewport_updater/viewport_preset_js_file.rb', line 5

def initialize
  super(github_path: 'src/platform/testing/e2e/cypress/support/commands/viewportPreset.js',
        name: 'viewportPreset.js')
end

Instance Method Details

#update(viewports:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/sidekiq/cypress_viewport_updater/viewport_preset_js_file.rb', line 10

def update(viewports:)
  new_lines = []

  raw_content.split("\n").each do |line|
    if /va-top-(mobile|tablet|desktop)-\d+/.match(line)
      if /va-top-(mobile|tablet|desktop)-1/.match(line)
        create_viewport_presets(line:,
                                viewports:) do |updated_line|
                                  new_lines << updated_line
                                end
      end
    else
      new_lines << line
    end
  end

  self.updated_content = "#{new_lines.join("\n")}\n"
  self
end