Skip to content

Commit

Permalink
moving tests to pod (#1346)
Browse files Browse the repository at this point in the history
* moving tests to pod

* fixing pod image importing

* fixing pod image importing

* more parallelisation

* typo in test bunde

* clang formatting files

* proper names for test and analyse step

* typo and renaming artifacts uploading
  • Loading branch information
frugoman authored Jun 24, 2022
1 parent a1a0ae1 commit 92d3f10
Show file tree
Hide file tree
Showing 505 changed files with 1,974 additions and 1,864 deletions.
59 changes: 49 additions & 10 deletions .github/workflows/_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,14 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

BuildPods:
name: Build pods
AnalyzePods:
name: Analyzing pods
runs-on: macos-11
needs: [Setup]
strategy:
fail-fast: false
matrix:
variant:
- common
- uikit
- swiftui
schemes: [common, uikit, swiftui]

steps:
- name: Checkout code
Expand Down Expand Up @@ -145,13 +142,55 @@ jobs:
- name: Select Xcode 13
run: sudo xcode-select --switch /Applications/Xcode_13.2.1.app

- name: Build and Test
run: ./scripts/ci ${{ matrix.variant }}
- name: Analyze
run: ./scripts/ci ${{ matrix.schemes }} analysis

TestPods:
name: Testing Pods
runs-on: macos-11
needs: [Setup]
strategy:
fail-fast: false
matrix:
schemes: [uitests, uikit, swiftui]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Cache Bundler install Gems
uses: actions/cache@v3
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ env.ImageVersion }}-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-${{ env.ImageVersion }}
- name: Cache Pods
uses: actions/cache@v3
with:
path: Example/Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
- name: Bundle Install
run: bundle install --jobs 4 --retry 3

- name: Pod Install
run: bundle exec pod install
working-directory: Example

- name: Select Xcode 13
run: sudo xcode-select --switch /Applications/Xcode_13.2.1.app

- name: Run Tests
run: ./scripts/ci ${{ matrix.schemes }} test

UploadArtifacts:
name: Build Backpack
name: Upload Artifacts
runs-on: macos-11
needs: [BuildPods]
needs: [TestPods]
steps:
- name: Save assets
uses: actions/upload-artifact@v3
Expand Down
17 changes: 17 additions & 0 deletions Backpack.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Pod::Spec.new do |s|
}
s.ios.deployment_target = '14.0'
s.source_files = 'Backpack/Backpack.h', 'Backpack/Common.h', 'Backpack/*/Classes/**/*.{h,m,swift}'
s.exclude_files = 'Backpack/Tests/**'
s.public_header_files = 'Backpack/Backpack.h', 'Backpack/*/Classes/**/*.h'

s.dependency 'FSCalendar', '~> 2.8.2'
Expand All @@ -43,4 +44,20 @@ Pod::Spec.new do |s|
s.frameworks = 'UIKit', 'Foundation', 'CoreText'
s.requires_arc = true
s.swift_versions = ['5.0', '4.2', '4.0']

s.test_spec 'SnapshotTests' do |test_spec|
test_spec.dependency 'iOSSnapshotTestCase', '~> 6.2.0'
test_spec.source_files = 'Backpack/Tests/SnapshotTests/**/*.{swift,h,m}'
test_spec.ios.resource_bundle = {
'SnapshotTestImages' => 'Backpack/Tests/SnapshotTests/Images*'
}
end

s.test_spec 'UnitTests' do |test_spec|
test_spec.dependency 'OCMock', '~> 3.8.1'
test_spec.source_files = 'Backpack/Tests/UnitTests/**/*.{swift,h,m}'
test_spec.ios.resource_bundle = {
'UnitTestImages' => 'Backpack/Tests/UnitTests/Images*'
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

import XCTest
import Backpack

import FBSnapshotTestCase

class BPKBadgeSnapshotTest: FBSnapshotTestCase {
override func setUp() {
super.setUp()
recordMode = false
}

private func createStackView() -> UIStackView {
let stackView = UIStackView(frame: .zero)
stackView.axis = .vertical
Expand All @@ -35,14 +36,14 @@ class BPKBadgeSnapshotTest: FBSnapshotTestCase {
stackView.translatesAutoresizingMaskIntoConstraints = false
return stackView
}

private func createViewWithTypes(andIcon icon: BPKBadge.Icon? = nil) -> UIView {
let stackView = createStackView()
let parentView = UIView(frame: .zero)
parentView.backgroundColor = BPKColor.skyGrayTint06
parentView.translatesAutoresizingMaskIntoConstraints = false
parentView.addSubview(stackView)

let badges = [BPKBadgeType.light, .inverse, .outline, .success, .warning, .destructive]
.map { BPKBadge(type: $0, icon: icon, message: "Backpack rocks!") }
badges.forEach(stackView.addArrangedSubview(_:))
Expand All @@ -54,29 +55,29 @@ class BPKBadgeSnapshotTest: FBSnapshotTestCase {
])
return parentView
}

func testViewSnapshotWithTypes() {
let lightView = createViewWithTypes()
let darkView = createViewWithTypes()

BPKSnapshotVerifyViewLight(lightView)
BPKSnapshotVerifyViewDark(darkView)
}

func testViewSnapshotWithLeadingIcon() {
let icon = BPKBadge.Icon(position: .leading, iconName: BPKSmallIconName.time)
let lightView = createViewWithTypes(andIcon: icon)
let darkView = createViewWithTypes(andIcon: icon)

BPKSnapshotVerifyViewLight(lightView)
BPKSnapshotVerifyViewDark(darkView)
}

func testViewSnapshotWithTrailingIcon() {
let icon = BPKBadge.Icon(position: .trailing, iconName: BPKSmallIconName.time)
let lightView = createViewWithTypes(andIcon: icon)
let darkView = createViewWithTypes(andIcon: icon)

BPKSnapshotVerifyViewLight(lightView)
BPKSnapshotVerifyViewDark(darkView)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import XCTest
import FBSnapshotTestCase
import Backpack

class BPKButtonSnapshotTest: FBSnapshotTestCase {
override func setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ - (void)configureParentView:(UIView *)parentView forCalendar:(BPKCalendar *)cale
parentView.backgroundColor = [BPKColor white];
[parentView addSubview:calendar];


CGSize screenSize = CGSizeMake(375, 667); // iPhone 6 screen dimensions
[parentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[calendar]-0-|"
options:0
Expand Down Expand Up @@ -118,15 +117,13 @@ - (void)testCalendarWithRangeSelection {
BPKCalendar *bpkCalendar = [[BPKCalendar alloc] initWithFrame:CGRectZero];

[self configureParentView:parentView forCalendar:bpkCalendar];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationRange alloc]
initWithStartSelectionHint:@""
endSelectionHint:@""
startSelectionState:@""
endSelectionState:@""
betweenSelectionState:@""
startAndEndSelectionState:@""
returnDatePrompt:@""
];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationRange alloc] initWithStartSelectionHint:@""
endSelectionHint:@""
startSelectionState:@""
endSelectionState:@""
betweenSelectionState:@""
startAndEndSelectionState:@""
returnDatePrompt:@""];
bpkCalendar.selectedDates = @[
[[BPKSimpleDate alloc] initWithDate:self.date1 forCalendar:bpkCalendar.gregorian], [[BPKSimpleDate alloc] initWithDate:self.date2
forCalendar:bpkCalendar.gregorian]
Expand All @@ -141,17 +138,16 @@ - (void)testCalendarWithLongRangeSelection {
BPKCalendar *bpkCalendar = [[BPKCalendar alloc] initWithFrame:CGRectZero];

[self configureParentView:parentView forCalendar:bpkCalendar];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationRange alloc]
initWithStartSelectionHint:@""
endSelectionHint:@""
startSelectionState:@""
endSelectionState:@""
betweenSelectionState:@""
startAndEndSelectionState:@""
returnDatePrompt:@""];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationRange alloc] initWithStartSelectionHint:@""
endSelectionHint:@""
startSelectionState:@""
endSelectionState:@""
betweenSelectionState:@""
startAndEndSelectionState:@""
returnDatePrompt:@""];
bpkCalendar.selectedDates = @[
[[BPKSimpleDate alloc] initWithDate:self.date1 forCalendar:bpkCalendar.gregorian],
[[BPKSimpleDate alloc] initWithDate:self.date3 forCalendar:bpkCalendar.gregorian]
[[BPKSimpleDate alloc] initWithDate:self.date1 forCalendar:bpkCalendar.gregorian], [[BPKSimpleDate alloc] initWithDate:self.date3
forCalendar:bpkCalendar.gregorian]
];
[bpkCalendar reloadData];

Expand All @@ -163,9 +159,7 @@ - (void)testCalendarWithSelectedDateInFuture {
BPKCalendar *bpkCalendar = [[BPKCalendar alloc] initWithFrame:CGRectZero];

[self configureParentView:parentView forCalendar:bpkCalendar];
bpkCalendar.selectedDates = @[
[[BPKSimpleDate alloc] initWithDate:self.date4 forCalendar:bpkCalendar.gregorian]
];
bpkCalendar.selectedDates = @[[[BPKSimpleDate alloc] initWithDate:self.date4 forCalendar:bpkCalendar.gregorian]];
[bpkCalendar reloadData];

FBSnapshotVerifyView(parentView, nil);
Expand All @@ -176,17 +170,16 @@ - (void)testCalendarWithRangeSelectionWithTheme {
BPKCalendar *bpkCalendar = [[BPKCalendar alloc] initWithFrame:CGRectZero];

[self configureParentView:parentView forCalendar:bpkCalendar];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationRange alloc]
initWithStartSelectionHint:@""
endSelectionHint:@""
startSelectionState:@""
endSelectionState:@""
betweenSelectionState:@""
startAndEndSelectionState:@""
returnDatePrompt:@""];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationRange alloc] initWithStartSelectionHint:@""
endSelectionHint:@""
startSelectionState:@""
endSelectionState:@""
betweenSelectionState:@""
startAndEndSelectionState:@""
returnDatePrompt:@""];
bpkCalendar.selectedDates = @[
[[BPKSimpleDate alloc] initWithDate:self.date1 forCalendar:bpkCalendar.gregorian],
[[BPKSimpleDate alloc] initWithDate:self.date2 forCalendar:bpkCalendar.gregorian]
[[BPKSimpleDate alloc] initWithDate:self.date1 forCalendar:bpkCalendar.gregorian], [[BPKSimpleDate alloc] initWithDate:self.date2
forCalendar:bpkCalendar.gregorian]
];
bpkCalendar.dateSelectedContentColor = UIColor.orangeColor;
bpkCalendar.dateSelectedBackgroundColor = UIColor.greenColor;
Expand Down Expand Up @@ -228,7 +221,8 @@ - (void)testCalendarWithCustomColorDates {
- (void)testCalendarWithPriceLabels {
UIView *parentView = [[UIView alloc] initWithFrame:CGRectZero];
BPKCalendarSelectionConfiguration *selectionConfiguration = [[BPKCalendarSelectionConfigurationSingle alloc] initWithSelectionHint:@""];
BPKCalendar *bpkCalendar = [[BPKCalendar alloc] initWithConfiguration:[BPKCalendarPriceLabelConfiguration new] selectionConfiguration:selectionConfiguration];
BPKCalendar *bpkCalendar = [[BPKCalendar alloc] initWithConfiguration:[BPKCalendarPriceLabelConfiguration new]
selectionConfiguration:selectionConfiguration];

[self configureParentView:parentView forCalendar:bpkCalendar];

Expand All @@ -245,15 +239,14 @@ - (void)testCalendarWithWholeMonthButton {
BPKCalendar *bpkCalendar = [[BPKCalendar alloc] initWithFrame:CGRectZero];

[self configureParentView:parentView forCalendar:bpkCalendar];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationRange alloc]
initWithStartSelectionHint:@""
endSelectionHint:@""
startSelectionState:@""
endSelectionState:@""
betweenSelectionState:@""
startAndEndSelectionState:@""
returnDatePrompt:@""
andWholeMonthTitle:@"Select whole month"];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationRange alloc] initWithStartSelectionHint:@""
endSelectionHint:@""
startSelectionState:@""
endSelectionState:@""
betweenSelectionState:@""
startAndEndSelectionState:@""
returnDatePrompt:@""
andWholeMonthTitle:@"Select whole month"];
[bpkCalendar selectWholeMonth:[[BPKSimpleDate alloc] initWithDate:self.date1 forCalendar:bpkCalendar.gregorian]];
[bpkCalendar reloadData];

Expand Down Expand Up @@ -291,26 +284,33 @@ - (id _Nullable)calendar:(BPKCalendar *)calendar cellDataForDate:(BPKSimpleDate
NSDateComponents *components = [cal components:NSCalendarUnitDay fromDate:date1 toDate:date2 options:0];

if (components.day == 2 || components.day == 8 || components.day == 12 || components.day == 20) {
return self.isShowingPrices ? [[BPKCalendarPriceLabelCellData alloc] initWithPrice:@"458.100₫" labelStyle:BPKCalendarPriceLabelStyle.positive] : BPKCalendarTrafficLightCellData.positive;
return self.isShowingPrices ? [[BPKCalendarPriceLabelCellData alloc] initWithPrice:@"458.100₫" labelStyle:BPKCalendarPriceLabelStyle.positive]
: BPKCalendarTrafficLightCellData.positive;
}

if (components.day == 4 || components.day == 10 || components.day == 24) {
return self.isShowingPrices ? [[BPKCalendarPriceLabelCellData alloc] initWithPrice:@"This should truncate" labelStyle:BPKCalendarPriceLabelStyle.negative] : BPKCalendarTrafficLightCellData.negative;
return self.isShowingPrices
? [[BPKCalendarPriceLabelCellData alloc] initWithPrice:@"This should truncate" labelStyle:BPKCalendarPriceLabelStyle.negative]
: BPKCalendarTrafficLightCellData.negative;
}

if (components.day == 1 || components.day == 3 || components.day == 11 || components.day == 22) {
return self.isShowingPrices ? [[BPKCalendarPriceLabelCellData alloc] initWithPrice:@"113.884.400₫" labelStyle:BPKCalendarPriceLabelStyle.noData] : BPKCalendarTrafficLightCellData.neutral;
return self.isShowingPrices
? [[BPKCalendarPriceLabelCellData alloc] initWithPrice:@"113.884.400₫" labelStyle:BPKCalendarPriceLabelStyle.noData]
: BPKCalendarTrafficLightCellData.neutral;
}

if (components.day == 13) {
return nil;
}

if (components.day == 15) {
return self.isShowingPrices ? [[BPKCalendarPriceLabelCellData alloc] initWithPrice:@"" labelStyle:BPKCalendarPriceLabelStyle.noData] : BPKCalendarTrafficLightCellData.normal;
return self.isShowingPrices ? [[BPKCalendarPriceLabelCellData alloc] initWithPrice:@"" labelStyle:BPKCalendarPriceLabelStyle.noData]
: BPKCalendarTrafficLightCellData.normal;
}

return self.isShowingPrices ? [[BPKCalendarPriceLabelCellData alloc] initWithPrice:@"" labelStyle:BPKCalendarPriceLabelStyle.noData] : BPKCalendarTrafficLightCellData.noData;
return self.isShowingPrices ? [[BPKCalendarPriceLabelCellData alloc] initWithPrice:@"" labelStyle:BPKCalendarPriceLabelStyle.noData]
: BPKCalendarTrafficLightCellData.noData;
}

#pragma clang diagnostic push
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import XCTest
import FBSnapshotTestCase
import Backpack

class BPKChipSnapshotTest: FBSnapshotTestCase {
override func setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import XCTest

import Backpack
import FBSnapshotTestCase

class BPKDialogViewSnapshotTest: FBSnapshotTestCase {
Expand Down
Loading

0 comments on commit 92d3f10

Please sign in to comment.